mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-11 23:59:56 +08:00
feat(route): add World Happiness Report (#7223)
Co-authored-by: NeverBehave <gayhub@never.pet>
This commit is contained in:
@@ -412,6 +412,16 @@ Provides all of the Thrillist articles with the specified tag.
|
|||||||
|
|
||||||
<RouteEn author="loganrockmore" example="/vulture/movies" path="/vulture/:tag/:excludetags?" :paramsDesc="['Tag', 'Comma-delimited list of tags. If an article includes one of these tags, it will be excluded from the RSS feed.']" />
|
<RouteEn author="loganrockmore" example="/vulture/movies" path="/vulture/:tag/:excludetags?" :paramsDesc="['Tag', 'Comma-delimited list of tags. If an article includes one of these tags, it will be excluded from the RSS feed.']" />
|
||||||
|
|
||||||
|
## World Happiness
|
||||||
|
|
||||||
|
### Blog
|
||||||
|
|
||||||
|
<RouteEn author="nczitzk" example="/worldhappiness/blog" path="/worldhappiness/blog"/>
|
||||||
|
|
||||||
|
### Archive
|
||||||
|
|
||||||
|
<RouteEn author="nczitzk" example="/worldhappiness/archive" path="/worldhappiness/archive"/>
|
||||||
|
|
||||||
## World Health Organization | WHO
|
## World Health Organization | WHO
|
||||||
|
|
||||||
### Newsroom
|
### Newsroom
|
||||||
|
|||||||
@@ -679,6 +679,16 @@ Supported sub-sites:
|
|||||||
|
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
|
## World Happiness
|
||||||
|
|
||||||
|
### Blog
|
||||||
|
|
||||||
|
<Route author="nczitzk" example="/worldhappiness/blog" path="/worldhappiness/blog"/>
|
||||||
|
|
||||||
|
### Archive
|
||||||
|
|
||||||
|
<Route author="nczitzk" example="/worldhappiness/archive" path="/worldhappiness/archive"/>
|
||||||
|
|
||||||
## ZAKER
|
## ZAKER
|
||||||
|
|
||||||
### source
|
### source
|
||||||
|
|||||||
@@ -4158,6 +4158,9 @@ router.get('/tanchinese/:category?', require('./routes/tanchinese'));
|
|||||||
// Harvard
|
// Harvard
|
||||||
router.get('/harvard/health/blog', require('./routes/universities/harvard/health/blog'));
|
router.get('/harvard/health/blog', require('./routes/universities/harvard/health/blog'));
|
||||||
|
|
||||||
|
// World Happiness Report
|
||||||
|
router.get('/worldhappiness/blog', require('./routes/worldhappiness/blog'));
|
||||||
|
router.get('/worldhappiness/archive', require('./routes/worldhappiness/archive'));
|
||||||
// 中国纺织经济信息网
|
// 中国纺织经济信息网
|
||||||
router.get('/ctei/news/:id?', require('./routes/ctei/news'));
|
router.get('/ctei/news/:id?', require('./routes/ctei/news'));
|
||||||
// 时事一点通
|
// 时事一点通
|
||||||
|
|||||||
50
lib/routes/worldhappiness/archive.js
Normal file
50
lib/routes/worldhappiness/archive.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
const { parseDate } = require('@/utils/parse-date');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const rootUrl = 'https://worldhappiness.report';
|
||||||
|
const currentUrl = `${rootUrl}/archive`;
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: currentUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
|
||||||
|
const list = $('.archived-report a')
|
||||||
|
.map((_, item) => {
|
||||||
|
item = $(item);
|
||||||
|
return {
|
||||||
|
title: item.text(),
|
||||||
|
link: `${rootUrl}${item.attr('href')}`,
|
||||||
|
pubDate: parseDate(item.text().split(' ').pop(), 'YYYY'),
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.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);
|
||||||
|
|
||||||
|
content('.report-title').remove();
|
||||||
|
|
||||||
|
item.description = content('.report-meta').html() + content('.report-body').html();
|
||||||
|
|
||||||
|
return item;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: $('title').text(),
|
||||||
|
link: currentUrl,
|
||||||
|
item: items,
|
||||||
|
};
|
||||||
|
};
|
||||||
48
lib/routes/worldhappiness/blog.js
Normal file
48
lib/routes/worldhappiness/blog.js
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
const { parseDate } = require('@/utils/parse-date');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const rootUrl = 'https://worldhappiness.report';
|
||||||
|
const currentUrl = `${rootUrl}/blog`;
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: currentUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
|
||||||
|
const list = $('.post-link')
|
||||||
|
.map((_, item) => {
|
||||||
|
item = $(item);
|
||||||
|
return {
|
||||||
|
title: item.children('h3').text(),
|
||||||
|
link: `${rootUrl}${item.attr('href')}`,
|
||||||
|
pubDate: parseDate(item.children('.post-date').attr('datetime')),
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.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);
|
||||||
|
|
||||||
|
item.description = content('.post-body').html();
|
||||||
|
|
||||||
|
return item;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: $('title').text(),
|
||||||
|
link: currentUrl,
|
||||||
|
item: items,
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user