Files
RSSHub/lib/routes/pts/projects.ts
T
DIYgod 83e701b592 feat: compile ts through tsdown (#18908)
* feat: build ts via tsdown

* feat: exec tsdown

* fix

* fix

* fix

* feat: use tsdown shims

* chore: run rolldown lifecycle script

* fix: use shims

---------
2025-04-22 22:29:11 +08:00

71 lines
1.9 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 { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import { art } from '@/utils/render';
import path from 'node:path';
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: art(path.join(__dirname, 'templates/description.art'), {
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,
};
}