fix(route): phoronix (#11892)

This commit is contained in:
Tony 2023-02-16 20:41:10 +01:00 committed by GitHub
parent 6bdf67c69e
commit 85ee7a24f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 75 additions and 60 deletions

View File

@ -562,6 +562,12 @@ This route provides a flexible plan with full text content to subscribe specific
</RouteEn>
## Phoronix
### News & Reviews
<RouteEn author="oppliate" example="/phoronix/news_topic/Intel" path="/phoronix/:page/:queryOrItem?" :paramsDesc="['Page name', 'For `category` it corresponds to `item`, for other pages it\'s `q`. You may find available parameters from their navigator links. E.g. to subscribe to the category page `https://www.phoronix.com/scan.php?page=category&item=Computers`, fill in the path `/phoronix/category/Computers`']" radar="1"/>
## Polar
### Blog

View File

@ -361,12 +361,6 @@ Only `s00017` is in English.
<RouteEn author="rainrdx" example="/nikkei-asia" path="/nikkei-asia"/>
## Phoronix
### News & Reviews
<RouteEn author="oppliate" example="/phoronix/news_topic/Intel" path="/phoronix/:page/:queryOrItem?" :paramsDesc="['Page name', 'For `category` it corresponds to `item`, for other pages it\'s `q`. You may find available parameters from their navigator links. E.g. to subscribe to the category page `https://www.phoronix.com/scan.php?page=category&item=Computers`, fill in the path `/phoronix/category/Computers`']" />
## Radio Free Asia (RFA)
### News

View File

@ -1057,6 +1057,12 @@ IPFS 网关有可能失效,那时候换成其他网关。
</Route>
## Phoronix
### 新闻与评测
<Route author="oppliate" example="/phoronix/news_topic/Intel" path="/phoronix/:page/:queryOrItem?" :paramsDesc="['页面', '对 `category` 页面是分类项目 `item`,对其它页面是主题 `q`,可以在网站顶部导航栏各项目链接里找出。如 `https://www.phoronix.com/scan.php?page=category&item=Computers` 对应 `/phoronix/category/Computers`']" radar="1"/>
## PMCAFF
### 今日推荐 / 精选

View File

@ -343,12 +343,6 @@ pageClass: routes
<Route author="nczitzk" example="/now/news/rank" path="/now/news/rank"/>
## Phoronix
### 新闻与评测
<Route author="oppliate" example="/phoronix/news_topic/Intel" path="/phoronix/:page/:queryOrItem?" :paramsDesc="['页面', '对 `category` 页面是分类项目 `item`,对其它页面是主题 `q`,可以在网站顶部导航栏各项目链接里找出。如 `https://www.phoronix.com/scan.php?page=category&item=Computers` 对应 `/phoronix/category/Computers`']" />
## RTHK 傳媒透視
<Route author="tpnonthealps" example="/mediadigest/latest" path="/mediadigest/:range" :paramsDesc="['时间范围']">

View File

@ -3378,7 +3378,7 @@ router.get('/uisdc/topic/:title?/:sort?', lazyloadRouteHandler('./routes/uisdc/t
router.get('/chinalaborwatch/reports/:lang?/:industry?', lazyloadRouteHandler('./routes/chinalaborwatch/reports'));
// Phoronix
router.get('/phoronix/:page/:queryOrItem?', lazyloadRouteHandler('./routes/phoronix/index'));
// router.get('/phoronix/:page/:queryOrItem?', lazyloadRouteHandler('./routes/phoronix/index'));
// 美国中央情报局
router.get('/cia/foia-annual-report', lazyloadRouteHandler('./routes/us/cia/foia-annual-report'));

View File

@ -2,14 +2,17 @@ const parser = require('@/utils/rss-parser');
const cheerio = require('cheerio');
const got = require('@/utils/got');
const baseUrl = 'https://www.phoronix.com';
module.exports = async (ctx) => {
const rssUrl = new URL('/rss.php', 'https://www.phoronix.com');
rssUrl.searchParams.set('page', ctx.params.page);
if (ctx.params.queryOrItem) {
if (ctx.params.page === 'category') {
rssUrl.searchParams.set('item', ctx.params.queryOrItem);
const { page, queryOrItem } = ctx.params;
const rssUrl = new URL('/rss.php', baseUrl);
rssUrl.searchParams.set('page', page);
if (queryOrItem) {
if (page === 'category') {
rssUrl.searchParams.set('item', queryOrItem);
} else {
rssUrl.searchParams.set('q', ctx.params.queryOrItem);
rssUrl.searchParams.set('q', queryOrItem);
}
}
@ -23,58 +26,50 @@ module.exports = async (ctx) => {
const $ = cheerio.load(html);
const content = $('.content');
// Maybe it's paginated
const links = [];
$('.pagination > a').each((_i, pager) => {
const link = pager.attribs.href;
links.push(link);
});
// Author
const authorSelector = $('.author > a');
// thel last 2 are the category and comments
const author = authorSelector
.slice(0, authorSelector.length - 2)
.toArray()
.map((e) => $(e).text());
const pages = await Promise.all(
links.map((link) =>
ctx.cache.tryGet(link, async () => {
const response = await got(item.link);
const html = response.body;
const $$ = cheerio.load(html);
const page = $$('.content');
return page.html();
})
)
);
content.append(pages);
// Maybe it's paginated
const links = $('.pagination > a')
.toArray()
.map((pager) => `${baseUrl}${pager.attribs.href}`)
.slice(0, -1); // the last one is "next page"
if (links.length) {
const pages = await Promise.all(
links.map((link) =>
ctx.cache.tryGet(link, async () => {
const response = await got(link);
const html = response.data;
const $$ = cheerio.load(html);
const page = $$('.content');
return page.html();
})
)
);
content.append(pages);
}
// Summary
const summary = $('.content > p:nth-child(1)');
// Author
const author = [];
const authorSelector = $('.author > a');
// thel last 2 are the category and comments
authorSelector.slice(0, authorSelector.length - 2).each((_i, e) => author.push(e.attribs.content));
// Remove unwanted DOMs
const unwanted_element_selectors = [
'[class*="-advert"]',
'.social-share',
'.article-body-after',
'scmp-chinaR2-early-text',
'.newsletter-widget-wrapper',
'[id*="-tracker"]',
'[class^="advert-"]',
'amp-list',
'.more-on-this',
];
unwanted_element_selectors.forEach((selector) => {
content.find(selector).each((_i, e) => {
$(e).remove();
});
// High res images
content.find('img').each((_, img) => {
if (img.attribs.src.endsWith('_med')) {
img.attribs.src = img.attribs.src.replace('_med', '_show');
}
});
return {
title: item.title,
id: item.guid,
pubDate: item.pubDate,
author: author.join(),
author: author.join(', '),
link: item.link,
summary: summary.html(),
description: content.html(),
@ -92,6 +87,7 @@ module.exports = async (ctx) => {
item: items,
language: feed.language,
icon: 'https://www.phoronix.com/android-chrome-192x192.png',
image: 'https://www.phoronix.com/android-chrome-192x192.png',
logo: 'https://www.phoronix.com/phxcms7-css/phoronix.png',
// Copied from thier web page metadata
category: [

View File

@ -0,0 +1,3 @@
module.exports = {
'/:page/:queryOrItem?': ['oppliate'],
};

13
lib/v2/phoronix/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'phoronix.com': {
_name: 'Phoronix',
'.': [
{
title: '新闻与评测',
docs: 'https://docs.rsshub.app/new-media.html#phoronix',
source: ['/*'],
target: '/phoronix/news',
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:page/:queryOrItem?', require('./index'));
};