Files
RSSHub/lib/v2/freebuf/index.js
Trganda 12f45a7844 feat(route): add Freebuf 文章订阅路由 (#12392)
* freebuf route

* accpet recommendataion

* add blank line

* query freebuf with api

* remove unused `id` args and retouch the rss link

* delete String() on variable `type`
2023-04-30 12:05:47 -06:00

42 lines
1.2 KiB
JavaScript

const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const { type = 'web' } = ctx.params;
const fapi = 'https://www.freebuf.com/fapi/frontend/category/list';
const baseUrl = 'https://www.freebuf.com';
const rssLink = `${baseUrl}/articles/${type}`;
const options = {
headers: {
referer: 'https://www.freebuf.com',
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
},
searchParams: {
name: type,
page: 1,
limit: 20,
select: 0,
order: 0,
type: 'category',
},
};
const response = await got.get(fapi, options).json();
const items = response.data.data_list.map((item) => ({
title: item.post_title,
link: `${baseUrl}${item.url}`,
description: item.content,
pubDate: parseDate(item.post_date),
author: item.nickname,
}));
ctx.state.data = {
title: `Freebuf ${type}`,
link: rssLink,
item: items,
};
};