fix(route/setn): fix incorrect timezone & title & author (#19778)
* fix(route/setn): fix incorrect timezone & title & author - timezone: Timezone error, 8-hour difference - title: Should use complete title from content, as current page title is only a short version - author: Fix data source extraction * refactor: remove IIFE in head JSON parsing * refactor: remove IIFE in head JSON parsing --------- Co-authored-by: Joe Wu <joecwu@tvbs.com.tw>
This commit is contained in:
parent
4102708f49
commit
6e689c4e0b
|
|
@ -2,6 +2,7 @@ import { Route } from '@/types';
|
|||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { load } from 'cheerio';
|
||||
import timezone from '@/utils/timezone';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
const defaultRootUrl = 'https://www.setn.com';
|
||||
|
|
@ -118,11 +119,19 @@ async function handler(ctx) {
|
|||
|
||||
const content = load(detailResponse.data);
|
||||
|
||||
let head = {};
|
||||
try {
|
||||
head = JSON.parse(content('script[type="application/ld+json"]').first().text());
|
||||
} catch {
|
||||
head = {};
|
||||
}
|
||||
|
||||
content('#gad_setn_innity_oop_1x1').remove();
|
||||
|
||||
item.author = content('meta[property="author"]').attr('content');
|
||||
item.title = content('h1').text();
|
||||
item.author = head?.author?.name || content('meta[name="author"]').attr('content');
|
||||
item.category = [content('meta[property="article:section"]').attr('content'), ...content('meta[name="news_keywords"]').attr('content').split(',')];
|
||||
item.pubDate = parseDate(content('meta[property="article:published_time"]').attr('content'));
|
||||
item.pubDate = timezone(parseDate(content('meta[property="article:published_time"]').attr('content')), +8);
|
||||
item.description = content('article, .content-p').html();
|
||||
|
||||
return item;
|
||||
|
|
|
|||
Loading…
Reference in New Issue