From b13e3f640255c3f953b714ac346affbd647dfbe4 Mon Sep 17 00:00:00 2001 From: artificialUsagi <41666068+artefaritaKuniklo@users.noreply.github.com> Date: Sat, 30 Dec 2023 23:32:59 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=B8=AD=E5=9B=BD?= =?UTF-8?q?=E7=9A=84=E4=B8=AD=E5=8F=A4=20(#14139)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 中国的中古 * Update lib/v2/medieval-china/post.js Co-authored-by: Tony * Update lib/v2/medieval-china/maintainer.js Co-authored-by: Tony * fix(route): fix desc of 中国的中古 * fix(route): fix data query of 中国的中古 * Update lib/v2/medieval-china/post.js Co-authored-by: Tony * style: auto format * fix(radar): add target --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/v2/medieval-china/maintainer.js | 3 ++ lib/v2/medieval-china/post.js | 44 +++++++++++++++++++++++++++++ lib/v2/medieval-china/radar.js | 13 +++++++++ lib/v2/medieval-china/router.js | 3 ++ website/docs/routes/reading.mdx | 6 ++++ 5 files changed, 69 insertions(+) create mode 100644 lib/v2/medieval-china/maintainer.js create mode 100644 lib/v2/medieval-china/post.js create mode 100644 lib/v2/medieval-china/radar.js create mode 100644 lib/v2/medieval-china/router.js diff --git a/lib/v2/medieval-china/maintainer.js b/lib/v2/medieval-china/maintainer.js new file mode 100644 index 0000000000..1b61246e8d --- /dev/null +++ b/lib/v2/medieval-china/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/': ['artefaritaKuniklo'], +}; diff --git a/lib/v2/medieval-china/post.js b/lib/v2/medieval-china/post.js new file mode 100644 index 0000000000..251f287651 --- /dev/null +++ b/lib/v2/medieval-china/post.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +module.exports = async (ctx) => { + const baseUrl = 'https://medieval-china.club'; + const { data: response } = await got(baseUrl); + const $ = cheerio.load(response); + const posts = JSON.parse( + $('script:contains("window.localPosts")') + .text() + .match(/window\.localPosts = JSON\.parse\('(.*)'\);/)[1] + ) + .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 10) + .map((item) => ({ + title: item.title, + link: `${baseUrl}${item.path}`, + pubDate: timezone(parseDate(item.date), +8), + })); + const items = await Promise.all( + posts.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link); + const $ = cheerio.load(response); + const imgSrc = $('img').attr('data-original'); + $('img').attr('src', `${baseUrl}${imgSrc}`); + $('.head-mask').remove(); + $('div.lover-box').remove(); + item.description = $('article').first().html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: '中国的中古', + link: baseUrl, + item: items, + image: 'https://medieval-china.club/images/icons/favicon-144x144.png', + description: + '世界那么大,你无法去到每一个地方,感受每一处风景;时间那么长,那些逝去的人你也终将无法与之谋面。而通过古人之文字,今人之分享,你可以领略以前风光之奇绝瑰玮,感受逝人之人情冷暖。中古就是这么一个地方,大家来自全球各地,不同时区,不同性别,不同身份,不同职业,但是大家都被中古的绚烂华章聚集在一起,哀其所哀,乐其所乐。这是一个虚拟的世界,但是我们仿佛跨越千里而来,谈一场绝世爱恋,今夕何夕!仅以此网站献给中古club的每一位成员,契阔谈宴,西园不芜!', + }; +}; diff --git a/lib/v2/medieval-china/radar.js b/lib/v2/medieval-china/radar.js new file mode 100644 index 0000000000..aea6fcfce2 --- /dev/null +++ b/lib/v2/medieval-china/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'medieval-china.club': { + _name: '中国的中古', + '.': [ + { + title: '首页', + docs: 'https://docs.rsshub.app/routes/reading#zhong-guo-de-zhong-shou-ye', + source: '/', + target: '/medieval-china', + }, + ], + }, +}; diff --git a/lib/v2/medieval-china/router.js b/lib/v2/medieval-china/router.js new file mode 100644 index 0000000000..9e0d5e7f96 --- /dev/null +++ b/lib/v2/medieval-china/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/', require('./post')); +}; diff --git a/website/docs/routes/reading.mdx b/website/docs/routes/reading.mdx index 0e3ac097be..c622570438 100644 --- a/website/docs/routes/reading.mdx +++ b/website/docs/routes/reading.mdx @@ -357,6 +357,12 @@ +## 中国的中古 {#zhong-guo-de-zhong-gu} + +### 首页 {#zhong-guo-de-zhong-gu-shou-ye} + + + ## 纵横 {#zong-heng} ### 章节 {#zong-heng-zhang-jie}