Authored by 郝肖肖

'news详情分词'

@@ -19,9 +19,9 @@ exports.index = (req, res, next) => { @@ -19,9 +19,9 @@ exports.index = (req, res, next) => {
19 } 19 }
20 20
21 return res.render('news-index', Object.assign({ 21 return res.render('news-index', Object.assign({
22 - title: '新闻 | ' + (res.locals.title || ''), 22 + title: '潮流资讯 | ' + (res.locals.title || ''),
23 pageHeader: headerModel.setNav({ 23 pageHeader: headerModel.setNav({
24 - navTitle: '新闻' 24 + navTitle: '潮流资讯'
25 }), 25 }),
26 module: 'news', 26 module: 'news',
27 localCss: true, 27 localCss: true,
@@ -51,7 +51,7 @@ exports.detail = (req, res, next) => { @@ -51,7 +51,7 @@ exports.detail = (req, res, next) => {
51 req.ctx(newsService).detail(channel, query).then(result => { 51 req.ctx(newsService).detail(channel, query).then(result => {
52 return res.render('news-detail', Object.assign({ 52 return res.render('news-detail', Object.assign({
53 pageHeader: headerModel.setNav({ 53 pageHeader: headerModel.setNav({
54 - navTitle: result.header && result.header.title || '新闻详情页' 54 + navTitle: result.header && result.header.title || '潮流资讯详情页'
55 }), 55 }),
56 module: 'news', 56 module: 'news',
57 localCss: true, 57 localCss: true,
@@ -2,8 +2,10 @@ @@ -2,8 +2,10 @@
2 2
3 const _ = require('lodash'); 3 const _ = require('lodash');
4 const helpers = global.yoho.helpers; 4 const helpers = global.yoho.helpers;
  5 +const utils = '../../../utils';
  6 +const redis = require(`${utils}/redis`);
5 const NewsAPi = require('./news-api'); 7 const NewsAPi = require('./news-api');
6 -const utils = require('./utils'); 8 +const newsUtils = require('./utils');
7 const moment = require('moment'); 9 const moment = require('moment');
8 const ATYPE = 'yohobuy4008899646,yohogroup,YOHO_GIRL,mars-app'; 10 const ATYPE = 'yohobuy4008899646,yohogroup,YOHO_GIRL,mars-app';
9 11
@@ -24,7 +26,7 @@ module.exports = class extends global.yoho.BaseModel { @@ -24,7 +26,7 @@ module.exports = class extends global.yoho.BaseModel {
24 26
25 lresult = { 27 lresult = {
26 id: articleData.id, 28 id: articleData.id,
27 - url: helpers.urlFormat(`/news/${articleData.id}_${articleData.cid}.html`), 29 + url: helpers.urlFormat(`/guang/news/${articleData.id}_${articleData.cid}.html`),
28 img: helpers.image(articleData.image, width, height, 1), 30 img: helpers.image(articleData.image, width, height, 1),
29 title: articleData.title, 31 title: articleData.title,
30 publishTime: articleData.update_time && moment(articleData.update_time * 1000).format('MM月DD HH:mm'), 32 publishTime: articleData.update_time && moment(articleData.update_time * 1000).format('MM月DD HH:mm'),
@@ -80,15 +82,18 @@ module.exports = class extends global.yoho.BaseModel { @@ -80,15 +82,18 @@ module.exports = class extends global.yoho.BaseModel {
80 title: contents.title, 82 title: contents.title,
81 summary: contents.summary, 83 summary: contents.summary,
82 tag: contents.tag, 84 tag: contents.tag,
  85 + syncTypeName: contents.syncTypeName || 'YOHO潮流志',
83 publishTime: contents.update_time && moment(contents.update_time * 1000).format('MM月DD HH:mm'), 86 publishTime: contents.update_time && moment(contents.update_time * 1000).format('MM月DD HH:mm'),
84 }; 87 };
85 - let content = utils.filterPhtml(contents.content, [ 88 + let content = newsUtils.filterPhtml(contents.content.replace(/www.yohobuy.com/ig, 'm.yohobuy.com'), [
86 '阅读原文', 89 '阅读原文',
87 '点击这里', 90 '点击这里',
88 '点这里' 91 '点这里'
89 ]); 92 ]);
90 93
91 - return {header: header, content: utils.filterAhtml(content)}; 94 + content = newsUtils.filterAhtml(content);
  95 +
  96 + return {header: header, content: newsUtils.imgAlt(content, contents.title, 5)};
92 } 97 }
93 98
94 detail(channel, param) { 99 detail(channel, param) {
@@ -96,16 +101,25 @@ module.exports = class extends global.yoho.BaseModel { @@ -96,16 +101,25 @@ module.exports = class extends global.yoho.BaseModel {
96 id: param.id, 101 id: param.id,
97 cid: param.cid 102 cid: param.cid
98 }; 103 };
99 - let newsAPi = new NewsAPi(this.ctx);  
100 104
101 - return newsAPi.getContentDetail(params).then(result => { 105 + return redis.all([
  106 + ['get', `global:yoho:news:detail:${params.id}-${params.cid}`]
  107 + ]).then(redisData => {
  108 + redisData = JSON.parse(redisData[0] || '{}');
  109 +
  110 + if (!redisData.data) {
  111 + return new NewsAPi(this.ctx).getContentDetail(params);
  112 + }
  113 +
  114 + return redisData;
  115 + }).then(result => {
102 let responseData = {}; 116 let responseData = {};
103 117
104 // 详情页数据 118 // 详情页数据
105 Object.assign(responseData, this._formatDetail(result, params)); 119 Object.assign(responseData, this._formatDetail(result, params));
106 120
107 // seo 121 // seo
108 - let title = _.get(responseData, 'header.title', '新闻详情页'); 122 + let title = _.get(responseData, 'header.title', '潮流资讯详情页');
109 let keywords = []; 123 let keywords = [];
110 let tags = _.compact(_.get(responseData, 'header.tag', []).map(el => { 124 let tags = _.compact(_.get(responseData, 'header.tag', []).map(el => {
111 return el.tag_name; 125 return el.tag_name;
@@ -23,7 +23,10 @@ const util = { @@ -23,7 +23,10 @@ const util = {
23 23
24 }); 24 });
25 25
26 - return $.html(); 26 + html = $.html();
  27 + $ = '';
  28 +
  29 + return html;
27 }, 30 },
28 31
29 // 过滤 a标签连接和删除html标签中的script和link脚本 32 // 过滤 a标签连接和删除html标签中的script和link脚本
@@ -34,9 +37,33 @@ const util = { @@ -34,9 +37,33 @@ const util = {
34 37
35 let $ = cheerio.load(html, {decodeEntities: false}); 38 let $ = cheerio.load(html, {decodeEntities: false});
36 39
37 - $('a').attr('href', 'javascript:void(0);').css({cursor: 'text'});// eslint-disable-line 40 + $('a').removeAttr('style').removeAttr('target').not('.a-anchor').attr('href', 'javascript:void(0);').css({cursor: 'text'});// eslint-disable-line
38 $('script,link').remove(); 41 $('script,link').remove();
39 - return $.html(); 42 +
  43 + html = $.html();
  44 + $ = '';
  45 +
  46 + return html;
  47 + },
  48 +
  49 + // 过滤 a标签连接和删除html标签中的script和link脚本
  50 + imgAlt: (html, alt, num) => {
  51 + if (!html) {
  52 + return html;
  53 + }
  54 +
  55 + let $ = cheerio.load(html, {decodeEntities: false});
  56 +
  57 + _.each($('img').slice(0, num), item => {
  58 + let $dom = $(item);
  59 +
  60 + $dom.attr('alt', $dom.attr('alt') || alt);
  61 + });
  62 +
  63 + html = $.html();
  64 + $ = '';
  65 +
  66 + return html;
40 } 67 }
41 }; 68 };
42 69
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 <div class="detail" data-id="{{id}}"> 2 <div class="detail" data-id="{{id}}">
3 {{# header}} 3 {{# header}}
4 <div class="post-title"> 4 <div class="post-title">
5 - <p class="title">{{title}}</p> 5 + <h1 class="title">{{title}}</h1>
6 {{> news-index/tvls}} 6 {{> news-index/tvls}}
7 </div> 7 </div>
8 {{/header}} 8 {{/header}}
1 <div class="time-view-like-share clearfix"> 1 <div class="time-view-like-share clearfix">
2 - <i class="iconfont">&#xe603;</i>  
3 - {{publishTime}}&nbsp;&nbsp;&nbsp;&nbsp;  
4 - {{#if pageView}}  
5 - <i class="iconfont">&#xe602;</i>  
6 - <span class="page-view">{{pageView}}</span> 2 + {{#if syncTypeName}}
  3 + <span class="page-view">来源于微信公众号:{{syncTypeName}}</span>
7 {{/if}} 4 {{/if}}
8 <div class="like-share-container"> 5 <div class="like-share-container">
  6 + <i class="iconfont">&#xe603;</i>
  7 + {{publishTime}}&nbsp;&nbsp;&nbsp;&nbsp;
  8 + {{#if pageView}}
  9 + <i class="iconfont">&#xe602;</i>
  10 + <span class="page-view">{{pageView}}</span>
  11 + {{/if}}
9 {{#like}} 12 {{#like}}
10 <i class="iconfont like-btn{{#isLiked}} like{{/isLiked}}">&#xe601;</i> 13 <i class="iconfont like-btn{{#isLiked}} like{{/isLiked}}">&#xe601;</i>
11 <span class="like-count">{{count}}</span> 14 <span class="like-count">{{count}}</span>
@@ -15,8 +15,8 @@ module.exports = app => { @@ -15,8 +15,8 @@ module.exports = app => {
15 15
16 // 业务模块 16 // 业务模块
17 app.use('/product', require('./apps/product')); 17 app.use('/product', require('./apps/product'));
  18 + app.use('/guang/news', require('./apps/news'));// seo-潮流资讯页
18 app.use('/guang', require('./apps/guang')); 19 app.use('/guang', require('./apps/guang'));
19 - app.use('/news', require('./apps/news'));  
20 app.use('/activity', require('./apps/activity')); 20 app.use('/activity', require('./apps/activity'));
21 app.use('/cart', require('./apps/cart')); 21 app.use('/cart', require('./apps/cart'));
22 22
@@ -62,7 +62,7 @@ export class IndexView extends View { @@ -62,7 +62,7 @@ export class IndexView extends View {
62 62
63 this.indexModel.loadMoreAjax({ 63 this.indexModel.loadMoreAjax({
64 type: 'GET', 64 type: 'GET',
65 - url: '/news/index/page', 65 + url: '/guang/news/index/page',
66 dataType: 'html', 66 dataType: 'html',
67 data: that.navState[index] 67 data: that.navState[index]
68 }).then(rdata => { 68 }).then(rdata => {
@@ -87,6 +87,9 @@ $focus-size: 42px; @@ -87,6 +87,9 @@ $focus-size: 42px;
87 87
88 img { 88 img {
89 height: auto; 89 height: auto;
  90 + width: auto;
  91 + max-width: 100%;
  92 + color: #fff;
90 } 93 }
91 } 94 }
92 95
@@ -877,6 +880,11 @@ $focus-size: 42px; @@ -877,6 +880,11 @@ $focus-size: 42px;
877 overflow: visible; 880 overflow: visible;
878 } 881 }
879 } 882 }
  883 +
  884 + .a-anchor {
  885 + color: #93b4c5;
  886 + text-decoration: underline;
  887 + }
880 } 888 }
881 889
882 .news-detail-page.menu-open { 890 .news-detail-page.menu-open {