Showing
10 changed files
with
98 additions
and
20 deletions
@@ -26,14 +26,19 @@ const pkg = require('./package.json'); | @@ -26,14 +26,19 @@ const pkg = require('./package.json'); | ||
26 | const app = express(); | 26 | const app = express(); |
27 | const MemcachedStore = memcached(session); | 27 | const MemcachedStore = memcached(session); |
28 | 28 | ||
29 | +// 指定libray目录 | ||
30 | +global.library = path.resolve('./library'); | ||
31 | +global.middleware = path.resolve('./doraemon/middleware'); | ||
32 | +global.utils = path.resolve('./utils'); | ||
33 | + | ||
34 | +const seo = require(`${global.middleware}/seo`); | ||
35 | + | ||
36 | + | ||
29 | 37 | ||
30 | // 向模板注入变量 | 38 | // 向模板注入变量 |
31 | app.locals.devEnv = app.get('env') === 'development'; | 39 | app.locals.devEnv = app.get('env') === 'development'; |
32 | app.locals.version = pkg.version; | 40 | app.locals.version = pkg.version; |
33 | 41 | ||
34 | -// 指定libray目录 | ||
35 | -global.library = path.resolve('./library'); | ||
36 | -global.middleware = path.resolve('./doraemon/middleware'); | ||
37 | 42 | ||
38 | app.set('view engine', '.hbs'); | 43 | app.set('view engine', '.hbs'); |
39 | 44 | ||
@@ -69,9 +74,13 @@ app.use((req, res, next) => { | @@ -69,9 +74,13 @@ app.use((req, res, next) => { | ||
69 | if (req.session && _.isNumber(req.session._LOGIN_UID)) { | 74 | if (req.session && _.isNumber(req.session._LOGIN_UID)) { |
70 | req.user.uid = req.session._LOGIN_UID; | 75 | req.user.uid = req.session._LOGIN_UID; |
71 | } | 76 | } |
77 | + | ||
72 | next(); | 78 | next(); |
73 | }); | 79 | }); |
74 | 80 | ||
81 | +app.use(seo()); | ||
82 | + | ||
83 | + | ||
75 | // dispatcher | 84 | // dispatcher |
76 | require('./dispatch')(app); | 85 | require('./dispatch')(app); |
77 | 86 |
@@ -14,6 +14,7 @@ var app = express(); | @@ -14,6 +14,7 @@ var app = express(); | ||
14 | var doraemon = path.join(__dirname, '../../doraemon/views'); // parent view root | 14 | var doraemon = path.join(__dirname, '../../doraemon/views'); // parent view root |
15 | var partials = path.join(__dirname, './views'); // parent view root | 15 | var partials = path.join(__dirname, './views'); // parent view root |
16 | 16 | ||
17 | + | ||
17 | app.on('mount', function(parent) { | 18 | app.on('mount', function(parent) { |
18 | delete parent.locals.settings; // 不继承父 App 的设置 | 19 | delete parent.locals.settings; // 不继承父 App 的设置 |
19 | Object.assign(app.locals, parent.locals); | 20 | Object.assign(app.locals, parent.locals); |
@@ -28,6 +29,7 @@ app.engine('.hbs', hbs({ | @@ -28,6 +29,7 @@ app.engine('.hbs', hbs({ | ||
28 | helpers: require('../../library/helpers') | 29 | helpers: require('../../library/helpers') |
29 | })); | 30 | })); |
30 | 31 | ||
32 | + | ||
31 | // router | 33 | // router |
32 | app.use(require('./router')); | 34 | app.use(require('./router')); |
33 | 35 |
@@ -11,7 +11,7 @@ const ServiceAPI = require(`${global.library}/api`).ServiceAPI; | @@ -11,7 +11,7 @@ const ServiceAPI = require(`${global.library}/api`).ServiceAPI; | ||
11 | const SearchAPI = require(`${global.library}/api`).SearchAPI; | 11 | const SearchAPI = require(`${global.library}/api`).SearchAPI; |
12 | const sign = require(`${global.library}/sign`); | 12 | const sign = require(`${global.library}/sign`); |
13 | const helpers = require(`${global.library}/helpers`); | 13 | const helpers = require(`${global.library}/helpers`); |
14 | -const images = require(`${global.middleware}/images`); | 14 | +const images = require(`${global.utils}/images`); |
15 | 15 | ||
16 | 16 | ||
17 | const serviceApi = new ServiceAPI(); | 17 | const serviceApi = new ServiceAPI(); |
@@ -11,12 +11,38 @@ const cRoot = './controllers'; | @@ -11,12 +11,38 @@ const cRoot = './controllers'; | ||
11 | 11 | ||
12 | // Your controller here | 12 | // Your controller here |
13 | const channelController = require(`${cRoot}/index`); | 13 | const channelController = require(`${cRoot}/index`); |
14 | +const seo = require(`${global.middleware}/seo`); | ||
15 | + | ||
16 | +const seoMap = { | ||
17 | +/* eslint-disable */ | ||
18 | + boys: { | ||
19 | + title: 'YOHO!有货 | 年轻人潮流购物中心,中国潮流购物风向标,官方授权正品保证', | ||
20 | + keywords: 'Yoho! 有货官网,潮流志,潮流男装,潮牌,美国潮牌,日本潮牌,香港潮牌,潮牌店,新品首发,欧美潮流,全球购,代购,时尚,流行,特卖,B2C,正品,购物网站,网上购物,货到付款', | ||
21 | + description: 'YOHO! 有货,年轻人潮流购物中心,中国最大的潮流商品购物网站。100%品牌正品保证,支持货到付款。作为YOHO!旗下的购物平台,汇集了全球潮流时尚商品和中国最流行的商品,也是国内最大的原创文化商品平台,也是香港,台湾地区流行商品的集中地。同时包含日本、韩国等众多国外潮流品牌,带给您全新潮流购物体验。' | ||
22 | + }, | ||
23 | + girls: { | ||
24 | + title: '女生|时尚潮流女装,日韩女装,潮牌女装全球购|YOHO!BUY有货 100%正品保证', | ||
25 | + keywords: '女生服饰,时尚潮流女装,日韩女装,女装正品购物网站,女装全球购', | ||
26 | + description: 'YOHO!BUY有货官网女生频道汇集了全球女装潮流时尚,提供时尚潮流女装,日版女装,韩版女装,潮牌女装正品全球购。YOHO!BUY有货购物100%正品保证,支持货到付款。' | ||
27 | + }, | ||
28 | + kids: { | ||
29 | + title: '潮童|男童装,女童装,韩版童装,儿童服装服饰|YOHO!BUY有货 100%正品保证', | ||
30 | + keywords: '潮童,男童装,女童装,韩版童装,儿童服装服饰', | ||
31 | + description: 'YOHO!BUY有货官网潮童频道汇集了全球潮童潮流时尚,提供新款男童装,女童装,韩版童装,儿童服装服饰正品全球购。YOHO!BUY有货购物100%正品保证,支持货到付款。' | ||
32 | + }, | ||
33 | + lifestyle: { | ||
34 | + title: '创意生活|创意生活馆,潮流创意家居,家居生活用品|YOHO!BUY有货 100%正品保证', | ||
35 | + keywords: '创意生活,创意生活馆,潮流家居,潮流创意家居,家居生活用品,YOHO!有货', | ||
36 | + description: 'YOHO!BUY有货官网创意生活频道汇集了创意生活馆,潮流创意家居,家居生活用品等正品网购,给您的生活带来更多创意。YOHO!BUY有货购物100%正品保证,支持货到付款。' | ||
37 | + } | ||
38 | +/* eslint-enable */ | ||
39 | +}; | ||
14 | 40 | ||
15 | // 频道页路由 | 41 | // 频道页路由 |
16 | -router.get('/', channelController.index); | ||
17 | -router.get('/woman', channelController.index); | ||
18 | -router.get('/kids', channelController.index); | ||
19 | -router.get('/lifestyle', channelController.index); | 42 | +router.get('/', seo(seoMap.boys), channelController.index); |
43 | +router.get('/woman', seo(seoMap.girls), channelController.index); | ||
44 | +router.get('/kids', seo(seoMap.kids), channelController.index); | ||
45 | +router.get('/lifestyle', seo(seoMap.lifestyle), channelController.index); | ||
20 | 46 | ||
21 | // ajax | 47 | // ajax |
22 | router.get('/getbrandFloorDataAjax', channelController.getbrandFloorDataAjax); | 48 | router.get('/getbrandFloorDataAjax', channelController.getbrandFloorDataAjax); |
apps/channel/seo.js
0 → 100644
@@ -14,11 +14,12 @@ module.exports = { | @@ -14,11 +14,12 @@ module.exports = { | ||
14 | siteUrl: 'http://localhost:6002/', | 14 | siteUrl: 'http://localhost:6002/', |
15 | domains: { | 15 | domains: { |
16 | api: 'http://testapi.yoho.cn:28078/', | 16 | api: 'http://testapi.yoho.cn:28078/', |
17 | - service: 'http://testservice.yoho.cn:28077/', | 17 | + |
18 | + // service: 'http://testservice.yoho.cn:28077/', | ||
18 | 19 | ||
19 | // api: 'http://192.168.102.205:8080/gateway/', | 20 | // api: 'http://192.168.102.205:8080/gateway/', |
20 | // service: 'http://testservice.yoho.cn:28077/', | 21 | // service: 'http://testservice.yoho.cn:28077/', |
21 | - // service: 'http://service.api.yohobuy.com/', | 22 | + service: 'http://service.api.yohobuy.com/', |
22 | search: 'http://192.168.102.216:8080/yohosearch/' | 23 | search: 'http://192.168.102.216:8080/yohosearch/' |
23 | }, | 24 | }, |
24 | useOneapm: false, | 25 | useOneapm: false, |
doraemon/middleware/seo.js
0 → 100644
1 | +'use strict'; | ||
2 | + | ||
3 | +const _ = require('lodash'); | ||
4 | + | ||
5 | +module.exports = seoData => { | ||
6 | + const defaultSeoData = { | ||
7 | + /* eslint-disable */ | ||
8 | + title: 'YOHO!有货 | 年轻人潮流购物中心,中国潮流购物风向标,官方授权正品保证', | ||
9 | + keywords: 'Yoho! 有货官网,潮流志,潮流男装,潮牌,美国潮牌,日本潮牌,香港潮牌,潮牌店,新品首发,欧美潮流,全球购,代购,时尚,流行,特卖,B2C,正品,购物网站,网上购物,货到付款', | ||
10 | + description: 'YOHO! 有货,年轻人潮流购物中心,中国最大的潮流商品购物网站。100%品牌正品保证,支持货到付款。作为YOHO!旗下的购物平台,汇集了全球潮流时尚商品和中国最流行的商品,也是国内最大的原创文化商品平台,也是香港,台湾地区流行商品的集中地。同时包含日本、韩国等众多国外潮流品牌,带给您全新潮流购物体验。' | ||
11 | + /* eslint-enable */ | ||
12 | + }; | ||
13 | + | ||
14 | + seoData = _.merge(defaultSeoData, seoData); | ||
15 | + | ||
16 | + return (req, res, next) => { | ||
17 | + if (!req.xhr) { | ||
18 | + res.locals.title = seoData.title; | ||
19 | + res.locals.keywords = seoData.keywords; | ||
20 | + res.locals.description = seoData.description; | ||
21 | + } | ||
22 | + next(); | ||
23 | + }; | ||
24 | +}; |
@@ -13,14 +13,6 @@ const sign = require(`${global.library}/sign`); | @@ -13,14 +13,6 @@ const sign = require(`${global.library}/sign`); | ||
13 | 13 | ||
14 | const serviceApi = new ServiceAPI(); | 14 | const serviceApi = new ServiceAPI(); |
15 | 15 | ||
16 | -/** | ||
17 | - * 获取公共配置 | ||
18 | - * @param undefined | ||
19 | - * @return {Object} 配置对象 | ||
20 | - */ | ||
21 | -const commonConfig = () => ({ | ||
22 | - title: 'YOHO!有货 | 年轻人潮流购物中心,中国潮流购物风向标,官方授权正品保证' | ||
23 | -}); | ||
24 | 16 | ||
25 | const getChannelIndex = type => { | 17 | const getChannelIndex = type => { |
26 | const channelMap = { | 18 | const channelMap = { |
@@ -187,7 +179,6 @@ const getSubNav = (data, type) => { | @@ -187,7 +179,6 @@ const getSubNav = (data, type) => { | ||
187 | * @return {object} 头部数据 | 179 | * @return {object} 头部数据 |
188 | */ | 180 | */ |
189 | exports.setHeaderData = (resData, type) => { | 181 | exports.setHeaderData = (resData, type) => { |
190 | - let config = commonConfig(); | ||
191 | let data = { | 182 | let data = { |
192 | headerData: { | 183 | headerData: { |
193 | header: true, | 184 | header: true, |
@@ -202,7 +193,7 @@ exports.setHeaderData = (resData, type) => { | @@ -202,7 +193,7 @@ exports.setHeaderData = (resData, type) => { | ||
202 | data.headerData.navbars[getChannelIndex(type)].active = true; | 193 | data.headerData.navbars[getChannelIndex(type)].active = true; |
203 | } | 194 | } |
204 | 195 | ||
205 | - return _.merge(config, data); | 196 | + return data; |
206 | }; | 197 | }; |
207 | 198 | ||
208 | 199 |
utils/seo.js
0 → 100644
1 | +'use strict'; | ||
2 | + | ||
3 | +const _ = require('lodash'); | ||
4 | + | ||
5 | +module.exports = seoData => { | ||
6 | + const defaultSeoData = { | ||
7 | + /* eslint-disable */ | ||
8 | + title: 'YOHO!有货 | 年轻人潮流购物中心,中国潮流购物风向标,官方授权正品保证', | ||
9 | + keywords: 'Yoho! 有货官网,潮流志,潮流男装,潮牌,美国潮牌,日本潮牌,香港潮牌,潮牌店,新品首发,欧美潮流,全球购,代购,时尚,流行,特卖,B2C,正品,购物网站,网上购物,货到付款', | ||
10 | + description: 'YOHO! 有货,年轻人潮流购物中心,中国最大的潮流商品购物网站。100%品牌正品保证,支持货到付款。作为YOHO!旗下的购物平台,汇集了全球潮流时尚商品和中国最流行的商品,也是国内最大的原创文化商品平台,也是香港,台湾地区流行商品的集中地。同时包含日本、韩国等众多国外潮流品牌,带给您全新潮流购物体验。' | ||
11 | + /* eslint-enable */ | ||
12 | + }; | ||
13 | + | ||
14 | + | ||
15 | + _.merge(defaultSeoData, seoData); | ||
16 | + | ||
17 | + return (req, res, next) => { | ||
18 | + if (!req.xhr) { | ||
19 | + res.locals.title = seoData.title; | ||
20 | + res.locals.keywords = seoData.keywords; | ||
21 | + res.locals.description = seoData.description; | ||
22 | + } | ||
23 | + next(); | ||
24 | + }; | ||
25 | +}; |
-
Please register or login to post a comment