diff --git a/docs/en/social-media.md b/docs/en/social-media.md index 4dbec2550..0cc34b4d0 100644 --- a/docs/en/social-media.md +++ b/docs/en/social-media.md @@ -54,6 +54,10 @@ pageClass: routes +### Telegram Blog + + + ## Twitter ### User timeline diff --git a/docs/social-media.md b/docs/social-media.md index 47340ead3..a92aed9ba 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -360,6 +360,10 @@ pageClass: routes ::: +### Telegram Blog + + + ### 列表时间线 diff --git a/lib/router.js b/lib/router.js index cc97555e5..915d692a4 100644 --- a/lib/router.js +++ b/lib/router.js @@ -241,6 +241,7 @@ router.get('/v2ex/post/:postid', require('./routes/v2ex/post')); // Telegram router.get('/telegram/channel/:username', require('./routes/telegram/channel')); router.get('/telegram/stickerpack/:name', require('./routes/telegram/stickerpack')); +router.get('/telegram/blog', require('./routes/telegram/blog')); // readhub router.get('/readhub/category/:category', require('./routes/readhub/category')); diff --git a/lib/routes/telegram/blog.js b/lib/routes/telegram/blog.js new file mode 100644 index 000000000..11e17394a --- /dev/null +++ b/lib/routes/telegram/blog.js @@ -0,0 +1,36 @@ +const cherrio = require('cheerio'); +const got = require('@/utils/got'); + +module.exports = async (ctx, next) => { + const link = 'https://telegram.org/blog'; + + const res = await got(link); + const $$ = cherrio.load(res.body); + + const items = await Promise.all( + $$('h1#dev_page_title') + .get() + .map(async (each) => { + const $ = $$(each); + const a = $.find('a[href]').first(); + const link = 'https://telegram.org' + a.attr('href'); + return await ctx.cache.tryGet(link, async () => { + const result = await got(link); + const $ = cherrio.load(result.body); + return { + title: $('#dev_page_title').text(), + link, + pubDate: new Date($('[property="article:published_time"]').attr('content')).toUTCString(), + description: $('#dev_page_content_wrap').html(), + }; + }); + }) + ); + + ctx.state.data = { + title: $$('title').text(), + link, + item: items, + }; + await next(); +};