From e3f3ce8b22d4b8c36bfc8b88d23d5b069fffba24 Mon Sep 17 00:00:00 2001 From: cubroe Date: Tue, 2 May 2023 04:25:05 +0800 Subject: [PATCH] feat(route): enhance feed of freecomputerbooks.com with full-text support (#12414) --- lib/v2/freecomputerbooks/index.js | 54 ++++++++++++++++----- lib/v2/freecomputerbooks/templates/desc.art | 3 ++ 2 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 lib/v2/freecomputerbooks/templates/desc.art diff --git a/lib/v2/freecomputerbooks/index.js b/lib/v2/freecomputerbooks/index.js index e9c5668c9..2db484da2 100644 --- a/lib/v2/freecomputerbooks/index.js +++ b/lib/v2/freecomputerbooks/index.js @@ -1,16 +1,20 @@ 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 response = await got({ method: 'get', url: requestURL }); - const $ = cheerio.load(response.data); + 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. @@ -24,23 +28,22 @@ module.exports = async (ctx) => { // For a "Selected New Books" page, the