mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 23:00:48 +08:00
31 lines
982 B
JavaScript
31 lines
982 B
JavaScript
const cheerio = require('cheerio');
|
|
const axios = require('@/utils/axios');
|
|
|
|
module.exports = async (ctx) => {
|
|
const url = `http://${ctx.params.url}`;
|
|
const res = await axios.get(url);
|
|
const $ = cheerio.load(res.data);
|
|
const authorInfo = $('.left-col').find('#header');
|
|
const title = authorInfo.find('.header-author').text();
|
|
const subtitle = authorInfo.find('.header-subtitle').text();
|
|
const articleNodeList = $('article');
|
|
const articles = Array.from(articleNodeList).map((article) => {
|
|
const each = $(article);
|
|
const titleEl = each.find('.article-title');
|
|
|
|
return {
|
|
title: titleEl.text(),
|
|
link: encodeURI(`${url}${titleEl.attr('href')}`),
|
|
description: each.find('.article-entry').text(),
|
|
pubDate: each.find('time').attr('datetime'),
|
|
};
|
|
});
|
|
|
|
ctx.state.data = {
|
|
title,
|
|
link: url,
|
|
description: subtitle,
|
|
item: articles,
|
|
};
|
|
};
|