From 6dee8af7098dc44c7f43ee1a9bcf2f5a76199ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=89=E5=87=89?= Date: Tue, 16 Oct 2018 18:20:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=EF=BC=9A=E7=85=8E=E8=9B=8B-?= =?UTF-8?q?=E7=83=AD=E6=A6=9C-=E5=A6=B9=E5=AD=90=E5=9B=BE=20(#899)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加:有品-每日上新 * 修复 summary 字段错误 * 将 youpin 模块转移至 mi 目录下,并更新文档 * 增加:煎蛋-热榜-妹子图 * 修改文档,妹子图与热榜-妹子图合并 --- docs/README.md | 6 +++++- routes/jandan/pic.js | 44 +++++++++++++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/docs/README.md b/docs/README.md index a3c9da080..0f594f093 100644 --- a/docs/README.md +++ b/docs/README.md @@ -767,7 +767,11 @@ GitHub 官方也提供了一些 RSS: - + + +| 妹子图 | 热榜 | +| ------ | -------- | +| ooxx | top-ooxx | ### 喷嚏 diff --git a/routes/jandan/pic.js b/routes/jandan/pic.js index e953bc882..4c894e9c4 100644 --- a/routes/jandan/pic.js +++ b/routes/jandan/pic.js @@ -20,7 +20,7 @@ module.exports = async (ctx) => { const $ = cheerio.load(response.data); - const items = Array(); + const items = []; $('.commentlist > li').each((_, item) => { // Get current comment id, if comment_id is 'adsense', just need to skip.. const comment_id = $(item).attr('id'); @@ -29,32 +29,43 @@ module.exports = async (ctx) => { } // Get current comment's link. - const link = $(item) + let link = $(item) .find('.righttext') .find('a') .attr('href'); - if (link === undefined) { - return; + + if (link !== undefined) { + link = `http:${link}`; + } else { + // sub_model 为 top-ooxx 时无链接 + link = ''; } - // Get current comment's images. - // TODO: should support multiple images. - let img_url = $(item) - .find('.text') - .find('.img-hash') - .html(); - if (img_url === null) { + const imgList = []; + + $(item) + .find('.text .img-hash') + .each((_, item) => { + const imgUrl = $(item).html(); + + if (imgUrl !== undefined) { + imgList.push(jandan_decode(imgUrl).replace(/(\/\/\w+\.sinaimg\.cn\/)(\w+)(\/.+\.(gif|jpg|jpeg))/, '$1large$3')); + } + }); + if (imgList.length === 0) { return; } - img_url = jandan_decode(img_url); - img_url = img_url.replace(/(\/\/\w+\.sinaimg\.cn\/)(\w+)(\/.+\.(gif|jpg|jpeg))/, '$1large$3'); // TODO: should load user's comments. items.push({ + guid: comment_id, title: comment_id, - description: ``, - link: `http:${link}`, + description: imgList.reduce((description, imgUrl) => { + description += `
`; + return description; + }, ''), + link, }); }); @@ -66,6 +77,9 @@ module.exports = async (ctx) => { } else if (sub_model === 'ooxx') { rss_title = '煎蛋妹子图'; description = '这儿才是正版妹子图。'; + } else if (sub_model === 'top-ooxx') { + rss_title = '煎蛋妹子图热榜'; + description = ''; // TODO: 这里写啥好 } ctx.state.data = {