From 8b0ded1f84b89a5c52969db7d9c2958c83c2a7a8 Mon Sep 17 00:00:00 2001 From: Cloud Date: Mon, 24 Jun 2019 22:40:22 +0800 Subject: [PATCH] fix: zzz.vip 404 (#2477) * fix: zzz.vip 404 * fix: zzz add author and pubDate --- lib/routes/zzz/index.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/routes/zzz/index.js b/lib/routes/zzz/index.js index 189efe101..375744456 100644 --- a/lib/routes/zzz/index.js +++ b/lib/routes/zzz/index.js @@ -1,9 +1,10 @@ const got = require('@/utils/got'); -const parser = require('@/utils/rss-parser'); const cheerio = require('cheerio'); module.exports = async (ctx) => { - const feed = await parser.parseURL('https://z-z-z.vip/feed'); + const response = await got.get('https://z-z-z.vip'); + const $ = cheerio.load(response.data); + const list = $('.media-list .az-article-wrapper').get(); const ProcessFeed = (data) => { const $ = cheerio.load(data); @@ -18,20 +19,33 @@ module.exports = async (ctx) => { }; const items = await Promise.all( - feed.items.map(async (item) => { + list.map(async (item) => { + const $ = cheerio.load(item); + const $a = $('.media-heading a'); + const link = $a.attr('href'); + + const cache = await ctx.cache.get(link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + const response = await got({ method: 'get', - url: item.link, + url: link, }); const single = { - guid: item.guid, - title: item.title, + title: $a.text(), description: ProcessFeed(response.data), - pubDate: item.pubDate, - link: item.link, - author: item['dc:creator'], + link: link, + pubDate: $('.glyphicon-calendar') + .toArray()[0] + .nextSibling.data.replace(/年|月/g, '-') + .replace('日', ''), + author: $('.glyphicon-user').toArray()[0].nextSibling.data, }; + + ctx.cache.set(link, JSON.stringify(single)); return Promise.resolve(single); }) );