feat: telegram blog (CHANGELOG) (#3228)
* feat: telegram blog (CHANGELOG) * docs: update doc
This commit is contained in:
parent
71cd089454
commit
3173e5e216
|
|
@ -54,6 +54,10 @@ pageClass: routes
|
|||
|
||||
<RouteEn author="DIYgod" example="/telegram/stickerpack/DIYgod" path="/telegram/stickerpack/:name" :paramsDesc="['Sticker Pack name, available in the sharing URL']"/>
|
||||
|
||||
### Telegram Blog
|
||||
|
||||
<RouteEn author="fengkx" example="/telegram/blog" path="/telegram/blog" />
|
||||
|
||||
## Twitter
|
||||
|
||||
### User timeline
|
||||
|
|
|
|||
|
|
@ -360,6 +360,10 @@ pageClass: routes
|
|||
|
||||
:::
|
||||
|
||||
### Telegram Blog
|
||||
|
||||
<Route author="fengkx" example="/telegram/blog" path="/telegram/blog" />
|
||||
|
||||
</Route>
|
||||
|
||||
### 列表时间线
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
};
|
||||
Loading…
Reference in New Issue