From 53d0e741c46e6081367ba9d9c7bf929393e56b77 Mon Sep 17 00:00:00 2001 From: Tenemo Date: Sat, 18 Oct 2025 11:36:22 +0200 Subject: [PATCH 1/2] main branch fallback if master doesn't exist --- src/utils/fetchGithubData.ts | 66 +++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/src/utils/fetchGithubData.ts b/src/utils/fetchGithubData.ts index 10796f4..09d2713 100644 --- a/src/utils/fetchGithubData.ts +++ b/src/utils/fetchGithubData.ts @@ -113,43 +113,47 @@ async function getPackageJsonLicenseFromMaster( repo: string, ): Promise { // Spec: license from package.json on master HEAD commit, if present. - // We intentionally only check the 'master' branch as requested, - // and do not fallback to 'main' here. - try { - const raw = await fetchText( - `https://raw.githubusercontent.com/${owner}/${repo}/master/package.json`, - ); + // Fallback: if 'master' isn't available, try 'main'. + const candidateBranches = ['master', 'main'] as const; + + for (const branch of candidateBranches) { try { - const pkg = JSON.parse(raw) as unknown; - if ( - pkg && - typeof pkg === 'object' && - 'license' in (pkg as Record) - ) { - const lic = (pkg as Record).license; - if (typeof lic === 'string') return lic; + const raw = await fetchText( + `https://raw.githubusercontent.com/${owner}/${repo}/${branch}/package.json`, + ); + try { + const pkg = JSON.parse(raw) as unknown; if ( - lic && - typeof lic === 'object' && - 'type' in (lic as Record) && - typeof (lic as Record).type === 'string' - ) - return (lic as Record).type as string; - } - // Support legacy `licenses` array - if (pkg && typeof pkg === 'object') { - const anyPkg = pkg as Record; - const licensesRaw = anyPkg.licenses; - if (Array.isArray(licensesRaw) && licensesRaw.length > 0) { - const first = licensesRaw[0] as { type?: unknown }; - if (typeof first.type === 'string') return first.type; + pkg && + typeof pkg === 'object' && + 'license' in (pkg as Record) + ) { + const lic = (pkg as Record).license; + if (typeof lic === 'string') return lic; + if ( + lic && + typeof lic === 'object' && + 'type' in (lic as Record) + ) { + const typeVal = (lic as Record).type; + if (typeof typeVal === 'string') return typeVal; + } + } + // Support legacy `licenses` array + if (pkg && typeof pkg === 'object') { + const anyPkg = pkg as Record; + const licensesRaw = anyPkg.licenses; + if (Array.isArray(licensesRaw) && licensesRaw.length > 0) { + const first = licensesRaw[0] as { type?: unknown }; + if (typeof first.type === 'string') return first.type; + } } + } catch { + // ignore JSON parsing errors and try next branch } } catch { - // ignore JSON parsing errors and fall through + // package.json not found or inaccessible on this branch; try next } - } catch { - // master/package.json not found or inaccessible } return undefined; } From 30eb263a2ccf45ee1922049ad6d400dac2a3d424 Mon Sep 17 00:00:00 2001 From: Tenemo Date: Sat, 18 Oct 2025 11:47:09 +0200 Subject: [PATCH 2/2] graphs not getting stringified twice --- src/routes/contact.tsx | 2 +- src/routes/index.tsx | 2 +- src/routes/project-item.tsx | 2 +- src/routes/projects.tsx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/routes/contact.tsx b/src/routes/contact.tsx index 1408057..6de5f86 100644 --- a/src/routes/contact.tsx +++ b/src/routes/contact.tsx @@ -104,7 +104,7 @@ export const meta: MetaFunction = () => { rel: 'canonical', href: 'https://piech.dev/contact/', }, - { 'script:ld+json': JSON.stringify(graph) }, + { 'script:ld+json': graph }, ]; }; diff --git a/src/routes/index.tsx b/src/routes/index.tsx index 9482419..d8c3454 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -194,7 +194,7 @@ export const meta: MetaFunction = () => { content: 'Portrait photo of Piotr Piech.', }, { tagName: 'link', rel: 'canonical', href: 'https://piech.dev/' }, - { 'script:ld+json': JSON.stringify(graph) }, + { 'script:ld+json': graph }, ]; }; diff --git a/src/routes/project-item.tsx b/src/routes/project-item.tsx index b291fa2..a06b89e 100644 --- a/src/routes/project-item.tsx +++ b/src/routes/project-item.tsx @@ -155,7 +155,7 @@ export const meta: MetaFunction = (args) => { rel: 'canonical', href: `https://piech.dev/projects/${repo}`, }, - { 'script:ld+json': JSON.stringify(graph) }, + { 'script:ld+json': graph }, ]; }; diff --git a/src/routes/projects.tsx b/src/routes/projects.tsx index ccb8ea3..81e95e2 100644 --- a/src/routes/projects.tsx +++ b/src/routes/projects.tsx @@ -139,7 +139,7 @@ export const meta: MetaFunction = () => { rel: 'canonical', href: 'https://piech.dev/projects/', }, - { 'script:ld+json': JSON.stringify(graph) }, + { 'script:ld+json': graph }, ]; };