diff --git a/docs/en/other.md b/docs/en/other.md index 38e75f8d37..439a2ef9ff 100644 --- a/docs/en/other.md +++ b/docs/en/other.md @@ -111,6 +111,18 @@ Official Website: [https://www.ssm.gov.mo/apps1/PreventWuhanInfection/en.aspx](h +## King Arthur + +### Baking + + + +| Story | Recipes | Tips and Techniques | +| ----- | ------- | ------------------- | +| story | recipes | tips-and-techniques | + + + ## MITRE ### All Publications diff --git a/lib/router.js b/lib/router.js index e0b658e98a..fcad8a96cc 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/kingarthur/index.js b/lib/routes/kingarthur/index.js new file mode 100644 index 0000000000..0226514387 --- /dev/null +++ b/lib/routes/kingarthur/index.js @@ -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, + }; +};