Skip to content

Commit

Permalink
Parse URL before trying to find non-prod data (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiyundai authored Jan 10, 2025
1 parent bf113d0 commit e8cfc10
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion events/scripts/content-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,17 @@ export async function getNonProdData(env) {
const json = await resp.json();
let { pathname } = window.location;
if (pathname.endsWith('.html')) pathname = pathname.slice(0, -5);
const pageData = json.data.find((d) => d.url === pathname);
const pageData = json.data.find((d) => {
let pageUrl = '';

try {
pageUrl = new URL(d.url).pathname;
} catch (e) {
pageUrl = d.url;
}

return pageUrl === pathname;
});

if (pageData) return pageData;

Expand Down

0 comments on commit e8cfc10

Please sign in to comment.