Files
Odin Zhang c5741650d2 feat(route): add bookfere (#9501)
* feat(route): add bookfere

* style: auto format

* fix(route): change bookfere to v2

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-04-09 23:43:08 +08:00

37 lines
1.0 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const url = 'https://bookfere.com/category/' + ctx.params.category;
const response = await got({
method: 'get',
url,
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('main div div section');
ctx.state.data = {
title: $('head title').text(),
link: url,
item:
list &&
list
.map((index, item) => {
item = $(item);
const date = item.find('time').attr('datetime');
const pubDate = parseDate(date);
return {
title: item.find('h2 a').text(),
link: item.find('h2 a').attr('href'),
pubDate,
description: item.find('p').text(),
};
})
.get(),
};
};