feat: add day one blog (#6478)
This commit is contained in:
@@ -80,6 +80,13 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more
|
||||
| | 2 | 6 | 14 | 3 | 4 | 10 | 8 | 1 | 9 | 7 |
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## Day One
|
||||
|
||||
### Blog
|
||||
|
||||
<RouteEn author="nczitzk" example="/dayone/blog" path="/dayone/blog"/>
|
||||
|
||||
## DeepMind
|
||||
|
||||
### Blog
|
||||
|
||||
@@ -124,6 +124,12 @@ pageClass: routes
|
||||
|
||||
<Route author="kt286 HaitianLiu" example="/cnbeta" path="/cnbeta"/>
|
||||
|
||||
## Day One
|
||||
|
||||
### Blog
|
||||
|
||||
<Route author="nczitzk" example="/dayone/blog" path="/dayone/blog"/>
|
||||
|
||||
## DeepL
|
||||
|
||||
### Blog
|
||||
|
||||
@@ -3724,6 +3724,8 @@ router.get('/mathunion/fields-medal', require('./routes/mathunion/fields-medal')
|
||||
// ACM
|
||||
router.get('/acm/amturingaward', require('./routes/acm/amturingaward'));
|
||||
|
||||
// Day One
|
||||
router.get('/dayone/blog', require('./routes/dayone/blog'));
|
||||
// 滴答清单
|
||||
router.get('/dida365/habit/checkins', require('./routes/dida365/habit-checkins'));
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = 'https://dayoneapp.com';
|
||||
const currentUrl = `${rootUrl}/blog`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('h3 a')
|
||||
.slice(0, 20)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
const info = item.parent().next().text().split(' by ');
|
||||
|
||||
return {
|
||||
author: info[1],
|
||||
title: item.text(),
|
||||
link: `${rootUrl}${item.attr('href')}`,
|
||||
pubDate: new Date(info[0]).toUTCString(),
|
||||
};
|
||||
})
|
||||
.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 description = content('.blog-layout');
|
||||
|
||||
description.children().last().remove();
|
||||
content('h1').next().remove();
|
||||
content('h1').remove();
|
||||
|
||||
item.description = description.html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user