feat(route): add 公視新聞網即時新聞 (#8458)

This commit is contained in:
Ethan Shen
2021-11-27 08:47:01 +00:00
committed by GitHub
parent 8e42a73401
commit d251822d51
6 changed files with 83 additions and 0 deletions
+6
View File
@@ -430,3 +430,9 @@ Provide full article RSS for WSJ topics.
Provides all of the articles by the specified Yahoo! author.
</RouteEn>
## 公視新聞網
### Daily News
<RouteEn author="nczitzk" example="/pts/dailynews" path="/pts/dailynews"/>
+6
View File
@@ -699,6 +699,12 @@ Type 栏目:
<Route author="HenryQW" example="/dwnews/rank" path="/dwnews/rank"/>
## 公視新聞網
### 即時新聞
<Route author="nczitzk" example="/pts/dailynews" path="/pts/dailynews"/>
## 华尔街见闻
### 华尔街见闻
+52
View File
@@ -0,0 +1,52 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const rootUrl = 'https://news.pts.org.tw';
const currentUrl = `${rootUrl}/dailynews`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('h2 a')
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: item.attr('href'),
};
})
.get();
const items = await Promise.all(
list.map((item) =>
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[property="article:author"]').attr('content');
item.pubDate = timezone(parseDate(content('meta[property="article:published_time"]').attr('content')), +8);
item.description = `<img src="${content('meta[property="og:image"]').attr('content')}">${content('.post-article').html()}`;
return item;
})
)
);
ctx.state.data = {
title: '即時 公視新聞網 PNN',
link: currentUrl,
item: items,
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/dailynews': ['nczitzk'],
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'pts.org.tw': {
_name: '公視新聞網 PNN',
news: [
{
title: '即時',
docs: 'https://docs.rsshub.app/traditional-media.html#gong-shi-xin-wen-wang-ji-shi-xin-wen',
source: ['/dailynews'],
target: '/pts/dailynews',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/dailynews', require('./dailynews'));
};