diff --git a/docs/blog.md b/docs/blog.md index 4b8e692169..46f304561c 100644 --- a/docs/blog.md +++ b/docs/blog.md @@ -16,6 +16,16 @@ pageClass: routes +## Hedwig.pub + + + +| 呆唯的 Newsletter | 0neSe7en 的技术周刊 | 地心引力 | 宪学宪卖 | Comeet 每周精选 | 无鸡之谈 | 我有一片芝麻地 | +| ----------------- | ------------------- | -------- | -------- | --------------- | -------- | -------------- | +| hirasawayui | se7en | walnut | themez | comeet | sunskyxh | zmd | + +> 原则上只要是{type}.hedwig.pub 都可以匹配。 + ## Hexo ### Next 主题博客 diff --git a/lib/router.js b/lib/router.js index 671de29ea0..f64355269b 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2305,6 +2305,9 @@ router.get('/wolley/host/:host', require('./routes/wolley/host')); // 西安交大 router.get('/xjtu/dean/:subpath+', require('./routes/universities/xjtu/dean')); +// 我有一片芝麻地 +router.get('/blogs/hedwig/:type', require('./routes/blogs/hedwig')); + // LoveHeaven router.get('/loveheaven/update/:slug', require('./routes/loveheaven/update')); diff --git a/lib/routes/blogs/hedwig.js b/lib/routes/blogs/hedwig.js new file mode 100644 index 0000000000..e8f84b32cc --- /dev/null +++ b/lib/routes/blogs/hedwig.js @@ -0,0 +1,62 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const type = ctx.params.type; + + const url = 'https://' + `${type}` + '.hedwig.pub'; + const res = await got({ + method: 'get', + url: url, + }); + const $ = cheerio.load(res.data); + const title = $('div[class="StyledBox-sc-13pk1d4-0 heWGCm"]') + .find('h1') + .text(); + + const list = $('div[class="StyledBox-sc-13pk1d4-0 czKiZd"]') + .find('div[class="StyledBox-sc-13pk1d4-0 czKiZd"]') + .find('div[class="StyledBox-sc-13pk1d4-0 czKiZd"]') + .map((i, e) => { + const element = $(e); + const title = element + .find('a') + .find('h3') + .text(); + const link = url + element.find('a').attr('href'); + return { + title: title, + description: '', + link: link, + }; + }) + .get(); + + const result = await Promise.all( + list.map(async (item) => { + const link = item.link; + + const cache = await ctx.cache.get(link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const itemReponse = await got.get(link); + const itemElement = cheerio.load(itemReponse.data); + // Remove duplicate title + itemElement('.StyledBox-sc-13pk1d4-0 .bpdfin') + .find('h1[class="StyledHeading-sc-1rdh4aw-0 kIYNxP"]') + .remove(); + item.description = itemElement('.StyledBox-sc-13pk1d4-0 .bpdfin').html(); + + ctx.cache.set(link, JSON.stringify(item)); + return Promise.resolve(item); + }) + ); + + ctx.state.data = { + title: 'Ⓙ Hedwig - ' + title, + link: 'https://' + `${type}` + '.hedwig.pub', + item: result, + }; +};