fix(route): jandan 煎蛋 parseDate bug (#10950)
* Fix jandan item parseDate error * change main
This commit is contained in:
parent
cc738eab26
commit
25ede3fb80
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = {
|
||||
'/:category?': ['nczitzk'],
|
||||
'/': ['nczitzk'],
|
||||
'/': ['nczitzk', 'bigfei'],
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue