feat: add King Arthur (#6820)

This commit is contained in:
Logan Rockmore
2021-02-03 22:17:57 -05:00
committed by GitHub
parent c8275d890d
commit de4d088357
3 changed files with 75 additions and 0 deletions
+12
View File
@@ -111,6 +111,18 @@ Official Website: [https://www.ssm.gov.mo/apps1/PreventWuhanInfection/en.aspx](h
</RouteEn>
## King Arthur
### Baking
<RouteEn author="loganrockmore" example="/kingarthur/story" path="/instapaper/:category">
| Story | Recipes | Tips and Techniques |
| ----- | ------- | ------------------- |
| story | recipes | tips-and-techniques |
</RouteEn>
## MITRE
### All Publications
+3
View File
@@ -3916,4 +3916,7 @@ router.get('/shinybbs/latest', require('./routes/shinybbs/latest'));
// 天眼查
router.get('/tianyancha/hot', require('./routes/tianyancha/hot'));
// King Arthur
router.get('/kingarthur/:type', require('./routes/kingarthur/index'));
module.exports = router;
+60
View File
@@ -0,0 +1,60 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
module.exports = async (ctx) => {
const type = ctx.params.type;
const response = await got({
method: 'get',
url: `https://www.kingarthurbaking.com/blog/category/${type}/`,
});
const url = response.url; // got will make sure that this is the final URL after redirects
const data = response.data;
const $ = cheerio.load(data);
const title = $('meta[property="og:site_name"]').attr('content');
const description = $('meta[property="og:site_name"]').attr('content');
const list = $('div.article > a')
.slice(0, 10)
.map((_, item) => {
item = $(item);
const itemURL = new URL(item.attr('href'), url).href;
return {
link: itemURL,
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
const body = content('div.article__body');
// remove extra body content that we don't want to see
body.find('blockquote').remove();
item.title = content('meta[property="og:title"]').attr('content');
item.description = body.html();
item.pubDate = new Date(content('div.stat__item--date > span').text()).toUTCString();
return item;
})
)
);
ctx.state.data = {
title,
link: url,
description,
item: items,
};
};