diff --git a/docs/blog.md b/docs/blog.md index 058476e21..83fed53a6 100644 --- a/docs/blog.md +++ b/docs/blog.md @@ -316,9 +316,9 @@ username 为博主用户名,而非`xxx.hashnode.dev`中`xxx`所代表的 blog ## 十年之约 -### 文章 +### 专题展示 - 文章 - + ## 王五四文集 diff --git a/lib/routes/blogs/foreverblog.js b/lib/routes/blogs/foreverblog.js deleted file mode 100644 index 724dad408..000000000 --- a/lib/routes/blogs/foreverblog.js +++ /dev/null @@ -1,33 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const response = await got({ - method: 'get', - url: 'https://www.foreverblog.cn/feeds.html', - }); - - const data = response.data; - - const $ = cheerio.load(data); - const list = $('article[class="post post-type-normal"]'); - - ctx.state.data = { - title: '十年之约 - 订阅', - link: 'https://www.foreverblog.cn/feeds.html', - language: 'zh-cn', - item: - list && - list - .map((index, item) => { - item = $(item); - return { - title: item.find('a.post-title-link>span').text(), - description: item.find('div.post-author').text(), - link: item.find('a.post-title-link').attr('href'), - pubDate: item.find('time.post-time').text(), - }; - }) - .get(), - }; -}; diff --git a/lib/v2/foreverblog/feeds.js b/lib/v2/foreverblog/feeds.js new file mode 100644 index 000000000..812d4c72b --- /dev/null +++ b/lib/v2/foreverblog/feeds.js @@ -0,0 +1,36 @@ +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 currentUrl = 'https://www.foreverblog.cn/feeds.html'; + + const response = await got(currentUrl); + + const $ = cheerio.load(response.data); + const $articles = $('article[class="post post-type-normal"]'); + const items = $articles + .map((_, el) => { + const $titleDiv = $(el).find('h1[class="post-title"]'); + const title = $titleDiv.text().trim(); + const link = $titleDiv.find('a').eq(0).attr('href'); + const author = $(el).find('div[class="post-author"]').text().trim(); + const postDate = $(el).find('time').text().trim(); + const pubDate = timezone(parseDate(postDate, 'MM-DD'), +8); + const description = `${author}: ${title}`; + return { + title: description, + description, + link, + pubDate, + }; + }) + .toArray(); + + ctx.state.data = { + title: '十年之约——专题展示', + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/foreverblog/maintainer.js b/lib/v2/foreverblog/maintainer.js new file mode 100644 index 000000000..915061a8a --- /dev/null +++ b/lib/v2/foreverblog/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/feeds': ['7Wate', 'a180285'], +}; diff --git a/lib/v2/foreverblog/radar.js b/lib/v2/foreverblog/radar.js new file mode 100644 index 000000000..f1dbb3e03 --- /dev/null +++ b/lib/v2/foreverblog/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'foreverblog.cn': { + _name: '十年之约', + www: [ + { + title: '专题展示', + docs: 'https://docs.rsshub.app/blog.html#shi-nian-zhi-yue', + source: ['/feeds.html'], + target: '/foreverblog/feeds', + }, + ], + }, +}; diff --git a/lib/v2/foreverblog/router.js b/lib/v2/foreverblog/router.js new file mode 100644 index 000000000..1a696ebc3 --- /dev/null +++ b/lib/v2/foreverblog/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/feeds', require('./feeds')); +};