From fa719b8d56b4ed7b1c5b4103473246535dbc634f Mon Sep 17 00:00:00 2001 From: aha2mao Date: Tue, 19 Feb 2019 11:38:22 +0800 Subject: [PATCH] feat: Hexo Yilia theme RSS support (#1552) --- docs/README.md | 2 ++ docs/en/README.md | 2 ++ lib/router.js | 1 + lib/routes/hexo/yilia.js | 43 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 lib/routes/hexo/yilia.js diff --git a/docs/README.md b/docs/README.md index 71465f538..14425d6c1 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2608,6 +2608,8 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的 + + ### Keep diff --git a/docs/en/README.md b/docs/en/README.md index 07f073e9e..cffca3241 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -358,6 +358,8 @@ EZTV provides an official RSS feed of all torrents: https://eztv.ag/ezrss.xml + + ### Google diff --git a/lib/router.js b/lib/router.js index 25fa81afb..77eae915b 100644 --- a/lib/router.js +++ b/lib/router.js @@ -412,6 +412,7 @@ router.get('/tuicool/mags/:type', require('./routes/tuicool/mags')); // Hexo router.get('/hexo/next/:url', require('./routes/hexo/next')); +router.get('/hexo/yilia/:url', require('./routes/hexo/yilia')); // 小米 router.get('/mi/crowdfunding', require('./routes/mi/crowdfunding')); diff --git a/lib/routes/hexo/yilia.js b/lib/routes/hexo/yilia.js new file mode 100644 index 000000000..964f673fa --- /dev/null +++ b/lib/routes/hexo/yilia.js @@ -0,0 +1,43 @@ +const cheerio = require('cheerio'); +const axios = require('../../utils/axios'); + +module.exports = async (ctx) => { + const url = `http://${ctx.params.url}`; + const res = await axios.get(`${url}/archives`); + const data = res.data; + const $ = cheerio.load(data); + const list = $('.archive-type-post'); + const item = await Promise.all( + Array.from(list).map(async (each) => { + const itemLink = each.find('.archive-article-title').attr('href'); + const item = { + title: each.find('.archive-article-title').text(), + link: encodeURI(`${url}${itemLink}`), + }; + const key = item.link; + const value = await ctx.cache.get(key); + + if (value) { + item.description = value; + } else { + const storyDeatil = await axios.get(item.link); + const data = storyDeatil.data; + const $ = cheerio.load(data); + item.pubDate = $('time').attr('datetime'); + item.description = $('.article-entry').html(); + ctx.cache.set(key, item.description, 6 * 60 * 60); + } + return Promise.resolve(item); + }) + ); + ctx.state.data = { + title: $('.header-author') + .find('a') + .text(), + link: url, + description: $('.header-subtitle') + .eq(0) + .text(), + item, + }; +};