Files
RSSHub/lib/v2/8kcos/article.js
T
2024-02-28 16:25:59 +08:00

25 lines
733 B
JavaScript

import { load } from 'cheerio';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
async function loadArticle(link) {
const resp = await got(link);
const article = load(resp.body);
const entryChildren = article('div.entry-content').children();
const imgs = entryChildren
.find('noscript')
.toArray()
.map((e) => e.children[0].data);
const txt = entryChildren
.slice(2)
.toArray()
.map((e) => load(e).html());
return {
title: article('.entry-title').text(),
description: [...imgs, ...txt].join(''),
pubDate: parseDate(article('time')[0].attribs.datetime),
link,
};
}
module.exports = loadArticle;