mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
refactor: improve readability for jinshi/index.js (#6062)
This commit is contained in:
+22
-18
@@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user