From f965e0b15fd1ecd29577e3d1ada4912944fb7e3f Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 22 Jan 2024 06:35:58 +0000 Subject: [PATCH] feat(route): keepass (#14301) --- lib/v2/keepass/maintainer.js | 3 ++ lib/v2/keepass/news.js | 46 ++++++++++++++++++++++++++ lib/v2/keepass/radar.js | 13 ++++++++ lib/v2/keepass/router.js | 3 ++ website/docs/routes/program-update.mdx | 6 ++++ 5 files changed, 71 insertions(+) create mode 100644 lib/v2/keepass/maintainer.js create mode 100644 lib/v2/keepass/news.js create mode 100644 lib/v2/keepass/radar.js create mode 100644 lib/v2/keepass/router.js diff --git a/lib/v2/keepass/maintainer.js b/lib/v2/keepass/maintainer.js new file mode 100644 index 00000000000000..83fc5ed48db85a --- /dev/null +++ b/lib/v2/keepass/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/': ['TonyRL'], +}; diff --git a/lib/v2/keepass/news.js b/lib/v2/keepass/news.js new file mode 100644 index 00000000000000..b22e8a10ee7c47 --- /dev/null +++ b/lib/v2/keepass/news.js @@ -0,0 +1,46 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const baseUrl = 'https://keepass.info/news/news_all.html'; + const { data: response } = await got(baseUrl); + const $ = cheerio.load(response); + + const list = $('p > a') + .toArray() + .map((elem) => { + elem = $(elem); + return { + title: elem.find('b').text(), + link: new URL(elem.attr('href'), baseUrl).href, + pubDate: parseDate(elem.next().next('small').text().split('.')[0]), + }; + }) + .slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 10); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + if (!item.link.startsWith('https://keepass.info/')) { + return item; + } + + const { data } = await got(item.link); + const $ = cheerio.load(data); + + $('.sectionheader').remove(); + $('.laytablews > tbody> tr:nth-child(1) > td:nth-child(2) > p').first().remove(); + + item.description = $('.laytablews > tbody> tr:nth-child(1) > td:nth-child(2)').html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: $('head title').attr('content'), + link: baseUrl, + item: items, + }; +}; diff --git a/lib/v2/keepass/radar.js b/lib/v2/keepass/radar.js new file mode 100644 index 00000000000000..d03658c1aab962 --- /dev/null +++ b/lib/v2/keepass/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'keepass.info': { + _name: 'KeePass', + '.': [ + { + title: 'News', + docs: 'https://docs.rsshub.app/routes/program-update.html#keepass', + source: ['/news/news_all.html', '/'], + target: '/keepass/news', + }, + ], + }, +}; diff --git a/lib/v2/keepass/router.js b/lib/v2/keepass/router.js new file mode 100644 index 00000000000000..bfacc196581817 --- /dev/null +++ b/lib/v2/keepass/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/', require('./news')); +}; diff --git a/website/docs/routes/program-update.mdx b/website/docs/routes/program-update.mdx index c0c2f83f88af0a..972a2b25d2792b 100644 --- a/website/docs/routes/program-update.mdx +++ b/website/docs/routes/program-update.mdx @@ -329,6 +329,12 @@ Need to configure `CIVITAI_COOKIE` to obtain image information of NSFW models. +## KeePass {#keepass} + +### News {#keepass-news} + + + ## Logseq {#logseq} :::warning