refactor: improve readability for jinshi/index.js (#6062)

This commit is contained in:
Laam Pui
2020-11-02 11:00:10 +00:00
committed by GitHub
parent f08a84b55e
commit 14cef9f738
+22 -18
View File
@@ -4,28 +4,32 @@ const cheerio = require('cheerio');
module.exports = async (ctx) => {
const response = await got.get('https://www.jin10.com/');
const $ = cheerio.load(response.data);
const item = [];
let month_day;
let date;
$('#jin_flash_list .jin-flash-item-container').each((index, ele) => {
const year = new Date().getFullYear();
const new_month_day = $('.jin-flash-date-line span', ele).text().trim();
new_month_day && (month_day = new_month_day);
const month = month_day.match(/\d+/g)[0];
const day = month_day.match(/\d+/g)[1];
const time = $('.item-time', ele).text();
const date = new Date(`${year}-${month}-${day} ${time}`);
const item = $('#jin_flash_list .jin-flash-item-container')
.filter((index, ele) => !!$('.right-content div:first-of-type', ele).text() && !$('.is-vip', ele).length)
.map((index, ele) => {
const year = new Date().getFullYear();
const time = $('.item-time', ele).text();
const title = $('.right-content div:first-of-type', ele).text();
const link = $('.right-content .flash-item-share_right a', ele).attr('href');
date = $('.jin-flash-date-line span', ele).text().trim() ? $('.jin-flash-date-line span', ele).text().trim() : date;
const datetime = year + '-' + date.replace('月', '-').replace('日', ` ${time}`);
return {
title,
link,
description: datetime,
pubDate: new Date(datetime),
};
})
.get();
item.push({
title: $('.right-content div:first-of-type', ele).text(),
link: $('.right-content .flash-item-share_right a', ele).attr('href'),
description: `${year}-${month}-${day} ${time}`,
pubDate: date.toUTCString(),
});
});
ctx.state.data = {
title: '金十数据',
link: 'https://www.jin10.com/',
item: item,
item,
};
};