Authored by 李靖

prefix router miplink

@@ -9,7 +9,7 @@ const productDetailModel = require(`${mRoot}/product-detail`); @@ -9,7 +9,7 @@ const productDetailModel = require(`${mRoot}/product-detail`);
9 exports.index = (req, res, next) => { 9 exports.index = (req, res, next) => {
10 co(function* () { 10 co(function* () {
11 let params = { 11 let params = {
12 - productSkn: req.params[0], 12 + productSkn: req.params.skn,
13 protocol: req.protocol 13 protocol: req.protocol
14 }; 14 };
15 15
@@ -5,15 +5,15 @@ module.exports = { @@ -5,15 +5,15 @@ module.exports = {
5 /** 5 /**
6 * 分离 CSS 6 * 分离 CSS
7 * @param {*} $ 7 * @param {*} $
8 - * @param {*} prefix 8 + * @param {*} option
9 */ 9 */
10 - processStyle($, prefix) { 10 + processStyle($, option) {
11 let css = []; 11 let css = [];
12 12
13 $('*').each(function(index) { 13 $('*').each(function(index) {
14 let $this = $(this); 14 let $this = $(this);
15 let localStyle = $this.attr('style'); 15 let localStyle = $this.attr('style');
16 - let className = `yoho-inline-style-${prefix}-${index}`; 16 + let className = `yoho-inline-style-${option.prefix}-${index}`;
17 17
18 if (localStyle) { 18 if (localStyle) {
19 css.push(`.${className}{${localStyle}}`); 19 css.push(`.${className}{${localStyle}}`);
@@ -28,13 +28,13 @@ module.exports = { @@ -28,13 +28,13 @@ module.exports = {
28 * 替换标签 28 * 替换标签
29 * @param {*} $ 29 * @param {*} $
30 */ 30 */
31 - processTag($, prefix) { 31 + processTag($, option) {
32 let css = []; 32 let css = [];
33 33
34 // mip-anim 34 // mip-anim
35 $('img[src*=".gif"]').each(function() { 35 $('img[src*=".gif"]').each(function() {
36 let $this = $(this); 36 let $this = $(this);
37 - let mipAnim = `<mip-anim layout="responsive" width="350" height="263" src="${$this.attr('src')}" alt="${$this.attr('alt') || ''}" class="${$this.attr('class') || ''}"></mip-anim>`; // eslint-disable-line 37 + let mipAnim = `<mip-anim layout="container" src="${$this.attr('src')}" alt="${$this.attr('alt') || ''}" class="${$this.attr('class') || ''}"></mip-anim>`; // eslint-disable-line
38 38
39 $this.replaceWith(mipAnim); 39 $this.replaceWith(mipAnim);
40 }); 40 });
@@ -50,7 +50,7 @@ module.exports = { @@ -50,7 +50,7 @@ module.exports = {
50 // mip-video 50 // mip-video
51 $('video').each(function() { 51 $('video').each(function() {
52 let $this = $(this); 52 let $this = $(this);
53 - let mipVideo = `<mip-video layout="responsive" width="350" height="263" poster="${$this.attr('poster') || ''}" src="${$this.attr('src')}" alt="${$this.attr('alt') || ''}" class="${$this.attr('class') || ''}"></mip-video>`; // eslint-disable-line 53 + let mipVideo = `<mip-video layout="container" poster="${$this.attr('poster') || ''}" src="${$this.attr('src')}" alt="${$this.attr('alt') || ''}" class="${$this.attr('class') || ''}"></mip-video>`; // eslint-disable-line
54 54
55 $this.replaceWith(mipVideo); 55 $this.replaceWith(mipVideo);
56 }); 56 });
@@ -66,7 +66,7 @@ module.exports = { @@ -66,7 +66,7 @@ module.exports = {
66 // mip-iframe 66 // mip-iframe
67 $('iframe').each(function() { 67 $('iframe').each(function() {
68 let $this = $(this); 68 let $this = $(this);
69 - let mipIframe = `<mip-iframe layout="responsive" width="350" height="263" src="${$this.attr('src')}" class="${$this.attr('class') || ''}"></mip-iframe>`; // eslint-disable-line 69 + let mipIframe = `<mip-iframe layout="container" src="${$this.attr('src')}" class="${$this.attr('class') || ''}"></mip-iframe>`; // eslint-disable-line
70 70
71 $this.replaceWith(mipIframe); 71 $this.replaceWith(mipIframe);
72 }); 72 });
@@ -80,7 +80,7 @@ module.exports = { @@ -80,7 +80,7 @@ module.exports = {
80 }); 80 });
81 81
82 // mip-link 82 // mip-link
83 - if (prefix.mipLint) { 83 + if (option.mipLink) {
84 $('a').each(function() { 84 $('a').each(function() {
85 let $this = $(this); 85 let $this = $(this);
86 let mipLink = `<a data-type="mip" class="${$this.attr('class') || ''}" 86 let mipLink = `<a data-type="mip" class="${$this.attr('class') || ''}"
@@ -107,17 +107,17 @@ module.exports = { @@ -107,17 +107,17 @@ module.exports = {
107 /** 107 /**
108 * 处理 HTML 为 MIP 所需要的格式 108 * 处理 HTML 为 MIP 所需要的格式
109 * @param {*} html HTML 109 * @param {*} html HTML
110 - * @param {*} prefix CSS 前缀 110 + * @param {*} option.prefix CSS 前缀
111 */ 111 */
112 112
113 - process(html = '', prefix = 0) { 113 + process(html = '', option = '') {
114 html = _.isString(html) ? html : ''; 114 html = _.isString(html) ? html : '';
115 115
116 let $ = cheerio.load(html, { 116 let $ = cheerio.load(html, {
117 decodeEntities: false 117 decodeEntities: false
118 }); 118 });
119 - let inlineStyle = this.processStyle($, prefix); // 必须先处理内联样式  
120 - let tagHtml = this.processTag($, prefix); 119 + let inlineStyle = this.processStyle($, option); // 必须先处理内联样式
  120 + let tagHtml = this.processTag($, option);
121 121
122 return { 122 return {
123 mipHtml: tagHtml.mipHtml, 123 mipHtml: tagHtml.mipHtml,
@@ -163,7 +163,7 @@ class ProductDetail extends global.yoho.BaseModel { @@ -163,7 +163,7 @@ class ProductDetail extends global.yoho.BaseModel {
163 if (_.get(result, '[2]')) { 163 if (_.get(result, '[2]')) {
164 // 处理a标签 164 // 处理a标签
165 let option = { 165 let option = {
166 - mipLint: true 166 + mipLink: true
167 }; 167 };
168 168
169 let resultHtml = _.isString(result[2]) ? result[2] : ''; 169 let resultHtml = _.isString(result[2]) ? result[2] : '';
@@ -23,6 +23,6 @@ router.get(/^\/guang\/(.*?)\.html/, rewrite.resolve, guang.detailIndex); @@ -23,6 +23,6 @@ router.get(/^\/guang\/(.*?)\.html/, rewrite.resolve, guang.detailIndex);
23 router.get('/chanpin/:id.html', chanpin.index); 23 router.get('/chanpin/:id.html', chanpin.index);
24 router.get('/list/:id.html', chanpin.redirect); 24 router.get('/list/:id.html', chanpin.redirect);
25 25
26 -router.get(/^\/product\/(\d+)\.html/, productDetail.index); 26 +router.get('/product/:skn.html', productDetail.index);
27 27
28 module.exports = router; 28 module.exports = router;
@@ -253,7 +253,7 @@ const processArticleDetail = (articleContent, isApp, gender, isWeixin, isqq, isW @@ -253,7 +253,7 @@ const processArticleDetail = (articleContent, isApp, gender, isWeixin, isqq, isW
253 let newText = ''; 253 let newText = '';
254 254
255 if (isMip) { 255 if (isMip) {
256 - let mipHtml = mipUtils.process(value.text.data.text, index); 256 + let mipHtml = mipUtils.process(value.text.data.text, {prefix: index});
257 257
258 newText = mipHtml.mipHtml; 258 newText = mipHtml.mipHtml;
259 localStyle.push(mipHtml.css); 259 localStyle.push(mipHtml.css);