diff --git a/lib/v2/jandan/index.js b/lib/v2/jandan/index.js index e3a45abf92..cd0c19710f 100644 --- a/lib/v2/jandan/index.js +++ b/lib/v2/jandan/index.js @@ -1,64 +1,30 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); -const timezone = require('@/utils/timezone'); -const { parseDate } = require('@/utils/parse-date'); -const { art } = require('@/utils/render'); -const path = require('path'); +const parser = require('@/utils/rss-parser'); module.exports = async (ctx) => { const rootUrl = 'http://i.jandan.net'; - - const response = await got({ - method: 'get', - url: rootUrl, - }); - - const $ = cheerio.load(response.data); - - let items = $('.post') - .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 15) - .toArray() - .map((item) => { - item = $(item); - - const a = item.find('.thetitle a'); - - return { - title: a.text(), - link: a.attr('href'), - description: art(path.join(__dirname, 'templates/description.art'), { - summary: item.find('.indexs').text(), - image: item - .find('img') - .attr('data-original') - .replace(/!square/, ''), - }), - }; - }); - - items = await Promise.all( - items.map((item) => + const feed = await parser.parseURL(`${rootUrl}/feed/`); + const items = await Promise.all( + feed.items.map((item) => ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - - const content = cheerio.load(detailResponse.data); - - content('.wechat-hide').prev().nextAll().remove(); - - item.description += content('.entry').html(); - item.author = content('.postinfo strong').text(); - item.pubDate = timezone(parseDate(detailResponse.data.match(/"pubDate": "(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})"/)[1]), +8); - - return item; + const response = await got(item.link); + const $ = cheerio.load(response.data); + $('.wechat-hide').prev().nextAll().remove(); + const single = { + title: item.title, + description: $('.entry').html(), + pubDate: item.pubDate, + link: item.link, + author: item['dc:creator'], + category: item.categories, + }; + return single; }) ) ); - ctx.state.data = { - title: $('title').text(), + title: '煎蛋', link: rootUrl, item: items, }; diff --git a/lib/v2/jandan/maintainer.js b/lib/v2/jandan/maintainer.js index 8dc696085e..33b455c436 100644 --- a/lib/v2/jandan/maintainer.js +++ b/lib/v2/jandan/maintainer.js @@ -1,4 +1,4 @@ module.exports = { '/:category?': ['nczitzk'], - '/': ['nczitzk'], + '/': ['nczitzk', 'bigfei'], };