feat: Hexo Yilia theme RSS support (#1552)

This commit is contained in:
aha2mao
2019-02-19 11:38:22 +08:00
committed by DIYgod
parent ea5d33dcc3
commit fa719b8d56
4 changed files with 48 additions and 0 deletions
+2
View File
@@ -2608,6 +2608,8 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
<route name="Next 主题博客" author="fengkx" example="/hexo/next/fengkx.top" path="/hexo/next/:url" :paramsDesc="['博客 Url 不带协议头']"/>
<route name="Yilia 主题博客" author="aha2mao" example="/hexo/yilia/litten.me" path="/hexo/yilia/:url" :paramsDesc="['博客 Url 不带协议头']"/>
### Keep
<route name="运动日记" author="Dectinc DIYgod" example="/keep/user/556b02c1ab59390afea671ea" path="/keep/user/:id" :paramsDesc="['Keep 用户 id']"/>
+2
View File
@@ -358,6 +358,8 @@ EZTV provides an official RSS feed of all torrents: https://eztv.ag/ezrss.xml
<routeEn name="Blog using Next theme" author="fengkx" path="/hexo/next/:url" example="/hexo/next/fengkx.top" :paramsDesc="['the blog URL without the protocol (http:// and https://)']" />
<routeEn name="Blog using Yilia theme" author="aha2mao" path="/hexo/yilia/:url" example="/hexo/yilia/litten.me" :paramsDesc="['the blog URL without the protocol (http:// and https://)']" />
### Google
<routeEn name="Google Scholar Keywords Monitoring" author="HenryQW" path="/google/scholar/:query" example="/google/scholar/data+visualization" :paramsDesc="['query statement which supports「Basic」and「Advanced」modes']" >
+1
View File
@@ -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'));
+43
View File
@@ -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,
};
};