fix(route): bbc incorrect section in title (#15502)

* fix: incorrect section in title

* fix: remove String()
This commit is contained in:
Henry Wang
2024-05-08 00:11:58 +08:00
committed by GitHub
parent c0ded03df4
commit 5e2cbc1ee7
+16 -8
View File
@@ -65,18 +65,26 @@ async function handler(ctx) {
const $ = load(response);
const description = new URL(item.link).pathname.startsWith('/news/av') ? item.content : utils.ProcessFeed($);
const path = new URL(item.link).pathname;
let section = 'sport';
const urlSplit = item.link.split('/');
const sectionSplit = urlSplit.at(-1).split('-');
if (sectionSplit.length > 1) {
section = sectionSplit[0];
let description;
switch (true) {
case path.startsWith('/sport'):
description = item.content;
break;
case path.startsWith('/sounds/play'):
description = item.content;
break;
case path.startsWith('/news/live'):
description = item.content;
break;
default:
description = utils.ProcessFeed($);
}
section = section[0].toUpperCase() + section.slice(1);
return {
title: `[${section}] ${item.title}`,
title: item.title,
description,
pubDate: item.pubDate,
link: item.link,