fix(route): 北京价格价格日报 (#17270)

* fix(route): 北京价格价格日报

* fix(route): 北京价格价格日报
This commit is contained in:
Ethan Shen 2024-10-23 21:49:52 +08:00 committed by GitHub
parent a3454ed515
commit 44ce93e15d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 3 deletions

View File

@ -26,19 +26,34 @@ export const handler = async (ctx) => {
const a = item.find('a');
const link = a.prop('href');
const msg = a.prop('msg');
const title = a.text()?.trim() ?? a.prop('title');
let enclosureUrl;
let enclosureType;
if (msg) {
const parsedMsg = JSON.parse(msg);
enclosureUrl = new URL(`${parsedMsg.path}${parsedMsg.fileName}`, rootUrl).href;
enclosureType = `application/${parsedMsg.suffix}`;
}
return {
title: a.text()?.trim() ?? a.prop('title'),
title,
pubDate: parseDate(item.contents().last().text()),
link: link.startsWith('http') ? link : new URL(link, rootUrl).href,
link: enclosureUrl ?? (link.startsWith('http') ? link : new URL(link, rootUrl).href),
language,
enclosure_url: enclosureUrl,
enclosure_type: enclosureType,
enclosure_title: enclosureUrl ? title : undefined,
};
});
items = await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
if (!item.link.includes('www.beijingprice.cn')) {
if (!item.link.includes('www.beijingprice.cn') || item.link.endsWith('.pdf')) {
return item;
}