From 20a7852394f8ea0cffd76124fa9062d88aa8a73c Mon Sep 17 00:00:00 2001 From: cnkmmk <22782790+cnkmmk@users.noreply.github.com> Date: Sun, 25 Feb 2024 23:39:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E8=8D=92=E5=B2=9B=20(#145?= =?UTF-8?q?50)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add lala * 更新 rss.js --- lib/v2/lala/maintainer.js | 3 +++ lib/v2/lala/radar.js | 13 +++++++++++++ lib/v2/lala/router.js | 3 +++ lib/v2/lala/rss.js | 32 ++++++++++++++++++++++++++++++++ website/docs/routes/blog.mdx | 6 ++++++ 5 files changed, 57 insertions(+) create mode 100644 lib/v2/lala/maintainer.js create mode 100644 lib/v2/lala/radar.js create mode 100644 lib/v2/lala/router.js create mode 100644 lib/v2/lala/rss.js diff --git a/lib/v2/lala/maintainer.js b/lib/v2/lala/maintainer.js new file mode 100644 index 000000000..387d961bf --- /dev/null +++ b/lib/v2/lala/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/': ['cnkmmk'], +}; diff --git a/lib/v2/lala/radar.js b/lib/v2/lala/radar.js new file mode 100644 index 000000000..b50f1e375 --- /dev/null +++ b/lib/v2/lala/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'lala.im': { + _name: "荒岛", + '.': [ + { + title: '博客', + docs: 'https://docs.rsshub.app/routes/blog#huang-dao', + source: ['/'], + target: '/lala', + }, + ], + }, +}; diff --git a/lib/v2/lala/router.js b/lib/v2/lala/router.js new file mode 100644 index 000000000..574929e02 --- /dev/null +++ b/lib/v2/lala/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/', require('./rss')); +}; diff --git a/lib/v2/lala/rss.js b/lib/v2/lala/rss.js new file mode 100644 index 000000000..82eba69a7 --- /dev/null +++ b/lib/v2/lala/rss.js @@ -0,0 +1,32 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const currentUrl = 'https://lala.im'; + const response = await got(`${currentUrl}/feed`); + const $ = cheerio.load(response.data, { xmlMode: true }); + const titleMain = $('channel > title').text(); + const descriptionMain = $('channel > description').text(); + const items = $('channel > item') + .map((_, item) => { + const $item = $(item); + const link = $item.find('link').text(); + const title = $item.find('title').text(); + const description = $item.find('description').text(); + const pubDate = $item.find('pubDate').text(); + return { + link, + pubDate, // no need to normalize because it's from a valid RSS feed + title, + description, + }; + }) + .get(); + + ctx.state.data = { + title: titleMain, + description: descriptionMain, + link: currentUrl, + item: items, + }; +}; diff --git a/website/docs/routes/blog.mdx b/website/docs/routes/blog.mdx index 3fad78967..eb4ab5ac6 100644 --- a/website/docs/routes/blog.mdx +++ b/website/docs/routes/blog.mdx @@ -479,3 +479,9 @@ ### 上周热门 TOP 20 {#zhu-bai-shang-zhou-re-men-top-20} + +## 荒岛 {#huang-dao} + +### 博客 {#huang-dao-bo-ke} + + \ No newline at end of file