Files
RSSHub/lib/routes/pts/projects.ts
T
DIYgod cf4e772de8 refactor: replace art template with jsx (#20777)
* refactor: replace art template with jsx

* fix: tsx files

* fix: renderToString import

* fix: hono html raw import

* feat: remove art
2025-12-29 12:27:32 +08:00

71 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { load } from 'cheerio';
import type { Route } from '@/types';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
import { renderDescription } from './templates/description';
export const route: Route = {
path: '/projects',
categories: ['traditional-media'],
example: '/pts/projects',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['news.pts.org.tw/projects', 'news.pts.org.tw/'],
},
],
name: '數位敘事',
maintainers: ['nczitzk'],
handler,
url: 'news.pts.org.tw/projects',
};
async function handler() {
const rootUrl = 'https://news.pts.org.tw';
const currentUrl = `${rootUrl}/projects`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = load(response.data);
const items = $('h3 a')
.toArray()
.map((item) => {
item = $(item);
const projectDiv = item.parent().parent();
const description = projectDiv.find('p').text();
return {
title: item.text(),
link: item.attr('href'),
pubDate: parseDate(projectDiv.find('time').text()),
description: renderDescription({
image: projectDiv.parent().find('.cover-fit')?.attr('src') ?? projectDiv.parent().parent().find('.cover-fit').attr('src'),
description: description ? `<p>${description}</p>` : '',
}),
};
});
return {
title: $('title')
.text()
.replace(/第\d+頁 | /, ''),
link: currentUrl,
item: items,
};
}