Authored by 郝肖肖

'sitemap'

... ... @@ -40,7 +40,8 @@ app.get('/goods-:start.xml', cseo.index);
app.get('/auto-goods.html', cseo.autoGoodsXml);
app.get('/seo/setTask', cseo.setTask);
app.get('/seo/delTask', cseo.delTask);
app.get('/demo-xml', cseo.demoXml);
app.get('/seo/sitemap.xml', cseo.siteMapXml);
app.get('/demo.xml', cseo.demoXml);
// 定时任务 主动推送和生成xml
seo.start();
... ...
... ... @@ -48,9 +48,19 @@ const demoXml = (req, res) => {
res.render('seo/demo-xml');
};
const siteMapXml = (req, res) => {
let sitemap = new Array(26).fill().map((val, k) => {
return `http://spiderwebhook.yoho.cn/dist/goods-xml/goods-${k + 1}.xml`;
});
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
res.render('seo/site-map', {sitemap});
};
module.exports = {
index,
autoGoodsXml,
siteMapXml,
setTask,
delTask,
demoXml
... ...
... ... @@ -9,7 +9,7 @@ const helpers = global.yoho.helpers;
const goodsHbs = require(`${ROOT_PATH}/hbs/partials/seo/index.hbs`);
const util = require(`${ROOT_PATH}/libs/util`);
const redis = require(`${ROOT_PATH}/libs/redis`);
const SIZE = 4000;
const SIZE = 3000;
const GOODS_URL = 'http://spiderwebhook.yoho.cn/dist/goods-xml';
class SeoIndexModel extends global.yoho.BaseModel {
... ... @@ -34,12 +34,13 @@ class SeoIndexModel extends global.yoho.BaseModel {
const fWrite = fs.createWriteStream(`${ROOT_PATH}/public/dist/goods-xml/${fileName}`);
fWrite.write(goodsHbs({products: result}).replace(/\s+/g, ' '));// max 9.5M
fWrite.write(goodsHbs({products: result}));// max 9.5M
fWrite.end();
result = [];
console.log(`${GOODS_URL}/${fileName} over...`);
console.log(`${GOODS_URL}/${fileName} over...`);
return {code: 200, data: `${GOODS_URL}/${fileName}`};
});
}
... ... @@ -56,10 +57,6 @@ class SeoIndexModel extends global.yoho.BaseModel {
let data = _.get(rdata, 'data', {});
let productLists = _.get(rdata, 'data.product_list', []);
if (data.page > data.page_total) {
return products;
}
_.each(productLists, item => {
let images = [];
... ... @@ -134,6 +131,10 @@ class SeoIndexModel extends global.yoho.BaseModel {
rdata = [];
productLists = [];
if (data.page >= data.page_total) {
return products;
}
return this.searchGoodsHandle(Object.assign({}, params, {page: ++params.page}), products, sort);
});
}
... ...
<?xml version="1.0" encoding="utf-8" ?>
<sitemapindex>
{{#sitemap}}
<sitemap>
<loc>
{{.}}
</loc>
</sitemap>
{{/sitemap}}
</sitemapindex>
... ...
... ... @@ -11,7 +11,7 @@
<fromSrc>{{fromSrc}}</fromSrc>
{{#images}}
<image>
<contentUrl><![CDATA[{{{contentUrl}}}]]></contentUrl>
<contentUrl>{{{contentUrl}}}</contentUrl>
<height>{{height}}</height>
<width>{{width}}</width>
<description>{{description}}</description>
... ...