mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 23:00:48 +08:00
* Add nytimes/author route * Removed unnecessary logger and fs usage * refactor: migrate to v2
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
const got = require('@/utils/got');
|
|
const cheerio = require('cheerio');
|
|
|
|
module.exports = async (ctx) => {
|
|
const byline = ctx.params.byline;
|
|
|
|
const authorUrl = `https://www.nytimes.com/by/${byline}`;
|
|
|
|
const response = await got({
|
|
method: 'get',
|
|
url: authorUrl,
|
|
});
|
|
const data = response.data;
|
|
const $ = cheerio.load(data);
|
|
|
|
const authorName = $('h1').text();
|
|
|
|
const items = $('#stream-panel li')
|
|
.map((index, elem) => {
|
|
const $item = $(elem);
|
|
const $info = $item.find('div > div');
|
|
const title = $info.find('h2').text();
|
|
const href = $info.find('a').attr('href');
|
|
const link = new URL(href, authorUrl);
|
|
const description = $info.find('a > p').text();
|
|
const author = $info.find('a p > span').text();
|
|
|
|
return {
|
|
title,
|
|
author,
|
|
description,
|
|
link,
|
|
};
|
|
})
|
|
.get()
|
|
.filter((d) => d.title);
|
|
|
|
ctx.state.data = {
|
|
title: `${authorName} - The New York Times`,
|
|
link: authorUrl,
|
|
item: items,
|
|
};
|
|
};
|