diff --git a/lib/routes/chinacdc/index.ts b/lib/routes/chinacdc/index.ts index f3c0222a2d665c..79e18d37a09279 100644 --- a/lib/routes/chinacdc/index.ts +++ b/lib/routes/chinacdc/index.ts @@ -31,9 +31,20 @@ export const handler = async (ctx: Context): Promise => { const $item: Cheerio = $(item); const aEl: Cheerio = $item.find('a'); - const title: string = aEl.prop('title') === undefined ? aEl.text() : aEl.prop('title'); + const dateMatch = title.match(/(\d{4}-\d{2}-\d{2})$/); + let pubDate; + let cleanTitle = title; + + if (dateMatch) { + pubDate = parseDate(dateMatch[0]); + cleanTitle = title.replace(/\d{4}-\d{2}-\d{2}$/, '').trim(); + } else { + const spanText = $item.find('span').text().trim(); + pubDate = spanText ? parseDate(spanText) : undefined; + } + const description: string = art(path.join(__dirname, 'templates/description.art'), { intro: $item.find('p.zy').text(), }); @@ -48,9 +59,9 @@ export const handler = async (ctx: Context): Promise => { } return { - title, + title: cleanTitle, description, - pubDate: parseDate($item.find('span').text()), + pubDate, link: new URL(aEl.prop('href') as string, targetUrl).href, content: { html: description, @@ -79,11 +90,14 @@ export const handler = async (ctx: Context): Promise => { description: $$('div.TRS_Editor').html(), }); + const detailDate = $$('span.fb em').text().trim(); + const pubDate = detailDate ? parseDate(detailDate) : item.pubDate; + return { title: detailTitle || item.title, // Use original title as fallback description, link: item.link, - pubDate: parseDate($$('span.fb em').text()), + pubDate, content: { html: description, text: $$('div.TRS_Editor').text(),