Files
RSSHub/lib/v2/zhubai/index.js
T
Ryan Yuanandnaixy28 b6229bf987 feat(route): add 竹白blog (#9032)
* Feat: add route for 竹白

* Tweak: change to v2

* Fix: 1. use parseDate 2. update doc 3. support limit query

* Fix: 1. ensure limit is number 2. chore  doc

* Fix: use nullish coalescing

* Fix: revert nullish coalescing for not passing DeepScan check

* Fix

* Chore(doc)

Co-authored-by: naixy28 <yuanyang@iftech.io>
2022-02-15 03:13:05 -08:00

30 lines
912 B
JavaScript

const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const { id } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 20;
const response = await got({
method: 'get',
url: `https://${id}.zhubai.love/api/publications/${id}/posts?publication_id_type=token&limit=${limit}`,
headers: {
Referer: `https://${id}.zhubai.love/`,
},
});
const data = response.data.data;
const { name, description } = data[0].publication;
ctx.state.data = {
title: name,
link: `https://${id}.zhubai.love/`,
description,
item: data.map((item) => ({
title: item.title,
pubDate: parseDate(item.created_at),
link: `https://${id}.zhubai.love/posts/${item.id}`,
author: name,
})),
};
};