From 86c9f24d9b0ebbac3c2800fc254760aa7ff1d388 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 23 Jan 2022 04:21:11 +0800 Subject: [PATCH] feat(route): add LogoNews (#8810) --- docs/design.md | 42 +++++++++++++ lib/v2/logonews/index.js | 76 +++++++++++++++++++++++ lib/v2/logonews/maintainer.js | 8 +++ lib/v2/logonews/radar.js | 43 +++++++++++++ lib/v2/logonews/router.js | 5 ++ lib/v2/logonews/templates/description.art | 4 ++ 6 files changed, 178 insertions(+) create mode 100644 lib/v2/logonews/index.js create mode 100644 lib/v2/logonews/maintainer.js create mode 100644 lib/v2/logonews/radar.js create mode 100644 lib/v2/logonews/router.js create mode 100644 lib/v2/logonews/templates/description.art diff --git a/docs/design.md b/docs/design.md index db59916b5..2a475aaeb 100644 --- a/docs/design.md +++ b/docs/design.md @@ -65,6 +65,48 @@ Behance 用户主页 URL 获取用户名,如 +## LogoNews 标志情报局 + +### 首页 + + + +### 文章分类 + + + +如 [简讯 - 标志情报局](https://www.logonews.cn/category/news/newsletter) 的 URL 为 ,可得路由为 [`/logonews/category/news/newsletter`](https://rsshub.app/logonews/category/news/newsletter)。 + + + +### 文章标签 + + + +如 [中国 - 标志情报局](https://www.logonews.cn/tag/china) 的 URL 为 ,可得路由为 [`/logonews/tag/china`](https://rsshub.app/logonews/tag/china)。 + + + +### 作品 + + + +### 作品分类 + + + +如 [LOGO 作品分类:酒店餐饮 - 标志情报局](https://www.logonews.cn/work/categorys/hotel-catering) 的 URL 为 ,可得路由为 [`/logonews/work/categorys/hotel-catering`](https://rsshub.app/logonews/work/categorys/hotel-catering)。 + + + +### 作品标签 + + + +如 [LOGO 标签:旅游 - 标志情报局](https://www.logonews.cn/work/tags/旅游) 的 URL 为 [https://www.logonews.cn/work/tags/ 旅游](https://www.logonews.cn/work/tags/旅游),可得路由为 [`/logonews/work/tags/旅游`](https://rsshub.app/logonews/work/tags/旅游)。 + + + ## Method Studios ### 菜单 diff --git a/lib/v2/logonews/index.js b/lib/v2/logonews/index.js new file mode 100644 index 000000000..3cf338ece --- /dev/null +++ b/lib/v2/logonews/index.js @@ -0,0 +1,76 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const params = ctx.path; + const isWork = params.indexOf('/work') === 0; + + const rootUrl = 'https://www.logonews.cn'; + const currentUrl = `${rootUrl}${params === '/' ? '' : params}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $(isWork ? 'h2 a' : 'a.article-link') + .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 25) + .toArray() + .map((item) => { + item = $(item); + + return { + link: item.attr('href'), + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + content('.iconfont').remove(); + + content('img[data-src]').each(function () { + content(this).attr( + 'src', + content(this) + .attr('data-src') + .replace(/_logonews/, '') + ); + }); + + item.title = content('title').text(); + item.author = content('.author-links').text(); + item.pubDate = parseDate(content('meta[property="og:release_date"]').attr('content')); + item.category = content('a.category_link, a[rel="tag"]') + .toArray() + .map((c) => content(c).text().replace(/ · /g, '')); + + item.description = art(path.join(__dirname, 'templates/description.art'), { + isWork, + image: content('meta[property="og:image"]').attr('content'), + description: content('.This_Article_content, .w_info').html(), + }); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/logonews/maintainer.js b/lib/v2/logonews/maintainer.js new file mode 100644 index 000000000..07de94997 --- /dev/null +++ b/lib/v2/logonews/maintainer.js @@ -0,0 +1,8 @@ +module.exports = { + '/work/tags/:tag': ['nczitzk'], + '/work/categorys/:category': ['nczitzk'], + '/work': ['nczitzk'], + '/category/:category/:type': ['nczitzk'], + '/tag/:tag': ['nczitzk'], + '/': ['nczitzk'], +}; diff --git a/lib/v2/logonews/radar.js b/lib/v2/logonews/radar.js new file mode 100644 index 000000000..afd4eae4b --- /dev/null +++ b/lib/v2/logonews/radar.js @@ -0,0 +1,43 @@ +module.exports = { + 'logonews.cn': { + _name: 'LogoNews 标志情报局', + '.': [ + { + title: '首页', + docs: 'https://docs.rsshub.app/design.html#logonews-biao-zhi-qing-bao-ju-shou-ye', + source: ['/'], + target: '/logonews', + }, + { + title: '文章分类', + docs: 'https://docs.rsshub.app/design.html#logonews-biao-zhi-qing-bao-ju-wen-zhang-fen-lei', + source: ['/category/:category/:type?'], + target: '/logonews/category/:category/:type?', + }, + { + title: '文章标签', + docs: 'https://docs.rsshub.app/design.html#logonews-biao-zhi-qing-bao-ju-wen-zhang-biao-qian', + source: ['/tag/:tag'], + target: '/logonews/tag/:tag', + }, + { + title: '作品', + docs: 'https://docs.rsshub.app/design.html#logonews-biao-zhi-qing-bao-ju-zuo-pin', + source: ['/work'], + target: '/logonews/work', + }, + { + title: '作品分类', + docs: 'https://docs.rsshub.app/design.html#logonews-biao-zhi-qing-bao-ju-zuo-pin-fen-lei', + source: ['/work/categorys/:category'], + target: '/logonews/work/categorys/:category', + }, + { + title: '作品标签', + docs: 'https://docs.rsshub.app/design.html#logonews-biao-zhi-qing-bao-ju-zuo-pin-biao-qian', + source: ['/work/tags/:tag'], + target: '/logonews/work/tags/:tag', + }, + ], + }, +}; diff --git a/lib/v2/logonews/router.js b/lib/v2/logonews/router.js new file mode 100644 index 000000000..2d5748066 --- /dev/null +++ b/lib/v2/logonews/router.js @@ -0,0 +1,5 @@ +module.exports = function (router) { + router.get('/work/tags/:tag', require('./index')); + router.get('/tag/:tag', require('./index')); + router.get(/([\w|\d|/|-]+)?/, require('./index')); +}; diff --git a/lib/v2/logonews/templates/description.art b/lib/v2/logonews/templates/description.art new file mode 100644 index 000000000..946e8f84c --- /dev/null +++ b/lib/v2/logonews/templates/description.art @@ -0,0 +1,4 @@ +{{if isWork}} + +{{/if}} +{{ description }} \ No newline at end of file