feat(route): add 簡訊設計 (#11228)

* feat(route): add 簡訊設計

* fix(route): improve async and use templates
This commit is contained in:
Haukeng 2022-11-07 21:42:38 +08:00 committed by GitHub
parent 5890fc8007
commit f553391447
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 101 additions and 0 deletions

View File

@ -2483,6 +2483,26 @@ others = 热点新闻 + 滚动新闻
<Route author="nczitzk" example="/jiazhen108" path="/jiazhen108" />
## 簡訊設計
### 志祺七七
<Route author="haukeng" example="/simpleinfo" path="/simpleinfo/:category?" radar="1" rssbud="1" :paramsDesc="['分类名']">
| 夥伴聊聊 | 專案設計 |
| ---- | ---- |
| work | talk |
| 國內外新聞 | 政治百分百 | 社會觀察家 | 心理與哲學 |
| ----- | -------- | ------- | --------------------- |
| news | politics | society | psychology-philosophy |
| 科學大探索 | 環境與健康 | ACG 快樂聊 | 好書籍分享 | 其它主題 |
| ------- | ------------------ | ------- | ------------ | ------------ |
| science | environment-health | acg | book-sharing | other-topics |
</Route>
## 健康界
### 首页

View File

@ -0,0 +1,50 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const path = require('path');
const { art } = require('@/utils/render');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const { category } = ctx.params;
const rootUrl = 'https://blog.simpleinfo.cc';
const link = `${rootUrl}${category ? (category === 'work' || category === 'talk' ? `/blog/${category}` : `/shasha77?category=${category}`) : '/shasha77'}`;
const response = await got(link);
const $ = cheerio.load(response.data);
const title = `${$('.-active').text()} - 簡訊設計`;
$('.-ad').remove();
const list = $('.article-item')
.map((_, item) => {
item = $(item);
return {
title: item.find('.title').text(),
link: item.find('a').first().attr('href'),
category: item.find('.category').text(),
};
})
.get();
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const result = await got(item.link);
const content = cheerio.load(result.data);
item.author = content('meta[property="article:author"]').attr('content');
item.pubDate = timezone(parseDate(content('meta[property="article:published_time"]').attr('content')), +8);
item.description = art(path.join(__dirname, 'templates/description.art'), {
image: content('meta[property="og:image"]').attr('content'),
description: content('.article-content').first().html(),
});
return item;
})
)
);
ctx.state.data = {
title,
link,
language: 'zh-tw',
item: items,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/:category?': ['haukeng'],
};

View File

@ -0,0 +1,19 @@
module.exports = {
'blog.simpleinfo.cc': {
_name: '簡訊設計',
'.': [
{
title: '志祺七七',
docs: 'https://docs.rsshub.app/new-media.html#jian-xun-she-ji',
source: '/shasha77',
target: (_, url) => `/simpleinfo/${new URL(url).searchParams.get('category')}`,
},
{
title: '夥伴聊聊 / 專案作品',
docs: 'https://docs.rsshub.app/new-media.html#jian-xun-she-ji',
source: '/blog/:category',
target: '/simpleinfo/:category',
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:category?', require('./index'));
};

View File

@ -0,0 +1,6 @@
{{ if image }}
<img src="{{ image }}">
{{ /if }}
{{ if description }}
{{@ description }}
{{ /if }}