mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat(route): the atlantic (#12092)
* feat(route): the atlantic * fix: docs * chore: discard async-pool * fix: docs * feat: utils update * fix: typo * Update lib/v2/theatlantic/utils.js * Update lib/v2/theatlantic/templates/article-description.art ---------
This commit is contained in:
@@ -574,6 +574,20 @@ Language
|
||||
|
||||
<RouteEn author="TonyRL" example="/taiwannews/hot" path="/taiwannews/hot/:lang?" :paramsDesc="['Language, `en` or `zh`, `en` by default']" radar="1" rssbud="1"/>
|
||||
|
||||
## The Atlantic
|
||||
|
||||
### News
|
||||
|
||||
<RouteEn author="NavePnow" example="/theatlantic/latest" path="/theatlantic/:category" :paramsDesc="['category, see below']">
|
||||
|
||||
| Popular | Latest | Politics | Technology | Business |
|
||||
| ------------ | ------ | -------- | ---------- | -------- |
|
||||
| most-popular | latest | politics | technology | business |
|
||||
|
||||
More categories (except photo) can be found within the navigation bar at <https://www.theatlantic.com/>
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## The Economist
|
||||
|
||||
### Category
|
||||
|
||||
@@ -468,6 +468,20 @@ Solidot 提供的 feed:
|
||||
|
||||
</Route>
|
||||
|
||||
## The Atlantic
|
||||
|
||||
### News
|
||||
|
||||
<Route author="NavePnow" example="/theatlantic/latest" path="/theatlantic/:category" :paramsDesc="['分类, 见下表']">
|
||||
|
||||
| Popular | Latest | Politics | Technology | Business |
|
||||
| ------------ | ------ | -------- | ---------- | -------- |
|
||||
| most-popular | latest | politics | technology | business |
|
||||
|
||||
More categories (except photo) can be found within the navigation bar at <https://www.theatlantic.com/>
|
||||
|
||||
</Route>
|
||||
|
||||
## The Economist
|
||||
|
||||
### 分类
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/:category': ['NavePnow'],
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { getArticleDetails } = require('./utils');
|
||||
module.exports = async (ctx) => {
|
||||
const host = 'https://www.theatlantic.com';
|
||||
const category = ctx.params.category;
|
||||
const url = `${host}/${category}/`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url,
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
const contents = JSON.parse($('script#__NEXT_DATA__').text()).props.pageProps.urqlState;
|
||||
const firstKey = Object.keys(contents)[0];
|
||||
const data = JSON.parse(contents[firstKey].data);
|
||||
let list = Object.values(data)[0].river.edges;
|
||||
list = list.filter((item) => !item.node.url.startsWith('https://www.theatlantic.com/photo'));
|
||||
list = list.map((item) => {
|
||||
const data = {};
|
||||
data.title = item.node.title;
|
||||
data.link = item.node.url;
|
||||
data.pubDate = item.node.datePublished;
|
||||
return data;
|
||||
});
|
||||
const items = await getArticleDetails(list, ctx);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `The Atlantic - ${category.toUpperCase()}`,
|
||||
link: url,
|
||||
description: `The Atlantic - ${category.toUpperCase()}`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
'theatlantic.com': {
|
||||
_name: 'The Atlantic',
|
||||
www: [
|
||||
{
|
||||
title: '新闻',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#the-atlantic',
|
||||
source: '/:category',
|
||||
target: '/theatlantic/:category',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/:category', require('./news'));
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
<div>
|
||||
{{@ item.caption}}
|
||||
<br>
|
||||
{{ if item.imgUrl }}
|
||||
<figure>
|
||||
<img src="{{item.imgUrl}}" alt="{{item.imgAlt}}">
|
||||
<figcaption>{{item.imgCaption}}</figcaption>
|
||||
</figure>
|
||||
{{ /if }}
|
||||
{{each item.content}}
|
||||
{{@ $value.innerHtml}}
|
||||
{{if !$value.tagName}}
|
||||
<br>
|
||||
<br>
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
const cheerio = require('cheerio');
|
||||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
const UA = require('@/utils/rand-user-agent')({ browser: 'chrome', os: 'android', device: 'mobile' });
|
||||
|
||||
const getArticleDetails = async (items, ctx) => {
|
||||
const list = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const url = item.link;
|
||||
const response = await got({
|
||||
url,
|
||||
method: 'get',
|
||||
headers: {
|
||||
'User-Agent': UA,
|
||||
},
|
||||
});
|
||||
const html = response.data;
|
||||
const $ = cheerio.load(html);
|
||||
let data = JSON.parse($('script#__NEXT_DATA__').text());
|
||||
|
||||
const list = data.props.pageProps.urqlState;
|
||||
const keyWithContent = Object.keys(list).filter((key) => list[key].data.includes('content'));
|
||||
data = JSON.parse(list[keyWithContent].data).article;
|
||||
item.category = data.categories.map((category) => category.slug);
|
||||
data.channels.forEach((channel) => {
|
||||
item.category.push(channel.slug);
|
||||
});
|
||||
item.content = data.content.filter((item) => item.innerHtml !== undefined && item.innerHtml !== '');
|
||||
item.caption = data.dek;
|
||||
item.imgUrl = data.leadArt.image?.url;
|
||||
item.imgAlt = data.leadArt.image?.altText;
|
||||
item.imgCaption = data.leadArt.image?.attributionText;
|
||||
item.description = art(path.join(__dirname, 'templates/article-description.art'), {
|
||||
item,
|
||||
});
|
||||
return {
|
||||
title: item.title,
|
||||
pubDate: parseDate(item.pubDate),
|
||||
link: item.link,
|
||||
description: item.description,
|
||||
};
|
||||
})
|
||||
)
|
||||
);
|
||||
return list;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getArticleDetails,
|
||||
};
|
||||
Reference in New Issue
Block a user