From 609063ffff8e1cef47665d9fba262c509e3c7079 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Wed, 17 Feb 2021 16:17:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E9=A6=99=E6=B8=AF=E5=95=86?= =?UTF-8?q?=E6=8A=A5=20PDF=20=E7=89=88=20(#6867)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add 香港商报 PDF 版 * fix date --- docs/traditional-media.md | 6 ++++++ lib/router.js | 3 +++ lib/routes/hkcd/pdf.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 lib/routes/hkcd/pdf.js diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 44bd94319..75afea6d8 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -815,6 +815,12 @@ category 对应的关键词有 +## 香港商报 + +### PDF 版 + + + ## 新京报 ### 栏目 diff --git a/lib/router.js b/lib/router.js index 43a231d3f..dec04ea80 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3961,4 +3961,7 @@ router.get('/furaffinity/favorites/:username/:nsfw?', require('./routes/furaffin router.get('/furaffinity/submission_comments/:id', require('./routes/furaffinity/submission_comments')); router.get('/furaffinity/journal_comments/:id', require('./routes/furaffinity/journal_comments')); +// 香港商报 +router.get('/hkcd/pdf', require('./routes/hkcd/pdf')); + module.exports = router; diff --git a/lib/routes/hkcd/pdf.js b/lib/routes/hkcd/pdf.js new file mode 100644 index 000000000..88866711c --- /dev/null +++ b/lib/routes/hkcd/pdf.js @@ -0,0 +1,30 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +module.exports = async (ctx) => { + const rootUrl = 'http://hk.hkcd.com'; + const currentUrl = `${rootUrl}/pdf/index.htm`; + const response = await got({ + method: 'get', + url: currentUrl, + responseType: 'buffer', + }); + + const data = iconv.decode(response.data, 'gb2312'); + const date = data.match(/(.*)/)[1]; + const $ = cheerio.load(data.replace('