Skip to content

Commit

Permalink
fix(chinacdc): format title and fix pubDate
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoyu committed Dec 31, 2024
1 parent 3f94723 commit 0ad07d2
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/routes/chinacdc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,20 @@ export const handler = async (ctx: Context): Promise<Data> => {
const $item: Cheerio<Element> = $(item);

const aEl: Cheerio<Element> = $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(),
});
Expand All @@ -48,9 +59,9 @@ export const handler = async (ctx: Context): Promise<Data> => {
}

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,
Expand Down Expand Up @@ -79,11 +90,14 @@ export const handler = async (ctx: Context): Promise<Data> => {
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(),
Expand Down

0 comments on commit 0ad07d2

Please sign in to comment.