Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/routes/contact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
];
};

Expand Down
2 changes: 1 addition & 1 deletion src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
];
};

Expand Down
2 changes: 1 addition & 1 deletion src/routes/project-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
];
};

Expand Down
2 changes: 1 addition & 1 deletion src/routes/projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
];
};

Expand Down
66 changes: 35 additions & 31 deletions src/utils/fetchGithubData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,43 +113,47 @@ async function getPackageJsonLicenseFromMaster(
repo: string,
): Promise<string | undefined> {
// 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<string, unknown>)
) {
const lic = (pkg as Record<string, unknown>).license;
if (typeof lic === 'string') return lic;
const raw = await fetchText(
`https://raw.githubusercontent.com/${owner}/${repo}/${branch}/package.json`,
);
Comment on lines +119 to +123
Copy link

Copilot AI Oct 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loop will continue attempting to fetch from 'main' even after successfully retrieving and parsing a license from 'master'. Consider adding an early return after successfully finding a valid license to avoid unnecessary network requests.

Copilot uses AI. Check for mistakes.
try {
const pkg = JSON.parse(raw) as unknown;
if (
lic &&
typeof lic === 'object' &&
'type' in (lic as Record<string, unknown>) &&
typeof (lic as Record<string, unknown>).type === 'string'
)
return (lic as Record<string, unknown>).type as string;
}
// Support legacy `licenses` array
if (pkg && typeof pkg === 'object') {
const anyPkg = pkg as Record<string, unknown>;
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<string, unknown>)
) {
const lic = (pkg as Record<string, unknown>).license;
if (typeof lic === 'string') return lic;
if (
lic &&
typeof lic === 'object' &&
'type' in (lic as Record<string, unknown>)
) {
const typeVal = (lic as Record<string, unknown>).type;
if (typeof typeVal === 'string') return typeVal;
}
}
// Support legacy `licenses` array
if (pkg && typeof pkg === 'object') {
const anyPkg = pkg as Record<string, unknown>;
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;
}
Expand Down