diff --git a/lib/router.js b/lib/router.js index 810cbee70..c5ff679ab 100644 --- a/lib/router.js +++ b/lib/router.js @@ -133,8 +133,8 @@ router.get('/plainlaw/archives', lazyloadRouteHandler('./routes/plainlaw/archive // router.get('/jandan/:sub_model', lazyloadRouteHandler('./routes/jandan/pic')); // 喷嚏 -router.get('/dapenti/tugua', lazyloadRouteHandler('./routes/dapenti/tugua')); -router.get('/dapenti/subject/:id', lazyloadRouteHandler('./routes/dapenti/subject')); +// router.get('/dapenti/tugua', lazyloadRouteHandler('./routes/dapenti/tugua')); +// router.get('/dapenti/subject/:id', lazyloadRouteHandler('./routes/dapenti/subject')); // Dockone router.get('/dockone/weekly', lazyloadRouteHandler('./routes/dockone/weekly')); diff --git a/lib/routes/dapenti/utils.js b/lib/routes/dapenti/utils.js deleted file mode 100644 index 6dfba0358..000000000 --- a/lib/routes/dapenti/utils.js +++ /dev/null @@ -1,73 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const iconv = require('iconv-lite'); -const { parseDate } = require('@/utils/parse-date'); -const timezone = require('@/utils/timezone'); - -module.exports = { - parseFeed: async ({ subjectid }) => { - const url = `https://www.dapenti.com/blog/blog.asp?name=xilei&subjectid=${subjectid}`; - const listRes = await got({ - method: 'get', - url, - headers: { - Referer: url, - }, - // 喷嚏网编码为GBK,需要转码 - // 转码需要设定返回数据的格式,其可选项是arraybuffer,blob,document,json,text,stream - // 默认为json - responseType: 'buffer', - }); - // 转码 - const data = iconv.decode(listRes.data, 'gb2312'); - const $ = cheerio.load(data); - // 只取最近的三个,取全文rss - const list = $('li', 'ul').slice(0, 3).get(); - - const result_item = await Promise.all( - list.map(async (item) => { - const el = $(item); - const url = `https://www.dapenti.com/blog/${el.find('a').attr('href')}`; - const original_data = await got({ - method: 'get', - url, - headers: { - Referer: url, - }, - responseType: 'buffer', - }); - const convert_data = iconv.decode(original_data.data, 'gbk'); - const description = cheerio.load(convert_data, { - decodeEntities: false, - })('body > table > tbody > tr > td.oblog_t_2 > div > table > tbody > tr:nth-child(2) > td'); - const pubInfo = description.find('span span.oblog_text').text().split('发布于'); - description.find('table, .adsbygoogle').remove(); - - // remove header - const count = subjectid.toString() === '70' ? 8 : 3; - for (let index = 0; index < count; index++) { - description.children().first().remove(); - } - - // remove footer - for (let index = 0; index < 8; index++) { - description.children().last().remove(); - } - const single = { - title: el.text(), - author: pubInfo[0].trim(), - description: description.html(), - pubDate: timezone(parseDate(pubInfo[1].trim()), +8), - link: url, - }; - return single; - }) - ); - - return { - title: `喷嚏-${subjectid}`, - link: url, - item: result_item, - }; - }, -}; diff --git a/lib/v2/dapenti/maintainer.js b/lib/v2/dapenti/maintainer.js new file mode 100644 index 000000000..e309c6e27 --- /dev/null +++ b/lib/v2/dapenti/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/tugua': ['tgly307'], + '/subject/:id': ['xyqfer'], +}; diff --git a/lib/v2/dapenti/radar.js b/lib/v2/dapenti/radar.js new file mode 100644 index 000000000..98debf304 --- /dev/null +++ b/lib/v2/dapenti/radar.js @@ -0,0 +1,27 @@ +module.exports = { + 'dapenti.com': { + _name: '喷嚏', + '.': [ + { + title: '图卦', + docs: 'https://docs.rsshub.app/picture.html#pen-ti', + source: ['/blog/blog.asp'], + target: (params, url) => { + if (new URL(url).searchParams.get('subjectid') === '70') { + return '/dapenti/tugua'; + } + }, + }, + { + title: '主题', + docs: 'https://docs.rsshub.app/picture.html#pen-ti', + source: ['/blog/blog.asp'], + target: (params, url) => { + if (new URL(url).searchParams.get('subjectid')) { + return '/dapenti/subject/' + new URL(url).searchParams.get('subjectid'); + } + }, + }, + ], + }, +}; diff --git a/lib/v2/dapenti/router.js b/lib/v2/dapenti/router.js new file mode 100644 index 000000000..e03886c5a --- /dev/null +++ b/lib/v2/dapenti/router.js @@ -0,0 +1,4 @@ +module.exports = function (router) { + router.get('/tugua', require('./tugua')); + router.get('/subject/:id', require('./subject')); +}; diff --git a/lib/routes/dapenti/subject.js b/lib/v2/dapenti/subject.js similarity index 90% rename from lib/routes/dapenti/subject.js rename to lib/v2/dapenti/subject.js index 4b3f37a54..cbd0748e5 100644 --- a/lib/routes/dapenti/subject.js +++ b/lib/v2/dapenti/subject.js @@ -1,5 +1,5 @@ const utils = require('./utils'); module.exports = async (ctx) => { - ctx.state.data = await utils.parseFeed({ subjectid: ctx.params.id }); + ctx.state.data = await utils.parseFeed({ subjectid: ctx.params.id }, ctx); }; diff --git a/lib/routes/dapenti/tugua.js b/lib/v2/dapenti/tugua.js similarity index 51% rename from lib/routes/dapenti/tugua.js rename to lib/v2/dapenti/tugua.js index d0f597f78..b6f4047fe 100644 --- a/lib/routes/dapenti/tugua.js +++ b/lib/v2/dapenti/tugua.js @@ -1,5 +1,5 @@ const utils = require('./utils'); module.exports = async (ctx) => { - ctx.state.data = await utils.parseFeed({ subjectid: 70 }); + ctx.state.data = await utils.parseFeed({ subjectid: 70 }, ctx); }; diff --git a/lib/v2/dapenti/utils.js b/lib/v2/dapenti/utils.js new file mode 100644 index 000000000..04a6127aa --- /dev/null +++ b/lib/v2/dapenti/utils.js @@ -0,0 +1,75 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +module.exports = { + parseFeed: async ({ subjectid }, ctx) => { + const url = `https://www.dapenti.com/blog/blog.asp?name=xilei&subjectid=${subjectid}`; + const listRes = await got({ + method: 'get', + url, + headers: { + Referer: url, + }, + // 喷嚏网编码为GBK,需要转码 + // 转码需要设定返回数据的格式,其可选项是arraybuffer,blob,document,json,text,stream + // 默认为json + responseType: 'buffer', + }); + // 转码 + const data = iconv.decode(listRes.data, 'gb2312'); + const $ = cheerio.load(data); + // 只取最近的三个,取全文rss + const list = $('li', 'ul').slice(0, 3).get(); + + const result_item = await Promise.all( + list.map((item) => + ctx.cache.tryGet(`https://www.dapenti.com/blog/${$(item).find('a').attr('href')}`, async () => { + const el = $(item); + const url = `https://www.dapenti.com/blog/${el.find('a').attr('href')}`; + const original_data = await got({ + method: 'get', + url, + headers: { + Referer: url, + }, + responseType: 'buffer', + }); + const convert_data = iconv.decode(original_data.data, 'gbk'); + const description = cheerio.load(convert_data, { + decodeEntities: false, + })('body > table > tbody > tr > td.oblog_t_2 > div > table > tbody > tr:nth-child(2) > td'); + const pubInfo = description.find('span span.oblog_text').text().split('发布于'); + description.find('table, .adsbygoogle').remove(); + + // remove header + const count = subjectid.toString() === '70' ? 7 : 3; + for (let index = 0; index < count; index++) { + description.children().first().remove(); + } + + // remove footer + for (let index = 0; index < 8; index++) { + description.children().last().remove(); + } + const single = { + title: el.text(), + author: pubInfo[0].trim(), + description: description.html(), + pubDate: timezone(parseDate(pubInfo[1]?.trim()), +8), + link: url, + }; + return single; + }) + ) + ); + + return { + title: `喷嚏-${subjectid}`, + link: url, + item: result_item, + }; + }, +};