mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-11 23:59:56 +08:00
feat: add数英网文章及项目专题 (#2204)
* add 数英网 * fix: 部分标题无法显示 * feat: add数英网文章及项目专题 * remove duplicate route
This commit is contained in:
57
lib/routes/digitaling/project.js
Normal file
57
lib/routes/digitaling/project.js
Normal file
@@ -0,0 +1,57 @@
|
||||
const cheerio = require('cheerio');
|
||||
const axios = require('@/utils/axios');
|
||||
|
||||
// 分类标题
|
||||
const categoryTitle = new Map([
|
||||
['all', { name: '全部' }],
|
||||
['weekly', { name: '每周项目精选' }],
|
||||
['monthly', { name: '每月项目精选' }],
|
||||
['international', { name: '海外项目精选' }],
|
||||
['hot', { name: '近期热门项目' }],
|
||||
['favorite', { name: '近期最多收藏' }],
|
||||
]);
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const category = ctx.params.category;
|
||||
const link = `https://www.digitaling.com/projects/${category}`;
|
||||
const res = await axios.get(link);
|
||||
const $ = cheerio.load(res.data);
|
||||
// 标题
|
||||
const title = categoryTitle.get(category).name;
|
||||
// 文章列表
|
||||
const list = $('#pro_list .works_title h3')
|
||||
.find('a')
|
||||
.map((i, e) => $(e).attr('href'))
|
||||
.get();
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (itemUrl) => {
|
||||
const cache = await ctx.cache.get(itemUrl);
|
||||
// 判断缓存
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
const res = await axios.get(itemUrl);
|
||||
const $ = cheerio.load(res.data);
|
||||
|
||||
const item = {
|
||||
title: $('.clearfix h2').text(),
|
||||
author: $('#avatar_by')
|
||||
.find('a')
|
||||
.text(),
|
||||
link: itemUrl,
|
||||
description: $('#article_con').html(),
|
||||
pubDate: new Date().toUTCString(),
|
||||
};
|
||||
ctx.cache.set(itemUrl, JSON.stringify(item));
|
||||
|
||||
return Promise.resolve(item);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `数英网-项目专题-${title}`,
|
||||
link: link,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user