feat(route): add The News Lens 關鍵評論 (#10454)

* feat(route): add The News Lens 關鍵評論

* fix typo
This commit is contained in:
Ethan Shen
2022-08-12 17:31:45 -07:00
committed by GitHub
parent 8172152acd
commit fdbb6fa709
6 changed files with 201 additions and 2 deletions
+48 -2
View File
@@ -12,7 +12,7 @@ pageClass: routes
### 分类
<Route author="nczitzk" example="/199it/category/199itdata" path="/199it/category/:caty" :paramsDesc="['分类, 可在分类页 URL 中找到']">
<Route author="nczitzk" example="/199it/category/199itdata" path="/199it/category/:caty" :paramsDesc="['分类,可在分类页 URL 中找到']">
分类为单一路径,如 `http://www.199it.com/archives/category/199itdata` 则路由为 `/199it/category/199itdata`.
@@ -22,7 +22,7 @@ pageClass: routes
### 标签
<Route author="nczitzk" example="/199it/tag/数据早报" path="/199it/tag/:tag" :paramsDesc="['标签, 可在标签页 URL 中找到']"/>
<Route author="nczitzk" example="/199it/tag/数据早报" path="/199it/tag/:tag" :paramsDesc="['标签,可在标签页 URL 中找到']"/>
## 36kr
@@ -1272,6 +1272,52 @@ IPFS 网关有可能失效,那时候换成其他网关。
</Route>
## The News Lens 關鍵評論
### 最新
<Route author="nczitzk" example="/thenewslens/latest-article" path="/thenewslens/latest-article/:sort?" :paramsDesc="['排序方式,见下表,可在对应排序页 URL 中找到']">
| 最新文章 | 最多觀看 | 最多分享 | 本日 | 本週 | 本月 | 今年 | 去年 | 有史以來 |
| ---- | ---- | ------ | --------- | -------- | --------- | -------- | ------------ | ----------- |
| | hot | social | hot/today | hot/week | hot/month | hot/year | hot/lastYear | hot/history |
</Route>
### 新闻
<Route author="nczitzk" example="/thenewslens/news" path="/thenewslens/news/:sort?" :paramsDesc="['排序方式,见下表,可在对应排序页 URL 中找到']">
| 最新文章 | 最多觀看 | 最多分享 |
| ---- | ---- | ------ |
| | hot | social |
</Route>
### 作者
<Route author="nczitzk" example="/thenewslens/author/BBC" path="/thenewslens/author/:id/:sort?" :paramsDesc="['作者 id,可在对应作者页 URL 中找到', '排序方式,同上表,可在对应排序页 URL 中找到']" />
### 分类
<Route author="nczitzk" example="/thenewslens/category/politics" path="/thenewslens/category/:id/:sort?" :paramsDesc="['分类 id,可在对应分类页 URL 中找到', '排序方式,同上表,可在对应排序页 URL 中找到']" />
### 标签
<Route author="nczitzk" example="/thenewslens/tag/中國" path="/thenewslens/tag/:id/:sort?" :paramsDesc="['标签 id,可在对应标签页 URL 中找到', '排序方式,同上表,可在对应排序页 URL 中找到']" />
### 频道
<Route author="nczitzk" example="/thenewslens/channel/hk" path="/thenewslens/channel/:id/:sort?" :paramsDesc="['标签 id,可在对应标签页 URL 中找到', '排序方式,同上表,可在对应排序页 URL 中找到']" />
### 评论
<Route author="nczitzk" example="/thenewslens/review" path="/thenewslens/review/:sort?" :paramsDesc="['排序方式,同上表,可在对应排序页 URL 中找到']" />
### 影音
<Route author="nczitzk" example="/thenewslens/videos/Projects" path="/thenewslens/videos/Projects/:sort?" :paramsDesc="['排序方式,同上表,可在对应排序页 URL 中找到']" />
## The Partnership on AI
### Resources
+79
View File
@@ -0,0 +1,79 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
module.exports = async (ctx) => {
const rootUrl = 'https://www.thenewslens.com';
const currentUrl = `${rootUrl}${ctx.path === '/' ? '/latest-article' : ctx.path}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
$('h1.title').remove();
let items = $('.regular-article-list, #list-container, .list-container')
.find('.article-title, .title')
.find('a')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 25)
.toArray()
.map((item) => {
item = $(item);
const link = item.attr('href');
return {
title: item.text(),
link: /\/article\//.test(link) ? `${link}/fullpage` : link,
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
content('#salon_comment_widget-anchor').remove();
content('ad2-recommender, footer, noscript').remove();
content('a[data-sk="tooltip_parent"]').parent().remove();
content('.ad-section, .recommender-title, .navigation-content').remove();
content('.article-img-container').each(function () {
content(this).replaceWith(
art(path.join(__dirname, 'templates/description.art'), {
image: content(this).find('img')?.attr('data-srcset').split('?')[0] ?? undefined,
})
);
});
item.author = content('meta[property="article:author"]').attr('content');
item.pubDate = parseDate(content('meta[property="article:published_time"]').attr('content'));
item.category = content('meta[property="article:tag"]')
.toArray()
.map((t) => content(t).attr('content'));
item.description = art(path.join(__dirname, 'templates/description.art'), {
image: content('meta[property="og:image"]')?.attr('content').split('?')[0] ?? undefined,
description: content('.article-main-box, article[itemprop="articleBody"]').html(),
});
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};
+10
View File
@@ -0,0 +1,10 @@
module.exports = {
'/author/:id/:sort?': ['nczitzk'],
'/category/:id/:sort?': ['nczitzk'],
'/channel/:id/:sort?': ['nczitzk'],
'/latest-article/:sort?': ['nczitzk'],
'/news/:sort?': ['nczitzk'],
'/review/:sort?': ['nczitzk'],
'/tag/:id/:sort?': ['nczitzk'],
'/videos/Projects/:sort?': ['nczitzk'],
};
+55
View File
@@ -0,0 +1,55 @@
module.exports = {
'thenewslens.com': {
_name: 'The News Lens 關鍵評論',
'.': [
{
title: '最新',
docs: 'https://docs.rsshub.app/new-media.html#the-news-lens-guan-jian-ping-lun',
source: ['/latest-article/:sort?', '/'],
target: '/thenewslens/latest-article/:sort?',
},
{
title: '新闻',
docs: 'https://docs.rsshub.app/new-media.html#the-news-lens-guan-jian-ping-lun',
source: ['/news/:sort?', '/'],
target: '/thenewslens/news/:sort?',
},
{
title: '作者',
docs: 'https://docs.rsshub.app/new-media.html#the-news-lens-guan-jian-ping-lun',
source: ['/author/:id/:sort?', '/'],
target: '/thenewslens/author/:id/:sort?',
},
{
title: '分类',
docs: 'https://docs.rsshub.app/new-media.html#the-news-lens-guan-jian-ping-lun',
source: ['/category/:id/:sort?', '/'],
target: '/thenewslens/category/:id/:sort?',
},
{
title: '标签',
docs: 'https://docs.rsshub.app/new-media.html#the-news-lens-guan-jian-ping-lun',
source: ['/tag/:id/:sort?', '/'],
target: '/thenewslens/tag/:id/:sort?',
},
{
title: '频道',
docs: 'https://docs.rsshub.app/new-media.html#the-news-lens-guan-jian-ping-lun',
source: ['/channel/:id/:sort?', '/'],
target: '/thenewslens/channel/:id/:sort?',
},
{
title: '评论',
docs: 'https://docs.rsshub.app/new-media.html#the-news-lens-guan-jian-ping-lun',
source: ['/review/:sort?', '/'],
target: '/thenewslens/review/:sort?',
},
{
title: '影音',
docs: 'https://docs.rsshub.app/new-media.html#the-news-lens-guan-jian-ping-lun',
source: ['/videos/Projects/:sort?', '/'],
target: '/thenewslens/videos/Projects/:sort?',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get(/([\w-/]+)?/, require('./index'));
};
@@ -0,0 +1,6 @@
{{ if image }}
<img src="{{ image }}">
{{ /if }}
{{ if description }}
{{@ description }}
{{ /if }}