mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 05:59:00 +08:00
* fix(route): change selector path, add radar and refactor to V2 * fix: use parse-date utils * fix: use https
66 lines
2.2 KiB
JavaScript
66 lines
2.2 KiB
JavaScript
const got = require('@/utils/got');
|
|
const cheerio = require('cheerio');
|
|
const { parseDate, parseRelativeDate } = require('@/utils/parse-date');
|
|
|
|
module.exports = async (ctx) => {
|
|
const category = ctx.params.category;
|
|
const url = `https://www.yystv.cn/b/${category}`;
|
|
const response = await got({
|
|
method: 'get',
|
|
url,
|
|
});
|
|
|
|
const data = response.data;
|
|
const $ = cheerio.load(data);
|
|
|
|
const first_part = $('.b-list-main-item')
|
|
.slice(0, 2)
|
|
.map(function () {
|
|
const info = {
|
|
title: $(this).find('.b-main-info-title').text(),
|
|
link: 'https://www.yystv.cn' + $(this).find('.b-main-info-title a').attr('href'),
|
|
pubDate: parseRelativeDate($(this).find('.b-main-createtime').text()),
|
|
author: $(this).find('.b-author').text(),
|
|
};
|
|
return info;
|
|
})
|
|
.get();
|
|
|
|
const second_part = $('.list-container li')
|
|
.slice(0, 18)
|
|
.map(function () {
|
|
const info = {
|
|
title: $('.list-article-title', this).text(),
|
|
link: 'https://www.yystv.cn' + $('a', this).attr('href'),
|
|
pubDate: $('.c-999', this).text().includes('-') ? parseDate($('.c-999', this).text()) : parseRelativeDate($('.c-999', this).text()),
|
|
author: $('.handler-author-link', this).text(),
|
|
};
|
|
return info;
|
|
})
|
|
.get();
|
|
|
|
const items = first_part.concat(second_part);
|
|
function getDescription(items) {
|
|
return Promise.all(
|
|
items.map(async (currentValue) => {
|
|
currentValue.description = await ctx.cache.tryGet(currentValue.link, async () => {
|
|
const r = await got({
|
|
url: currentValue.link,
|
|
method: 'get',
|
|
});
|
|
const $ = cheerio.load(r.data);
|
|
return $('.doc-content.rel').html();
|
|
});
|
|
return currentValue;
|
|
})
|
|
);
|
|
}
|
|
await getDescription(items).then(() => {
|
|
ctx.state.data = {
|
|
title: '游研社-' + $('title').text(),
|
|
link: `https://www.yystv.cn/b/${category}`,
|
|
item: items,
|
|
};
|
|
});
|
|
};
|