feat(route): add LogoNews (#8810)
This commit is contained in:
@@ -65,6 +65,48 @@ Behance 用户主页 URL 获取用户名,如 <https://www.behance.net/mishapet
|
||||
<Route author="miaoyafeng" example="/invisionapp/inside-design" path="/invisionapp/inside-design">
|
||||
</Route>
|
||||
|
||||
## LogoNews 标志情报局
|
||||
|
||||
### 首页
|
||||
|
||||
<Route author="nczitzk" example="/logonews" path="/logonews"/>
|
||||
|
||||
### 文章分类
|
||||
|
||||
<Route author="nczitzk" example="/logonews/category/news/newsletter" path="/logonews/category/:category/:type" :paramsDesc="['分类,可在对应分类页 URL 中找到', '类型,可在对应分类页 URL 中找到']">
|
||||
|
||||
如 [简讯 - 标志情报局](https://www.logonews.cn/category/news/newsletter) 的 URL 为 <https://www.logonews.cn/category/news/newsletter>,可得路由为 [`/logonews/category/news/newsletter`](https://rsshub.app/logonews/category/news/newsletter)。
|
||||
|
||||
</Route>
|
||||
|
||||
### 文章标签
|
||||
|
||||
<Route author="nczitzk" example="/logonews/tag/china" path="/logonews/tag/:tag" :paramsDesc="['标签,可在对应标签页 URL 中找到']">
|
||||
|
||||
如 [中国 - 标志情报局](https://www.logonews.cn/tag/china) 的 URL 为 <https://www.logonews.cn/tag/china>,可得路由为 [`/logonews/tag/china`](https://rsshub.app/logonews/tag/china)。
|
||||
|
||||
</Route>
|
||||
|
||||
### 作品
|
||||
|
||||
<Route author="nczitzk" example="/logonews/work" path="/logonews/work"/>
|
||||
|
||||
### 作品分类
|
||||
|
||||
<Route author="nczitzk" example="/logonews/work/categorys/hotel-catering" path="/logonews/work/categorys/:category" :paramsDesc="['分类,可在对应分类页 URL 中找到']">
|
||||
|
||||
如 [LOGO 作品分类:酒店餐饮 - 标志情报局](https://www.logonews.cn/work/categorys/hotel-catering) 的 URL 为 <https://www.logonews.cn/work/categorys/hotel-catering>,可得路由为 [`/logonews/work/categorys/hotel-catering`](https://rsshub.app/logonews/work/categorys/hotel-catering)。
|
||||
|
||||
</Route>
|
||||
|
||||
### 作品标签
|
||||
|
||||
<Route author="nczitzk" example="/logonews/work/tags/旅游" path="/logonews/work/tags/:tag?" :paramsDesc="['标签,可在对应标签页 URL 中找到']">
|
||||
|
||||
如 [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/旅游)。
|
||||
|
||||
</Route>
|
||||
|
||||
## Method Studios
|
||||
|
||||
### 菜单
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
'/work/tags/:tag': ['nczitzk'],
|
||||
'/work/categorys/:category': ['nczitzk'],
|
||||
'/work': ['nczitzk'],
|
||||
'/category/:category/:type': ['nczitzk'],
|
||||
'/tag/:tag': ['nczitzk'],
|
||||
'/': ['nczitzk'],
|
||||
};
|
||||
@@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -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'));
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
{{if isWork}}
|
||||
<img src="{{ image }}">
|
||||
{{/if}}
|
||||
{{ description }}
|
||||
Reference in New Issue
Block a user