diff --git a/docs/blog.md b/docs/blog.md index 4b0901963e..631ddf2d73 100644 --- a/docs/blog.md +++ b/docs/blog.md @@ -90,6 +90,33 @@ pageClass: routes +## Whoscall + +### 最新文章 + + + + + +### 分類 + + + +| News | Whoscall 百科 | 防詐小學堂 | Whoscall 日常 | +| ------ | --------------- | -------------- | --------------- | +| 1-News | 5-Whoscall 百科 | 4 - 防詐小學堂 | 6-Whoscall 日常 | + + + +### 標籤 + + + +| 防疫也防詐 | 防詐專家 | 來電辨識 | whoscall 日常 | +| ---------- | -------- | -------- | ------------- | + + + ## WordPress diff --git a/lib/v2/whoscall/index.js b/lib/v2/whoscall/index.js new file mode 100644 index 0000000000..80a7846be2 --- /dev/null +++ b/lib/v2/whoscall/index.js @@ -0,0 +1,55 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const id = ctx.params.id ?? ''; + const what = ctx.params.what ?? ''; + + const rootUrl = 'https://whoscall.com'; + const currentUrl = `${rootUrl}/zh-hant/blog/${id ? `${what}/${id}` : 'articles'}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.post-card__title a') + .map((_, item) => { + item = $(item); + + return { + title: item.text(), + link: `${rootUrl}${item.attr('href')}`, + }; + }) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.description = content('.blog-article__body').html(); + item.pubDate = parseDate(detailResponse.data.match(/"datePublished":"(.*)","dateModified"/)[1]); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title') + .text() + .replace(/ - 第\d+頁/, ''), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/whoscall/maintainer.js b/lib/v2/whoscall/maintainer.js new file mode 100644 index 0000000000..dd4f9e28d4 --- /dev/null +++ b/lib/v2/whoscall/maintainer.js @@ -0,0 +1,5 @@ +module.exports = { + '/': ['nczitzk'], + '/tags/:tag?': ['nczitzk'], + '/categories/:category?': ['nczitzk'], +}; diff --git a/lib/v2/whoscall/radar.js b/lib/v2/whoscall/radar.js new file mode 100644 index 0000000000..e13c42e266 --- /dev/null +++ b/lib/v2/whoscall/radar.js @@ -0,0 +1,25 @@ +module.exports = { + 'whoscall.com': { + _name: 'Whoscall', + '.': [ + { + title: '最新文章', + docs: 'https://docs.rsshub.app/blog.html#whoscall-zui-xin-wen-zhang', + source: ['/zh-hant/blog/articles', '/'], + target: '/whoscall', + }, + { + title: '分類', + docs: 'https://docs.rsshub.app/blog.html#whoscall-fen-lei', + source: ['/zh-hant/blog/categories/:category', '/'], + target: '/whoscall/categories/:category?', + }, + { + title: '標籤', + docs: 'https://docs.rsshub.app/blog.html#whoscall-biao-qian', + source: ['/zh-hant/blog/tags/:tag', '/'], + target: '/whoscall/tags/:tag?', + }, + ], + }, +}; diff --git a/lib/v2/whoscall/router.js b/lib/v2/whoscall/router.js new file mode 100644 index 0000000000..73d31c4be5 --- /dev/null +++ b/lib/v2/whoscall/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:what?/:id?', require('./index')); +};