diff --git a/docs/programming.md b/docs/programming.md index c510b5bc1..3bbe87dc0 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -720,7 +720,7 @@ GitHub 官方也提供了一些 RSS: ### 分类订阅 - + | 360 网络安全周报 | 活动 | 知识 | 资讯 | 招聘 | 工具 | | ---------- | -------- | --------- | ---- | --- | ---- | diff --git a/lib/v2/anquanke/category.js b/lib/v2/anquanke/category.js index cc4262e49..2dfbe6a09 100644 --- a/lib/v2/anquanke/category.js +++ b/lib/v2/anquanke/category.js @@ -1,20 +1,32 @@ const got = require('@/utils/got'); +const cheerio = require('cheerio'); const { parseDate } = require('@/utils/parse-date'); const timezone = require('@/utils/timezone'); module.exports = async (ctx) => { const api = 'https://api.anquanke.com/data/v1/posts?size=10&page=1&category='; const type = ctx.params.category; + const fulltext = ctx.params.fulltext; const host = 'https://www.anquanke.com'; const res = await got(`${api}${type}`); const dataArray = res.data.data; - const items = dataArray.map((item) => ({ - title: item.title, - description: item.desc, - pubDate: timezone(parseDate(item.date), +8), - link: `${host}/${type === 'week' ? 'week' : 'post'}/id/${item.id}`, - author: item.author.nickname, + const items = await Promise.all( + dataArray.map(async (item) => { + const art_url = `${host}/${type === 'week' ? 'week' : 'post'}/id/${item.id}`; + return { + title: item.title, + description: fulltext === 'fulltext' || fulltext === 'quanwen' + ? await ctx.cache.tryGet(art_url, async () => { + const { data: res } = await got(art_url); + const content = cheerio.load(res); + return content('#js-article').html(); + }) + : item.desc, + pubDate: timezone(parseDate(item.date), +8), + link: art_url, + author: item.author.nickname, + }; })); ctx.state.data = { diff --git a/lib/v2/anquanke/maintainer.js b/lib/v2/anquanke/maintainer.js index e247fa46d..0dc8f87b5 100644 --- a/lib/v2/anquanke/maintainer.js +++ b/lib/v2/anquanke/maintainer.js @@ -1,4 +1,4 @@ module.exports = { // '/vul': ['qwertyuiop6'], - '/:category': ['qwertyuiop6'], + '/:category/:fulltext?': ['qwertyuiop6'], }; diff --git a/lib/v2/anquanke/router.js b/lib/v2/anquanke/router.js index 7cc1f079a..08674bf4e 100644 --- a/lib/v2/anquanke/router.js +++ b/lib/v2/anquanke/router.js @@ -1,4 +1,4 @@ module.exports = (router) => { // router.get('/vul', require('./vul')); // 404 - router.get('/:category', require('./category')); + router.get('/:category/:fulltext?', require('./category')); };