feat: harden portfolio and add SEO foundations
This commit is contained in:
1 parent
b079afdd73
commit
62bcfbd8fa
121 files changed
+7769
-10469
No files matched your search
+17
-39
@@ -14,45 +14,19 @@ export interface ProjectHealthSnapshot {
|
||||
projects: Record<string, ProjectHealthCheck>;
|
||||
}
|
||||
|
||||
interface ProjectLike {
|
||||
id: string;
|
||||
featured?: boolean;
|
||||
}
|
||||
export type DemoAvailability = "available" | "unavailable" | "unknown" | "none";
|
||||
|
||||
function isFresh(checkedAt: string, now: Date) {
|
||||
const timestamp = Date.parse(checkedAt);
|
||||
return (
|
||||
Number.isFinite(timestamp) &&
|
||||
now.getTime() - timestamp <= PROJECT_HEALTH_MAX_AGE_MS
|
||||
);
|
||||
}
|
||||
|
||||
export function isCurrentLiveCheck(
|
||||
export function getDemoAvailability(
|
||||
demoUrl: string | null | undefined,
|
||||
check: ProjectHealthCheck | undefined,
|
||||
now = new Date(),
|
||||
) {
|
||||
return Boolean(
|
||||
check &&
|
||||
check.status === 200 &&
|
||||
check.contentType?.toLowerCase().startsWith("text/html") &&
|
||||
isFresh(check.checkedAt, now),
|
||||
);
|
||||
}
|
||||
|
||||
export function filterLiveProjects<T extends ProjectLike>(
|
||||
projects: T[],
|
||||
snapshot: ProjectHealthSnapshot | null,
|
||||
now = new Date(),
|
||||
) {
|
||||
if (!snapshot || !isFresh(snapshot.checkedAt, now)) {
|
||||
return [] as T[];
|
||||
}
|
||||
|
||||
return projects.filter(
|
||||
(project) =>
|
||||
project.featured !== false &&
|
||||
isCurrentLiveCheck(snapshot.projects[project.id], now),
|
||||
);
|
||||
): DemoAvailability {
|
||||
if (!demoUrl) return "none";
|
||||
if (!check) return "unknown";
|
||||
if (check.error || check.status === null) return "unknown";
|
||||
return check.status === 200 &&
|
||||
check.contentType?.split(";", 1)[0].trim().toLowerCase() === "text/html"
|
||||
? "available"
|
||||
: "unavailable";
|
||||
}
|
||||
|
||||
interface ProjectDemo {
|
||||
@@ -67,7 +41,10 @@ interface HealthResponse {
|
||||
body?: { cancel?: () => unknown } | null;
|
||||
}
|
||||
|
||||
type HealthFetcher = (url: string, init: RequestInit) => Promise<HealthResponse>;
|
||||
type HealthFetcher = (
|
||||
url: string,
|
||||
init: RequestInit,
|
||||
) => Promise<HealthResponse>;
|
||||
|
||||
export async function createProjectHealthSnapshot(
|
||||
projects: ProjectDemo[],
|
||||
@@ -101,7 +78,8 @@ export async function createProjectHealthSnapshot(
|
||||
status: null,
|
||||
contentType: null,
|
||||
checkedAt,
|
||||
error: error instanceof Error ? error.message : "Health check failed",
|
||||
error:
|
||||
error instanceof Error ? error.message : "Health check failed",
|
||||
},
|
||||
] as const;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user