RSSHub/lib/v2/medieval-china/post.js

45 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const baseUrl = 'https://medieval-china.club';
const { data: response } = await got(baseUrl);
const $ = cheerio.load(response);
const posts = JSON.parse(
$('script:contains("window.localPosts")')
.text()
.match(/window\.localPosts = JSON\.parse\('(.*)'\);/)[1]
)
.slice(0, ctx.query.limit ? Number.parseInt(ctx.query.limit) : 10)
.map((item) => ({
title: item.title,
link: `${baseUrl}${item.path}`,
pubDate: timezone(parseDate(item.date), +8),
}));
const items = await Promise.all(
posts.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);
const imgSrc = $('img').attr('data-original');
$('img').attr('src', `${baseUrl}${imgSrc}`);
$('.head-mask').remove();
$('div.lover-box').remove();
item.description = $('article').first().html();
return item;
})
)
);
ctx.state.data = {
title: '中国的中古',
link: baseUrl,
item: items,
image: 'https://medieval-china.club/images/icons/favicon-144x144.png',
description:
'世界那么大你无法去到每一个地方感受每一处风景时间那么长那些逝去的人你也终将无法与之谋面。而通过古人之文字今人之分享你可以领略以前风光之奇绝瑰玮感受逝人之人情冷暖。中古就是这么一个地方大家来自全球各地不同时区不同性别不同身份不同职业但是大家都被中古的绚烂华章聚集在一起哀其所哀乐其所乐。这是一个虚拟的世界但是我们仿佛跨越千里而来谈一场绝世爱恋今夕何夕仅以此网站献给中古club的每一位成员契阔谈宴西园不芜',
};
};