From cff988ad9f231ddf3087c912fb245637894e7314 Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Sun, 17 Apr 2022 21:24:17 +0800 Subject: [PATCH] feat(route): add Eagle's blog and refactor to V2 (#9546) * feat(route): add Eagle's blog and refactor to V2 * fix: remove deprecated eagle radar rules * fix: changelog date and guid * fix(route): add language option --- assets/radar-rules.js | 6 -- docs/design.md | 12 +++ docs/en/design.md | 6 ++ lib/radar-rules.js | 27 ------- lib/router.js | 2 +- lib/v2/eagle/blog.js | 47 ++++++++++++ lib/{routes => v2}/eagle/changelog.js | 4 +- lib/v2/eagle/maintainer.js | 4 + lib/v2/eagle/radar.js | 101 ++++++++++++++++++++++++++ lib/v2/eagle/router.js | 4 + 10 files changed, 178 insertions(+), 35 deletions(-) create mode 100644 lib/v2/eagle/blog.js rename lib/{routes => v2}/eagle/changelog.js (93%) create mode 100644 lib/v2/eagle/maintainer.js create mode 100644 lib/v2/eagle/radar.js create mode 100644 lib/v2/eagle/router.js diff --git a/assets/radar-rules.js b/assets/radar-rules.js index c53c451a9e..f8b487db7e 100644 --- a/assets/radar-rules.js +++ b/assets/radar-rules.js @@ -1053,12 +1053,6 @@ }, ], }, - 'eagle.cool': { - _name: 'Eagle', - cn: [{ title: '更新日志', docs: 'https://docs.rsshub.app/program-update.html#eagle', source: '/changelog', target: '/eagle/changelog/cn' }], - tw: [{ title: '更新日誌', docs: 'https://docs.rsshub.app/program-update.html#eagle', source: '/changelog', target: '/eagle/changelog/tw' }], - en: [{ title: 'Release Notes', docs: 'https://docs.rsshub.app/program-update.html#eagle', source: '/changelog', target: '/eagle/changelog/en' }], - }, 'furaffinity.net': { _name: 'Fur Affinity', www: [ diff --git a/docs/design.md b/docs/design.md index bc965b34d7..7478284a40 100644 --- a/docs/design.md +++ b/docs/design.md @@ -58,6 +58,18 @@ Behance 用户主页 URL 获取用户名,如 +## Eagle + +### 博客 + + + +| 全部 | 设计资源 | 设计技巧 | 最新消息 | +| --- | ---------------- | ------------ | ------------ | +| all | design-resources | learn-design | inside-eagle | + + + ## Google ### Google Fonts diff --git a/docs/en/design.md b/docs/en/design.md index cf23f69d39..5893dffe3a 100644 --- a/docs/en/design.md +++ b/docs/en/design.md @@ -58,6 +58,12 @@ Behance user's profile URL, like the user +## Eagle + +### Blog + + + ## Google ### Google Fonts diff --git a/lib/radar-rules.js b/lib/radar-rules.js index 59e756f7b3..09b673c293 100644 --- a/lib/radar-rules.js +++ b/lib/radar-rules.js @@ -2226,33 +2226,6 @@ module.exports = { }, ], }, - 'eagle.cool': { - _name: 'Eagle', - cn: [ - { - title: '更新日志', - docs: 'https://docs.rsshub.app/program-update.html#eagle', - source: '/changelog', - target: '/eagle/changelog/cn', - }, - ], - tw: [ - { - title: '更新日誌', - docs: 'https://docs.rsshub.app/program-update.html#eagle', - source: '/changelog', - target: '/eagle/changelog/tw', - }, - ], - en: [ - { - title: 'Release Notes', - docs: 'https://docs.rsshub.app/program-update.html#eagle', - source: '/changelog', - target: '/eagle/changelog/en', - }, - ], - }, 'furaffinity.net': { _name: 'Fur Affinity', www: [ diff --git a/lib/router.js b/lib/router.js index e740efec2c..51692f1e94 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3878,7 +3878,7 @@ router.get('/ccg/:category?', lazyloadRouteHandler('./routes/ccg/index')); // router.get('/gf-cn/news/:category?', lazyloadRouteHandler('./routes/gf-cn/news')); // Eagle -router.get('/eagle/changelog/:language?', lazyloadRouteHandler('./routes/eagle/changelog')); +// router.get('/eagle/changelog/:language?', lazyloadRouteHandler('./routes/eagle/changelog')); // ezone.hk // router.get('/ezone/:category?', lazyloadRouteHandler('./routes/ezone/index')); diff --git a/lib/v2/eagle/blog.js b/lib/v2/eagle/blog.js new file mode 100644 index 0000000000..8b407f445f --- /dev/null +++ b/lib/v2/eagle/blog.js @@ -0,0 +1,47 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +const cateList = ['all', 'design-resources', 'learn-design', 'inside-eagle']; + +module.exports = async (ctx) => { + let cate = ctx.params.cate ?? 'all'; + let language = ctx.params.language ?? 'cn'; + if (cateList.indexOf(cate) === -1) { + language = cate; + cate = 'all'; + } + const host = `https://${language}.eagle.cool`; + const url = `${host}/blog/${cate === 'all' ? '' : cate}`; + + const response = await got(url); + const $ = cheerio.load(response.data); + const title = $('div.categories-list > div > div > div > ul > li.active').text(); + const list = $('div.post-item') + .map((_index, item) => ({ + title: $(item).find('div.title').text(), + link: new URL($(item).find('a').attr('href'), host).href, + pubDate: parseDate($(item).find('div.metas > a > span').text().replace('・', '')), + })) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link); + + const content = cheerio.load(detailResponse.data); + + item.description = content('div.post-html').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `eagle - ${title}`, + link: url, + item: items, + }; +}; diff --git a/lib/routes/eagle/changelog.js b/lib/v2/eagle/changelog.js similarity index 93% rename from lib/routes/eagle/changelog.js rename to lib/v2/eagle/changelog.js index 134ec001b5..2e8f7a6806 100644 --- a/lib/routes/eagle/changelog.js +++ b/lib/v2/eagle/changelog.js @@ -1,5 +1,6 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { let language = ctx.params.language; @@ -67,7 +68,8 @@ module.exports = async (ctx) => { title: item.find('.ver').text(), description: item.find('.logs').html(), link: `https://${language}.eagle.cool/changelog`, - pubDate: new Date(getDate()).toUTCString(), + pubDate: parseDate(getDate()), + guid: item.find('.ver').text(), }; }) .get(), diff --git a/lib/v2/eagle/maintainer.js b/lib/v2/eagle/maintainer.js new file mode 100644 index 0000000000..db0f109cc2 --- /dev/null +++ b/lib/v2/eagle/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/blog/:cate?/:language?': ['Fatpandac'], + '/changelog/:language?': ['tigercubden'], +}; diff --git a/lib/v2/eagle/radar.js b/lib/v2/eagle/radar.js new file mode 100644 index 0000000000..ada749aa48 --- /dev/null +++ b/lib/v2/eagle/radar.js @@ -0,0 +1,101 @@ +module.exports = { + 'eagle.cool': { + _name: 'Eagle', + cn: [ + { + title: '更新日志', + docs: 'https://docs.rsshub.app/program-update.html#eagle', + source: '/changelog', + target: '/eagle/changelog/cn', + }, + { + title: '全部', + docs: 'https://docs.rsshub.app/design.html#eagle', + source: ['/blog'], + target: '/eagle/blog', + }, + { + title: '设计资源', + docs: 'https://docs.rsshub.app/design.html#eagle', + source: ['/blog/design-resources'], + target: '/eagle/blog/design-resources', + }, + { + title: '设计技巧', + docs: 'https://docs.rsshub.app/design.html#eagle', + source: ['/blog/learn-design'], + target: '/eagle/blog/learn-design', + }, + { + title: '最新消息', + docs: 'https://docs.rsshub.app/design.html#eagle', + source: ['/blog/inside-eagle'], + target: '/eagle/blog/inside-eagle', + }, + ], + tw: [ + { + title: '更新日誌', + docs: 'https://docs.rsshub.app/program-update.html#eagle', + source: '/changelog', + target: '/eagle/changelog/tw', + }, + { + title: '全部', + docs: 'https://docs.rsshub.app/design.html#eagle', + source: ['/blog'], + target: '/eagle/blog/tw', + }, + { + title: '設計資源', + docs: 'https://docs.rsshub.app/design.html#eagle', + source: ['/blog/design-resources'], + target: '/eagle/blog/design-resources/tw', + }, + { + title: '設計技巧', + docs: 'https://docs.rsshub.app/design.html#eagle', + source: ['/blog/learn-design'], + target: '/eagle/blog/learn-design/tw', + }, + { + title: '最新消息', + docs: 'https://docs.rsshub.app/design.html#eagle', + source: ['/blog/inside-eagle'], + target: '/eagle/blog/inside-eagle/tw', + }, + ], + en: [ + { + title: 'Release Notes', + docs: 'https://docs.rsshub.app/program-update.html#eagle', + source: '/changelog', + target: '/eagle/changelog/en', + }, + { + title: 'All', + docs: 'https://docs.rsshub.app/design.html#eagle', + source: ['/blog'], + target: '/eagle/blog/en', + }, + { + title: 'Design Resources', + docs: 'https://docs.rsshub.app/design.html#eagle', + source: ['/blog/design-resources'], + target: '/eagle/blog/design-resources/en', + }, + { + title: 'Learn Design', + docs: 'https://docs.rsshub.app/design.html#eagle', + source: ['/blog/learn-design'], + target: '/eagle/blog/learn-design/en', + }, + { + title: 'Inside Eagle', + docs: 'https://docs.rsshub.app/design.html#eagle', + source: ['/blog/inside-eagle'], + target: '/eagle/blog/inside-eagle/en', + }, + ], + }, +}; diff --git a/lib/v2/eagle/router.js b/lib/v2/eagle/router.js new file mode 100644 index 0000000000..0b9a46eeb1 --- /dev/null +++ b/lib/v2/eagle/router.js @@ -0,0 +1,4 @@ +module.exports = function (router) { + router.get('/blog/:cate?/:language?', require('./blog')); + router.get('/changelog/:language?', require('./changelog')); +};