From 4dc3362e41bb19bb883ea126af1aa20ea809043d Mon Sep 17 00:00:00 2001
From: Ethan Shen <42264778+nczitzk@users.noreply.github.com>
Date: Sun, 17 Jul 2022 20:24:20 +0800
Subject: [PATCH] =?UTF-8?q?feat(route):=20=E5=85=AC=E8=A6=96=E6=96=B0?=
=?UTF-8?q?=E8=81=9E=E7=B6=B2=20(#10236)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/traditional-media.md | 39 ++++++++++++++++++++++++
lib/v2/pts/curations.js | 44 +++++++++++++++++++++++++++
lib/v2/pts/{dailynews.js => index.js} | 35 ++++++++++++++-------
lib/v2/pts/maintainer.js | 6 ++++
lib/v2/pts/projects.js | 44 +++++++++++++++++++++++++++
lib/v2/pts/radar.js | 40 ++++++++++++++++++++++--
lib/v2/pts/router.js | 5 ++-
lib/v2/pts/templates/description.art | 6 ++++
8 files changed, 205 insertions(+), 14 deletions(-)
create mode 100644 lib/v2/pts/curations.js
rename lib/v2/pts/{dailynews.js => index.js} (52%)
create mode 100644 lib/v2/pts/projects.js
create mode 100644 lib/v2/pts/templates/description.art
diff --git a/docs/traditional-media.md b/docs/traditional-media.md
index fe90d4473..1ed858d7d 100644
--- a/docs/traditional-media.md
+++ b/docs/traditional-media.md
@@ -878,6 +878,45 @@ Type 栏目:
${content('.post-article').html()}`;
-
+ item.category = content('.tag-list')
+ .first()
+ .find('.blue-tag')
+ .toArray()
+ .map((t) => content(t).text())
+ .filter((t) => t !== '...');
+ item.description = art(path.join(__dirname, 'templates/description.art'), {
+ image: content('meta[property="og:image"]').attr('content'),
+ description: content('.post-article').html(),
+ });
return item;
})
)
);
ctx.state.data = {
- title: '即時 | 公視新聞網 PNN',
+ title: $('title')
+ .text()
+ .replace(/第\d+頁 | /, ''),
link: currentUrl,
item: items,
};
diff --git a/lib/v2/pts/maintainer.js b/lib/v2/pts/maintainer.js
index 8eaa4e035..0441ed933 100644
--- a/lib/v2/pts/maintainer.js
+++ b/lib/v2/pts/maintainer.js
@@ -1,3 +1,9 @@
module.exports = {
+ '/category/:id': ['nczitzk'],
+ '/curations': ['nczitzk'],
'/dailynews': ['nczitzk'],
+ '/opinion': ['nczitzk'],
+ '/projects': ['nczitzk'],
+ '/report': ['nczitzk'],
+ '/tag/:id': ['nczitzk'],
};
diff --git a/lib/v2/pts/projects.js b/lib/v2/pts/projects.js
new file mode 100644
index 000000000..93198627d
--- /dev/null
+++ b/lib/v2/pts/projects.js
@@ -0,0 +1,44 @@
+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://news.pts.org.tw';
+ const currentUrl = `${rootUrl}/projects`;
+
+ const response = await got({
+ method: 'get',
+ url: currentUrl,
+ });
+
+ const $ = cheerio.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 ? `
${description}
` : '', + }), + }; + }); + + ctx.state.data = { + title: $('title') + .text() + .replace(/第\d+頁 | /, ''), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/pts/radar.js b/lib/v2/pts/radar.js index a5ff8e2bd..557aaa0c1 100644 --- a/lib/v2/pts/radar.js +++ b/lib/v2/pts/radar.js @@ -3,11 +3,47 @@ module.exports = { _name: '公視新聞網 PNN', news: [ { - title: '即時', + title: '即時新聞', docs: 'https://docs.rsshub.app/traditional-media.html#gong-shi-xin-wen-wang-ji-shi-xin-wen', - source: ['/dailynews'], + source: ['/dailynews', '/'], target: '/pts/dailynews', }, + { + title: '專題策展', + docs: 'https://docs.rsshub.app/traditional-media.html#gong-shi-xin-wen-wang-zhuan-ti-ce-zhan', + source: ['/curations', '/'], + target: '/pts/curations', + }, + { + title: '觀點', + docs: 'https://docs.rsshub.app/traditional-media.html#gong-shi-xin-wen-wang-guan-dian', + source: ['/opinion', '/'], + target: '/pts/opinion', + }, + { + title: '數位敘事', + docs: 'https://docs.rsshub.app/traditional-media.html#gong-shi-xin-wen-wang-shu-wei-xu-shi', + source: ['/projects', '/'], + target: '/pts/projects', + }, + { + title: '深度報導', + docs: 'https://docs.rsshub.app/traditional-media.html#gong-shi-xin-wen-wang-shen-du-bao-dao', + source: ['/report', '/'], + target: '/pts/report', + }, + { + title: '分類', + docs: 'https://docs.rsshub.app/traditional-media.html#gong-shi-xin-wen-wang-fen-lei', + source: ['/category/:id', '/'], + target: '/pts/category/:id', + }, + { + title: '標籤', + docs: 'https://docs.rsshub.app/traditional-media.html#gong-shi-xin-wen-wang-biao-qian', + source: ['/tag/:id', '/'], + target: '/pts/tag/:id', + }, ], }, }; diff --git a/lib/v2/pts/router.js b/lib/v2/pts/router.js index e2bb9b13d..41f845414 100644 --- a/lib/v2/pts/router.js +++ b/lib/v2/pts/router.js @@ -1,3 +1,6 @@ module.exports = function (router) { - router.get('/dailynews', require('./dailynews')); + router.get('/curations', require('./curations')); + router.get('/projects', require('./projects')); + router.get(/([\w-/]+)?/, require('./index')); + router.get('', require('./index')); }; diff --git a/lib/v2/pts/templates/description.art b/lib/v2/pts/templates/description.art new file mode 100644 index 000000000..69e93d20c --- /dev/null +++ b/lib/v2/pts/templates/description.art @@ -0,0 +1,6 @@ +{{ if image }} +