guang-helper.js 4.3 KB
/**
 * 逛 model
 * @author: lcy<chuanyang.liu@yoho.cn>
 * @date: 2016/09/06
 */

'use strict';

const md5 = require('md5');
const requestIp = require('request-ip');
const _ = require('lodash');
const helpers = global.yoho.helpers;

/* COOKIE标识访问的是男生频道 */
// const COOKIE_NAME_BOYS = 'boys';
// const COOKIE_DOMAIN = '.yohobuy.com';

const getGenderByCookie = (req) => {
    let gender = null;
    let channel = req.yoho.channel;

    switch (channel) {
        case 'boys':
            {
                gender = '1,3';
                break;
            }
        case 'girls':
            {
                gender = '2,3';
                break;
            }
        default:
            {
                gender = '1,2,3';
            }
    }

    return gender;
};

/**
 * 获取客户端唯一标识
 *
 * @return string
 */
const getUdid = (req, res) => {
    let udid = req.cookies.udid;

    if (!udid) {
        udid = md5(req.ip || requestIp.getClientIp(req));

        if (res && res.cookie) {
            res.cookie('udid', udid);
        }
    }

    return udid;
};

/**
  * 获得文章 url
  * @param type string url 后台返回的url
  * @param type id 产品编号
  * @return type url
  */
const getArticleUrl = (url, id) => {

   /* 格式由url:{url:'aaa'} 更改为 url: 'aaa'
    try {
        let urlObj = JSON.parse(url);

        if (urlObj && urlObj['url']) {
            return urlObj['url'];
        }
    } catch (e) {}*/

    if (_.isString(url) && _.trim(url) !== '') {
        return url;
    }

    return helpers.urlFormat(`/guang/${id}.html`);
};

const guangListSeoMap = {
    1001: {
        title: '人气潮流资讯-YOHO!BUY 有货',
        keywords: '人气潮流文章,潮流人气,逛潮流人气',
        description: '有货网每天提供全球人气潮流文章资讯,宣传潮流商品,潮流文化,潮流品牌等信息,想更多了解高人气潮流资讯就来有货网!'
    },
    2: {
        title: '潮流搭配_潮流资讯-YOHO!BUY 有货',
        keywords: '搭配潮流文章,潮流搭配',
        description: '有货网每天提供全球潮流搭配文章资讯,宣传潮流商品,潮流文化,潮流品牌等信息,想更多了解学习潮流搭配资讯就来有货网!'
    },
    4: {
        title: '潮流品牌_潮流资讯-YOHO!BUY 有货',
        keywords: '逛潮品,潮流潮品,潮品资讯',
        description: '有货网每天提供全球潮流潮品文章资讯,宣传潮流商品,潮流文化,潮流品牌等信息,想更多了解学习潮流潮品资讯就来有货网!'
    },
    22: {
        title: 'Buy TV潮流视频_潮流资讯-YOHO!BUY 有货',
        keywords: '潮流视频,看潮流。',
        description: '有货网每天提供全球新潮精彩的潮流视频,宣传潮流商品,潮流文化,潮流品牌等信息,想更多欣赏潮流视频就来有货网!'
    }
};

const getIndexSeo = (params, tabs) => {
    let tdk = {
        title: '最新潮流资讯-YOHO!BUY 有货',
        keywords: '潮流资讯,时尚潮流资讯',
        description: '来有货玩潮流,潮流资讯大分享!年轻人潮流购物中心,了解潮流趋势、掌握潮流文化知识信息,尽在有货逛潮流!'
    };

    params = params || {};

    if (params.hasOwnProperty('type')) {
        let tab = _.find(tabs, {isActive: true});

        if (tab && tab.typeId) {
            Object.assign(tdk, guangListSeoMap[tab.typeId] || {});
        }
    }

    return tdk;
};

const getEditorSeo = (name) => {
    return {
        title: `【${name}】潮流编辑-YOHO!BUY 有货`,
        keywords: ` ${name},潮流编辑${name},潮流编辑`,
        description: `有货逛潮流,潮流编辑${name}分享大量原创潮流资讯,掌握大量不同类别的潮流文化知识信息,尽在有货逛潮流。`
    };
};

const getTagSeo = (tagName) => {
    return {
        title: `【${tagName}】潮流资讯-YOHO!BUY 有货`,
        keywords: `${tagName}${tagName}潮流资讯,${tagName}文章`,
        description: `来有货逛潮流,${tagName}潮流资讯大分享!了解${tagName}潮流趋势,掌握${tagName}潮流文化知识信息,尽在有货逛潮流。`
    };
};

module.exports = {
    getGenderByCookie,
    getUdid,
    getArticleUrl,
    getIndexSeo,
    getEditorSeo,
    getTagSeo
};