fix(route): 纽约时报 每日简报 -> 新闻简报 (#7820)
This commit is contained in:
parent
d03dbaa774
commit
efcdccc045
|
|
@ -29,7 +29,7 @@ pageClass: routes
|
|||
### 话题
|
||||
|
||||
<Route author="mjysci" example="/apnews/topics2/ap-top-news" path="/apnews/topics2/:topic" :paramsDesc="['话题名称,可在 URL 中找到,例如 AP Top News [https://apnews.com/hub/ap-top-news](https://apnews.com/hub/ap-top-news) 的话题为 `ap-top-news`']" anticrawler="1"/>
|
||||
采用了`puppeteer`规避`Project Shield`,无全文抓取,建议自建。
|
||||
采用了 `puppeteer` 规避 `Project Shield`,无全文抓取,建议自建。
|
||||
|
||||
## BBC
|
||||
|
||||
|
|
@ -186,7 +186,7 @@ pageClass: routes
|
|||
|
||||
<Route author="tpnonthealps" example="/mediadigest/latest" path="/mediadigest/:range" :paramsDesc="['时间范围']">
|
||||
|
||||
细则:
|
||||
细则:
|
||||
|
||||
- `:range` 时间范围参数
|
||||
(可为 `latest` 或 `四位数字的年份`)
|
||||
|
|
@ -227,9 +227,9 @@ Solidot 提供的 feed:
|
|||
|
||||
可选分类如下
|
||||
|
||||
| WIRELESS | BROADBAND | VIDEO | GENERAL | IT | INDUSTRY RESOURCES |
|
||||
| -------- | --------- | --------- | ------- | -- | ------------------ |
|
||||
| mobile | internet | boardcast | general | it | industry-resources |
|
||||
| WIRELESS | BROADBAND | VIDEO | GENERAL | IT | INDUSTRY RESOURCES |
|
||||
| -------- | --------- | --------- | ------- | --- | ------------------ |
|
||||
| mobile | internet | boardcast | general | it | industry-resources |
|
||||
|
||||
::: tip 提示
|
||||
|
||||
|
|
@ -822,9 +822,9 @@ category 对应的关键词有
|
|||
|
||||
- 主频道:
|
||||
|
||||
| Business | Markets | World | UK | Tech | Money | Breakingviews | Sport | Life |
|
||||
| -------- | ------- | ----- | -- | ---------- | --------------- | ------------- | ------ | --------- |
|
||||
| business | markets | world | uk | technology | personalFinance | breakingviews | sports | lifestyle |
|
||||
| Business | Markets | World | UK | Tech | Money | Breakingviews | Sport | Life |
|
||||
| -------- | ------- | ----- | --- | ---------- | --------------- | ------------- | ------ | --------- |
|
||||
| business | markets | world | uk | technology | personalFinance | breakingviews | sports | lifestyle |
|
||||
|
||||
</Route>
|
||||
|
||||
|
|
@ -866,9 +866,10 @@ category 对应的关键词有
|
|||
|
||||
</Route>
|
||||
|
||||
### 每日简报
|
||||
### 新闻简报
|
||||
|
||||
<Route author="xyqfer" example="/nytimes/morning_post" path="/nytimes/morning_post"/>
|
||||
<Route author="yueyericardo" example="/nytimes/daily_briefing_chinese" path="/nytimes/daily_briefing_chinese"/>
|
||||
网站地址:<https://www.nytimes.com/zh-hans/series/daily-briefing-chinese/>
|
||||
|
||||
### 畅销书排行榜
|
||||
|
||||
|
|
|
|||
|
|
@ -337,7 +337,7 @@ router.get('/yande.re/post/popular_recent', require('./routes/yande.re/post_popu
|
|||
router.get('/yande.re/post/popular_recent/:period', require('./routes/yande.re/post_popular_recent'));
|
||||
|
||||
// 纽约时报
|
||||
router.get('/nytimes/morning_post', require('./routes/nytimes/morning_post'));
|
||||
router.get('/nytimes/daily_briefing_chinese', require('./routes/nytimes/daily_briefing_chinese'));
|
||||
router.get('/nytimes/book/:category?', require('./routes/nytimes/book.js'));
|
||||
router.get('/nytimes/:lang?', require('./routes/nytimes/index'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const url = 'https://www.nytimes.com/zh-hans/series/daily-briefing-chinese';
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url,
|
||||
});
|
||||
const data = response.data;
|
||||
const $ = cheerio.load(data);
|
||||
const post = $('.css-13mho3u .css-ye6x8s')
|
||||
.map((index, elem) => {
|
||||
const $item = $(elem);
|
||||
const $link = $item.find('a');
|
||||
const $title = $item.find('h2');
|
||||
|
||||
return {
|
||||
title: $title.text(),
|
||||
link: 'https://www.nytimes.com' + $link.attr('href'),
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
post.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const response = await got.get(item.link);
|
||||
const $ = cheerio.load(response.data);
|
||||
$('.css-pncxxs.etfikam0').remove();
|
||||
$('.css-1xdhyk6.erfvjey0').each((_, item) => {
|
||||
item = $(item);
|
||||
const link = item.find('img').attr('src');
|
||||
item.replaceWith(`<img src="${link}">`);
|
||||
});
|
||||
item.description = $('.meteredContent.css-1r7ky0e').html();
|
||||
const date = $('.css-x7rtpa.e16638kd0').attr('datetime');
|
||||
item.pubDate = parseDate(date);
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '纽约时报中文网|新闻简报',
|
||||
link: url,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const url = 'https://www.nytimes.com/svc/collections/v1/publish/https://www.nytimes.com/zh-hans/series/daily-briefing-chinese/rss.xml';
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url,
|
||||
});
|
||||
const data = response.data;
|
||||
const $ = cheerio.load(data);
|
||||
const post = $('item')
|
||||
.map((index, elem) => {
|
||||
const title = $(elem).find('title').text();
|
||||
const link = $(elem).find('link').next().text();
|
||||
return {
|
||||
link: link,
|
||||
title: title,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const browser = await require('@/utils/puppeteer')();
|
||||
|
||||
const items = await Promise.all(
|
||||
post.map(async (item) => {
|
||||
// use puppeter cause all the image is lazy-load
|
||||
const result = utils.ProcessFeed(await utils.PuppeterGetter(ctx, browser, item.link), true);
|
||||
|
||||
item.pubDate = result.pubDate;
|
||||
|
||||
// Match 感谢|謝.*?cn.letters@nytimes.com。
|
||||
const ending = /感(谢|謝);.*?cn\.letters@nytimes\.com。/g;
|
||||
|
||||
const matching = '<div class="article-paragraph">';
|
||||
const formatted = '<br>' + matching;
|
||||
|
||||
item.description = result.description.replace(ending, '').split(matching).join(formatted);
|
||||
|
||||
return Promise.resolve(item);
|
||||
})
|
||||
);
|
||||
|
||||
browser.close();
|
||||
|
||||
ctx.state.data = {
|
||||
title: '纽约时报中文网|每日简报',
|
||||
link: url,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const ProcessImage = ($, e) => {
|
||||
const photo = $(e).find('figure').find('picture').find('img');
|
||||
|
|
@ -87,7 +88,7 @@ const ProcessFeed = (data, hasEnVersion = false) => {
|
|||
|
||||
const time = $('time').attr('datetime');
|
||||
if (time) {
|
||||
result.pubDate = new Date(time).toUTCString();
|
||||
result.pubDate = parseDate(time);
|
||||
}
|
||||
|
||||
result.description = content.html();
|
||||
|
|
|
|||
Loading…
Reference in New Issue