@@ -5,6 +5,7 @@ import { parseDate } from '@/utils/parse-date';
55import { renderToString } from 'hono/jsx/dom/server' ;
66import { base32 } from 'rfc4648' ;
77import Zaobao from './zaobao' ;
8+ import timezone from '@/utils/timezone' ;
89
910const baseUrl = 'https://www.zaobao.com' ;
1011export const logo = 'https://www.zaobao.com.sg/favicon.ico' ;
@@ -21,10 +22,10 @@ export const parseList = async (
2122 title : string ;
2223 resultList : {
2324 title : string ;
24- description : string ;
25+ description ? : string ;
2526 pubDate : Date ;
2627 link : string ;
27- category : string [ ] ;
28+ category ? : string [ ] ;
2829 } [ ] ;
2930} > => {
3031 const pageResponse = await ofetch . raw ( baseUrl + sectionUrl ) ;
@@ -36,15 +37,23 @@ export const parseList = async (
3637 }
3738 const origin = new URL ( pageResponse . url ) . origin ;
3839
39- const title = $ ( 'meta[property="og:title"]' ) . attr ( 'content' ) ;
40+ const title = $ ( 'meta[property="og:title"]' ) . attr ( 'content' ) as string ;
4041
4142 const resultList = await Promise . all (
4243 data . toArray ( ) . map ( ( item ) => {
4344 const $item = $ ( item ) ;
4445 const link = baseUrl + $item . attr ( 'href' ) ;
4546
4647 return cache . tryGet ( link , async ( ) => {
47- const response = await ofetch . raw ( origin + $item . attr ( 'href' ) ) ;
48+ if ( $item . attr ( 'href' ) ?. includes ( 'https://' ) ) {
49+ const isSingapore = pageResponse . url . startsWith ( 'https://www.zaobao.com.sg/' ) ;
50+ return {
51+ title : isSingapore ? $item . text ( ) . trim ( ) : ( $item . attr ( 'title' ) ?. trim ( ) as string ) ,
52+ link : $item . attr ( 'href' ) as string ,
53+ pubDate : timezone ( $item . next ( ) . text ( ) . trim ( ) . includes ( ':' ) ? parseDate ( $item . next ( ) . text ( ) . trim ( ) , 'HH:mm' ) : parseDate ( $item . next ( ) . text ( ) . trim ( ) , 'MM月DD日' ) , + 8 ) ,
54+ } ;
55+ }
56+ const response = await ofetch . raw ( new URL ( $item . attr ( 'href' ) as string , origin ) . href ) ;
4857 let $1 = load ( response . _data ) ;
4958
5059 let title , pubDate , category , images ;
0 commit comments