diff --git a/assets/radar-rules.js b/assets/radar-rules.js index dde5770e8..e36f10b8c 100644 --- a/assets/radar-rules.js +++ b/assets/radar-rules.js @@ -108,14 +108,6 @@ { title: '栏目', docs: 'https://docs.rsshub.app/other.html#wegene', source: '/crowdsourcing', target: '/wegene/column/all/all' }, ], }, - 'qdaily.com': { - _name: '好奇心日报', - www: [ - { title: '标签', docs: 'https://docs.rsshub.app/new-media.html#hao-qi-xin-ri-bao', source: '/tags/:idd', target: (params) => `/qdaily/tag/${params.idd.replace('.html', '')}` }, - { title: '栏目', docs: 'https://docs.rsshub.app/new-media.html#hao-qi-xin-ri-bao', source: '/special_columns/:idd', target: (params) => `/qdaily/column/${params.idd.replace('.html', '')}` }, - { title: '分类', docs: 'https://docs.rsshub.app/new-media.html#hao-qi-xin-ri-bao', source: '/categories/:idd', target: (params) => `/qdaily/category/${params.idd.replace('.html', '')}` }, - ], - }, '3ycy.com': { _name: '三界异次元', www: [{ title: '最近更新', docs: 'https://docs.rsshub.app/anime.html#san-jie-yi-ci-yuan', source: '/', target: '/3ycy/home' }] }, 'emi-nitta.net': { _name: 'Emi Nitta', diff --git a/lib/radar-rules.js b/lib/radar-rules.js index 97bea2413..43b9c57b4 100644 --- a/lib/radar-rules.js +++ b/lib/radar-rules.js @@ -231,30 +231,6 @@ module.exports = { }, ], }, - 'qdaily.com': { - _name: '好奇心日报', - www: [ - { - title: '标签', - docs: 'https://docs.rsshub.app/new-media.html#hao-qi-xin-ri-bao', - source: '/tags/:idd', - target: (params) => `/qdaily/tag/${params.idd.replace('.html', '')}`, - }, - { - title: '栏目', - docs: 'https://docs.rsshub.app/new-media.html#hao-qi-xin-ri-bao', - source: '/special_columns/:idd', - target: (params) => `/qdaily/column/${params.idd.replace('.html', '')}`, - }, - { - title: '分类', - docs: 'https://docs.rsshub.app/new-media.html#hao-qi-xin-ri-bao', - source: '/categories/:idd', - target: (params) => `/qdaily/category/${params.idd.replace('.html', '')}`, - }, - ], - }, - '3ycy.com': { _name: '三界异次元', www: [ diff --git a/lib/router.js b/lib/router.js index 769135f2f..1a2cc02eb 100644 --- a/lib/router.js +++ b/lib/router.js @@ -173,7 +173,7 @@ router.get('/geektime/news', lazyloadRouteHandler('./routes/geektime/news')); // router.get('/jiemian/list/:cid', lazyloadRouteHandler('./routes/jiemian/list.js')); // 好奇心日报 -router.get('/qdaily/:type/:id', lazyloadRouteHandler('./routes/qdaily/index')); +// router.get('/qdaily/:type/:id', lazyloadRouteHandler('./routes/qdaily/index')); // 爱奇艺 // router.get('/iqiyi/dongman/:id', lazyloadRouteHandler('./routes/iqiyi/dongman')); diff --git a/lib/routes/qdaily/index.js b/lib/routes/qdaily/index.js deleted file mode 100644 index 00af2a5f5..000000000 --- a/lib/routes/qdaily/index.js +++ /dev/null @@ -1,88 +0,0 @@ -const cheerio = require('cheerio'); -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - let type; - switch (ctx.params.type) { - case 'tag': - type = 'tags'; - break; - case 'category': - type = 'categories'; - break; - case 'column': - type = 'special_columns'; - break; - } - - const url = `http://www.qdaily.com/${type}/${ctx.params.id}.html`; - - const res = await got.get(url); - const $ = cheerio.load(res.data); - const list = $('.article').get(); - - const proList = []; - const indexList = []; - - const out = await Promise.all( - list.map(async (item, i) => { - const $ = cheerio.load(item); - let time = $('.smart-date').attr('data-origindate'); - let title = $('.title').text(); - if (!title) { - title = $('.smart-dotdotdot').text(); - } - if (!title) { - const mmTitle = $('.makemoney-title').text(); - const description = $('.makemoney-discription').text(); - title = mmTitle + ':' + description; - time = new Date(); - } - - const itemUrl = $('a').attr('href'); - const allUrl = `http://www.qdaily.com${itemUrl}`; - const cache = await ctx.cache.get(allUrl); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } - const single = { - title, - pubDate: new Date(time).toUTCString(), - link: allUrl, - guid: allUrl, - }; - proList.push(got.get(allUrl)); - indexList.push(i); - return Promise.resolve(single); - }) - ); - const responses = await got.all(proList); - for (let i = 0; i < responses.length; i++) { - const res = responses[i]; - const $ = cheerio.load(res.data); - - $('.article-detail-bd .author-share').remove(); - $('.article-detail-ft').remove(); - $('.lazylood').remove(); - $('img[data-src*="201609181246"]').remove(); - $('.category-title').remove(); - - const images = $('img[data-src]'); - for (let k = 0; k < images.length; k++) { - $(images[k]).replaceWith(``); - } - - if (out[indexList[i]].link.match('/weeklies/')) { - out[indexList[i]].description = $('.packery-container').html(); - } else { - out[indexList[i]].description = $('.main .com-article-detail').html(); - } - - ctx.cache.set(out[indexList[i]].link, JSON.stringify(out[i])); - } - ctx.state.data = { - title: $('title').text(), - link: url, - item: out, - }; -}; diff --git a/lib/v2/qdaily/index.js b/lib/v2/qdaily/index.js new file mode 100644 index 000000000..f1d1e88bb --- /dev/null +++ b/lib/v2/qdaily/index.js @@ -0,0 +1,87 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const baseUrl = 'http://www.qdaily.com'; + const { type, id } = ctx.params; + + const typeMap = { + tag: { + type: 'tags', + apiPath: 'tags/tagmore', + apiSuffix: '.json', + }, + category: { + type: 'categories', + apiPath: 'categories/categorymore', + apiSuffix: '.json', + }, + column: { + type: 'special_columns', + apiPath: 'special_columns/show_more', + apiSuffix: '', + }, + }; + + const url = `${baseUrl}/${typeMap[type].type}/${id}.html`; + + const res = await got(url); + const $ = cheerio.load(res.data); + const lastKey = $('.packery-container').attr('data-lastkey'); + + const { data } = await got(`${baseUrl}/${typeMap[type].apiPath}/${id}/${lastKey}${typeMap[type].apiSuffix}`); + + const list = data.data.feeds.map((item) => ({ + title: item.post.title, + description: item.post.description, + pubDate: parseDate(item.post.publish_time), + link: `${baseUrl}/articles/${item.post.id}.html`, + category: item.post.category.title, + image: item.image, + })); + + const out = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const res = await got(item.link); + const $ = cheerio.load(res.data); + + $('.author-share, .embed-mask, .lazylad, .lazyloa, .lazylod, .lazylaad, .lazylood, .lazyloadd').remove(); + $('.article-detail-bd') + .find('img') + .each((_, img) => { + if (img.attribs['data-src']) { + img.attribs.src = img.attribs['data-src'].split('-w600')[0]; + delete img.attribs['data-src']; + } + }); + + item.description = art(path.join(__dirname, 'templates/article.art'), { + image: item.image.split('?')[0], + description: $('.article-detail-bd').html(), + }); + item.category = [ + ...new Set([ + item.category, + ...$('.tags .tag a') + .toArray() + .map((item) => $(item).text()), + ]), + ]; + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('head title').text(), + description: $('head meta[name="description"]').attr('content'), + image: 'http://www.qdaily.com/favicon.ico', + link: url, + item: out, + }; +}; diff --git a/lib/v2/qdaily/maintainer.js b/lib/v2/qdaily/maintainer.js new file mode 100644 index 000000000..2b59f155e --- /dev/null +++ b/lib/v2/qdaily/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:type/:id': ['WenhuWee', 'emdoe', 'SivaGao', 'HenryQW'], +}; diff --git a/lib/v2/qdaily/router.js b/lib/v2/qdaily/router.js new file mode 100644 index 000000000..dee9a3186 --- /dev/null +++ b/lib/v2/qdaily/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:type/:id', require('./index')); +}; diff --git a/lib/v2/qdaily/templates/article.art b/lib/v2/qdaily/templates/article.art new file mode 100644 index 000000000..32915154e --- /dev/null +++ b/lib/v2/qdaily/templates/article.art @@ -0,0 +1,5 @@ +{{ if image }} +
+{{ /if }} + +{{@ description }} diff --git a/lib/v2/qdaily/templates/radar.js b/lib/v2/qdaily/templates/radar.js new file mode 100644 index 000000000..35066f965 --- /dev/null +++ b/lib/v2/qdaily/templates/radar.js @@ -0,0 +1,25 @@ +module.exports = { + 'qdaily.com': { + _name: '好奇心日报', + '.': [ + { + title: '标签', + docs: 'https://docs.rsshub.app/new-media.html#hao-qi-xin-ri-bao', + source: ['/tags/:id'], + target: (params) => `/qdaily/tag/${params.id.replace('.html', '')}`, + }, + { + title: '栏目', + docs: 'https://docs.rsshub.app/new-media.html#hao-qi-xin-ri-bao', + source: ['/special_columns/:id'], + target: (params) => `/qdaily/column/${params.id.replace('.html', '')}`, + }, + { + title: '分类', + docs: 'https://docs.rsshub.app/new-media.html#hao-qi-xin-ri-bao', + source: ['/categories/:id'], + target: (params) => `/qdaily/category/${params.id.replace('.html', '')}`, + }, + ], + }, +};