feat: add 香港商报 PDF 版 (#6867)

* feat: add 香港商报 PDF 版

* fix date
This commit is contained in:
Ethan Shen 2021-02-17 16:17:10 +08:00 committed by GitHub
parent 9a3b543eec
commit 609063ffff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 0 deletions

View File

@ -815,6 +815,12 @@ category 对应的关键词有
</Route>
## 香港商报
### PDF 版
<Route author="nczitzk" example="/hkcd/pdf" path="/hkcd/pdf"/>
## 新京报
### 栏目

View File

@ -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;

30
lib/routes/hkcd/pdf.js Normal file
View File

@ -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(/<td align="right"><font color="#FFFFFF">(.*)/)[1];
const $ = cheerio.load(data.replace('<table width="177" border="0" cellspacing="1" cellpadding="0"', '<table id="content" width="177" border="0" cellspacing="1" cellpadding="0"'));
ctx.state.data = {
title: '香港商报PDF版',
link: currentUrl,
item: [
{
title: date,
link: currentUrl,
description: $('#content').html(),
pubDate: new Date(date.replace(/年|月/g, '-').replace(/日/, '')).toUTCString(),
},
],
};
};