diff --git a/lib/v2/cnbeta/type.js b/lib/v2/cnbeta/type.js index 7d9ee8aff..383e13d9d 100644 --- a/lib/v2/cnbeta/type.js +++ b/lib/v2/cnbeta/type.js @@ -15,18 +15,24 @@ module.exports = async (ctx) => { const $ = cheerio.load(response.data); const token = encodeURI($('meta[name="csrf-token"]').attr('content')); - const apiUrl = `${rootUrl}/home/more?&type=${$('div[data-type]').attr('data-type')}&page=1&_csrf=${token}&_=${new Date().getTime()}`; + const apiUrl = `${rootUrl}/home/more?&type=${$('div[data-type]').data('type')}&page=1&_csrf=${token}&_=${Date.now()}`; response = await got(apiUrl); - const items = response.data.result.list.map((item) => ({ - title: item.title, - description: item.hometext, - author: item.source.split('@http')[0], - pubDate: timezone(parseDate(item.inputtime), +8), - link: item.url_show.startsWith('//') ? `https:${item.url_show}` : item.url_show.replace('http:', 'https:'), - category: item.label.name, - })); + const items = type + ? response.data.result.list.map((item) => ({ + title: item.title, + description: item.hometext, + author: item.source.split('@http')[0], + pubDate: timezone(parseDate(item.inputtime), +8), + link: item.url_show.startsWith('//') ? `https:${item.url_show}` : item.url_show.replace('http:', 'https:'), + category: item.label.name, + })) + : response.data.result.map((item) => ({ + title: item.title, + link: item.url_show.startsWith('//') ? `https:${item.url_show}` : item.url_show.replace('http:', 'https:'), + category: item.label.name, + })); ctx.state.data = { title: $('title').text(), diff --git a/lib/v2/cnbeta/utils.js b/lib/v2/cnbeta/utils.js index d6f566dc2..0242030a8 100644 --- a/lib/v2/cnbeta/utils.js +++ b/lib/v2/cnbeta/utils.js @@ -1,5 +1,7 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); const rootUrl = 'https://www.cnbeta.com.tw'; @@ -17,6 +19,7 @@ module.exports = { item.description = content('.article-summary').html() + content('.article-content').html(); item.author = content('header.title div.meta span.source').text(); + item.pubDate ??= timezone(parseDate(content('.meta span').first().text(), 'YYYY年MM月DD日 HH:mm'), +8); return item; })