Fetch data from separate GitHub Pages instead of bundling

- Add NEXT_PUBLIC_DATA_URL env var pointing to entdb-data Pages
- Refactor env.ts: dataURL, withBase (cleaner naming)
- Remove data download step from build workflow
This commit is contained in:
cc
2026-04-15 17:10:29 +02:00
parent bb72bd3f57
commit 53aeb562b7
8 changed files with 21 additions and 48 deletions
+2 -2
View File
@@ -15,7 +15,7 @@ import { CopyButton } from "@/components/copy-button";
import { DownloadButton } from "@/components/download-button";
import { DiffViewer } from "@/components/diff-viewer";
import { addBasePath } from "@/lib/env";
import { withBase } from "@/lib/env";
import { createEngine } from "@/lib/engine";
import type { PathHistory } from "@/lib/engine/types";
import { normalizePlist } from "@/lib/plist";
@@ -291,7 +291,7 @@ export default function BinaryDetail() {
],
properties: {
className: ["text-blue-600", "dark:text-blue-300", "hover:underline"],
href: addBasePath(
href: withBase(
`/os/find?key=${encodeURIComponent(
node.value as string,
)}&os=${encodeURIComponent(os!)}`,
+2 -2
View File
@@ -12,7 +12,7 @@ import {
} from "@/components/ui/breadcrumb";
import { VersionSwitcher } from "@/components/version-switcher";
import { addBasePath } from "@/lib/env";
import { withBase } from "@/lib/env";
import { useEffect } from "react";
import { usePathname } from "next/navigation";
@@ -46,7 +46,7 @@ export default function OSDetailLayout({
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbLink href={addBasePath("/")}>Home</BreadcrumbLink>
<BreadcrumbLink href={withBase("/")}>Home</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem>
+2 -2
View File
@@ -1,6 +1,6 @@
"use client";
import { addBasePath } from "@/lib/env";
import { withBase } from "@/lib/env";
import { useSearchParams, redirect } from "next/navigation";
export default function OSDetail() {
@@ -11,5 +11,5 @@ export default function OSDetail() {
return <div className="p-8">Invalid OS</div>;
}
redirect(addBasePath(`/os/keys?os=${os}`));
redirect(withBase(`/os/keys?os=${os}`));
}
+3 -3
View File
@@ -4,7 +4,7 @@ import Link from "next/link";
import { useEffect, useState, useMemo } from "react";
import { Group, OS } from "@/lib/types";
import { addBasePath } from "@/lib/env";
import { withBase, dataURL } from "@/lib/env";
import { Skeleton } from "./ui/skeleton";
function responseOK(r: Response) {
@@ -108,14 +108,14 @@ export default function OSList() {
useEffect(() => {
setLoading(true);
fetch(addBasePath("/data/groups.json"))
fetch(`${dataURL}/groups.json`)
.then(responseOK)
.then((r) => r.json() as Promise<string[]>)
.then(async (groupList: string[]) =>
Promise.all(
groupList.map(async (group) => {
const response = await fetch(
addBasePath(`/data/${group}/list.json`),
`${dataURL}/${group}/list.json`,
).then(responseOK);
const data = await response.json();
+2 -2
View File
@@ -12,7 +12,7 @@ import { Input } from "@/components/ui/input";
import { ChevronDown, Check } from "lucide-react";
import type { OS } from "@/lib/types";
import { addBasePath, basePath } from "@/lib/env";
import { withBase, basePath, dataURL } from "@/lib/env";
function compareVersion(a: string, b: string) {
const l1 = a.split(".").map(Number);
@@ -42,7 +42,7 @@ export function VersionSwitcher({ currentOs }: { currentOs: string }) {
useEffect(() => {
if (!group) return;
fetch(addBasePath(`/data/${group}/list.json`))
fetch(`${dataURL}/${group}/list.json`)
.then((r) => r.json())
.then((list: OS[]) => {
list.sort((a, b) => compareVersion(a.version, b.version));
+2 -2
View File
@@ -1,6 +1,6 @@
import type { Engine, PathHistory } from "./types";
import type { OS } from "@/lib/types";
import { dataBaseURL } from "@/lib/env";
import { dataURL } from "@/lib/env";
import { fetchText, fetchLines } from "@/lib/client";
interface KVRecord {
@@ -55,7 +55,7 @@ export class KVEngine implements Engine {
#baseURL: string;
constructor(group: string) {
this.#baseURL = `${dataBaseURL()}/${group}`;
this.#baseURL = `${dataURL}/${group}`;
}
async listOS(): Promise<OS[]> {
+3 -9
View File
@@ -1,11 +1,5 @@
export const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
export const dataURL = process.env.NEXT_PUBLIC_DATA_URL || `${basePath}/data`;
export function addBasePath(path: string) {
let prefixed = path;
if (!prefixed.startsWith("/")) prefixed = `/${prefixed}`;
return basePath + prefixed;
}
export function dataBaseURL(): string {
return addBasePath("/data");
}
export const withBase = (path: string) =>
basePath + (path.startsWith("/") ? path : `/${path}`);