重构了yilia主题的hexo rss化 (#1634)

This commit is contained in:
aha2mao 2019-02-28 14:29:41 +08:00 committed by DIYgod
parent 4299a4188c
commit ddad8aa642
3 changed files with 21 additions and 37 deletions

View File

@ -2733,7 +2733,7 @@ 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 不带协议头']"/>
<route name="Yilia 主题博客" author="aha2mao" example="/hexo/yilia/cloudstone.xin" path="/hexo/yilia/:url" :paramsDesc="['博客 Url 不带协议头']"/>
### Keep

View File

@ -362,7 +362,7 @@ 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://)']" />
<routeEn name="Blog using Yilia theme" author="aha2mao" path="/hexo/yilia/:url" example="/hexo/yilia/cloudstone.xin" :paramsDesc="['the blog URL without the protocol (http:// and https://)']" />
### Google

View File

@ -3,45 +3,29 @@ const axios = require('../../utils/axios');
module.exports = async (ctx) => {
const url = `http://${ctx.params.url}`;
const res = await axios.get(`${url}/archives`);
const res = await axios.get(url);
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);
const authorInfo = $('.left-col').find('#header');
const title = authorInfo.find('.header-author').text();
const subtitle = authorInfo.find('.header-subtitle').text();
const articleNodeList = $('article');
const articles = Array.from(articleNodeList).map((article) => {
const each = $(article);
const titleEl = each.find('.article-title');
return {
title: titleEl.text(),
link: encodeURI(`${url}${titleEl.attr('href')}`),
description: each.find('.article-entry').text(),
pubDate: each.find('time').attr('datetime'),
};
});
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(),
title,
link: url,
description: $('.header-subtitle')
.eq(0)
.text(),
item,
description: subtitle,
item: articles,
};
};