const cheerio = require('cheerio'); const path = require('path'); const got = require('@/utils/got'); const { art } = require('@/utils/render'); const { parseDate } = require('@/utils/parse-date'); const baseURL = 'https://freecomputerbooks.com/'; async function cheerioLoad(url) { return cheerio.load((await got(url)).data); } module.exports = async (ctx) => { const categoryId = ctx.params.category?.trim(); const requestURL = categoryId ? new URL(`${categoryId}.html`, baseURL).href : baseURL; const $ = await cheerioLoad(requestURL); // As observation has shown that each page only has one element of the // class, thus to simplify the processing the text is directly extracted. // Needing more robust processing if some day more such elements show up. const categoryTitle = $('.maintitlebar').text(); ctx.state.data = { title: 'Free Computer Books - ' + categoryTitle, link: requestURL, description: $('title').text(), // For a "Selected New Books" page, the