Files
RSSHub/lib/routes/solidot/_article.ts
T
Tony 5527d18de9 refactor: remove unnecessary trim/first/last (#22837)
* refactor: remove unnecessary trim/first/last

* refactor(types): allow null in DataItem.description

* refactor: remove unnecessary fallback

* refactor(types): allow null in Data.description

* refactor: remove unnecessary fallback

* refactor: remove .clone()

* refactor: refine json content text

* fIx: cognition

* fix: more fixes

* fix(route/jiemian): use api

* fix(route/jandan): housekeeping

add back maintainers from #8904

* fix(route/kcna/news): update source and target mappings

* fix(route/jandan): sanitize HTML content in titles

* refactor: remove unnecessary referer

* fix(route/jinse): regex
2026-07-27 22:23:57 +08:00

54 lines
1.6 KiB
TypeScript

import { load } from 'cheerio'; // html parser
import got from '@/utils/got'; // get web content
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
export default async function get_article(url) {
const domain = 'https://www.solidot.org';
if (/^\/.*$/.test(url)) {
url = domain + url;
}
const response = await got({
method: 'get',
url,
});
const data = response.data;
const $ = load(data);
const date_raw = $('div.talk_time')
.contents()
.filter((_, node) => node.type === 'text')
.text();
const date_str_zh = date_raw.replaceAll(/^[^`]*发表于(?=(.*分))\1[^`]*$/g, '$1'); // use [^`] to match \n
const date_str = date_str_zh
.replaceAll(/[年月]/g, '-')
.replaceAll('时', ':')
.replaceAll(/[分日]/g, '');
const title = $('div.block_m > div.ct_tittle > div.bg_htit > h2').text();
const category = $('div.icon_float > a').attr('title');
const author = $('div.talk_time > b')
.text()
.replaceAll(/^来自(.*)部门$/g, '$1');
$('div.ct_tittle').remove();
$('div.talk_time').remove();
const description = $('div.block_m')
.html()
.replaceAll(/(href.*?)<u>(.*?)<\/u>/g, '$1$2')
// Preserve the not extremely disturbing donation ad
// to support the site.
.replaceAll(/(<img.*liiLIZF8Uh6yM.*?>)/g, '<br><br>$1');
const item = {
title,
pubDate: timezone(parseDate(date_str), 8),
author,
link: url,
description,
category,
};
return item;
}