Skip to content

Commit

Permalink
fix(route): 北京价格价格日报 (DIYgod#17270)
Browse files Browse the repository at this point in the history
* fix(route): 北京价格价格日报

* fix(route): 北京价格价格日报
  • Loading branch information
nczitzk authored Oct 23, 2024
1 parent a3454ed commit 44ce93e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lib/routes/beijingprice/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 44ce93e

Please sign in to comment.