Skip to content

Commit

Permalink
fix(route): cnbeta (#13714)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored Nov 7, 2023
1 parent b1f2be6 commit 125c24e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/v2/cnbeta/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/cnbeta/utils.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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;
})
Expand Down

0 comments on commit 125c24e

Please sign in to comment.