feat(route): add Global Disinformation Index (#7217)

* feat: add Global Disinformation Index

* fix pubDate

* refactor: migirate to v2

* fix(radar): https

Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
This commit is contained in:
Ethan Shen 2022-02-19 01:55:30 +08:00 committed by GitHub
parent ea4bddb4ec
commit 04fc2aec4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 150 additions and 2 deletions

View File

@ -305,6 +305,16 @@ Country
</RouteEn>
## Global Disinformation Index
### Research
<RouteEn author="nczitzk" example="/disinformationindex/research" path="/disinformationindex/research"/>
### Blog
<RouteEn author="nczitzk" example="/disinformationindex/blog" path="/disinformationindex/blog"/>
## Google News
### News

View File

@ -425,6 +425,16 @@ Country
</Route>
## Global Disinformation Index
### Research
<Route author="nczitzk" example="/disinformationindex/research" path="/disinformationindex/research"/>
### Blog
<Route author="nczitzk" example="/disinformationindex/blog" path="/disinformationindex/blog"/>
## GQ
### GQ 台湾

View File

@ -4172,9 +4172,9 @@ router.get('/fashionnetwork/headline/:country?', lazyloadRouteHandler('./routes/
// mirror.xyz
router.get('/mirror/:id', lazyloadRouteHandler('./routes/mirror/entries'));
// Deprecated: DO NOT ADD ROUTE HERE
// KBS
router.get('/kbs/today/:language?', lazyloadRouteHandler('./routes/kbs/today'));
// Deprecated: DO NOT ADD ROUTE HERE
module.exports = router;

View File

@ -0,0 +1,49 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const rootUrl = 'https://disinformationindex.org';
const currentUrl = `${rootUrl}/blog`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.blog-entry-title a')
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: `${rootUrl}${item.attr('href')}`,
};
})
.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.author = content('.meta-author').text();
item.description = content('.entry-content').html();
item.pubDate = parseDate(content('.meta-date').text(), 'MMMM D, YYYY');
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};

View File

@ -0,0 +1,4 @@
module.export = {
'/blog': ['nczitzk'],
'/research': ['nczitzk'],
};

View File

@ -0,0 +1,19 @@
module.export = {
'disinformationindex.org': {
_name: 'Global Disinformation Index',
'.': [
{
title: 'Blog',
docs: 'https://docs.rsshub.app/new-media.html#global-disinformation-index',
source: ['/'],
target: '/disinformationindex/blog',
},
{
title: 'Research',
docs: 'https://docs.rsshub.app/new-media.html#global-disinformation-index',
source: ['/'],
target: '/disinformationindex/research',
},
],
},
};

View File

@ -0,0 +1,45 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { art } = require('@/utils/render');
const path = require('path');
module.exports = async (ctx) => {
const rootUrl = 'https://disinformationindex.org';
const currentUrl = `${rootUrl}/research`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const items = $('.elementor-widget-container .elementor-text-editor')
.map((_, item) => {
item = $(item);
const title = item.find('h3, h4').eq(0);
const image = item.parentsUntil('.elementor-container').find('.elementor-image img');
const firstLink = item.find('a.button').eq(0);
let links = '';
item.find('a.button').each(function () {
links += `<br><a href="${$(this).attr('href')}">${$(this).text()}</a>`;
});
return {
link: firstLink.attr('href'),
title: title.text() || firstLink.text(),
description: art(path.resolve(__dirname, 'templates/description.art'), {
image: image ? image.attr('src') : undefined,
title: title.next().html(),
links,
}),
};
})
.get();
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};

View File

@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/blog', require('./blog'));
router.get('/research', require('./research'));
};

View File

@ -0,0 +1,7 @@
{{ if image }}
<img src="{{ image }}"><br>
{{ /if }}
{{ if title }}
{{@ title }}
{{ /if }}
{{@ links }}