Skip to content

Commit

Permalink
fix: caching issue?
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Mar 3, 2025
1 parent 3c97463 commit 511a555
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,7 @@ generated-assets
.idea/

.velite
sites/docs/static/registry
sites/docs/static/registry
sites/docs/src/lib/registry-json/**/*.json
sites/docs/src/lib/registry-json/**/*.css
sites/docs/static/themes.css
5 changes: 3 additions & 2 deletions sites/docs/scripts/build-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { transformContent } from "./transformers";
import prettier from "prettier";
import prettierPluginSvelte from "prettier-plugin-svelte";

const REGISTRY_PATH = path.resolve("static", "registry");
const REGISTRY_PATH = path.resolve("src", "lib", "registry-json");
const THEMES_CSS_PATH = path.resolve("static");
const REGISTRY_IGNORE = ["super-form"];

const prettierConfig: prettier.Config = {
Expand Down Expand Up @@ -369,7 +370,7 @@ export const Index = {
);
}

writeFileWithDirs(path.join(REGISTRY_PATH, `themes.css`), themeCSS.join("\n"), "utf-8");
writeFileWithDirs(path.join(THEMES_CSS_PATH, `themes.css`), themeCSS.join("\n"), "utf-8");

console.info("✅ Done!");
}
Expand Down
16 changes: 16 additions & 0 deletions sites/docs/src/__registry__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,14 @@ export const Index = {
files: ["../lib/registry/default/example/slider-multiple.svelte"],
raw: () => import("../lib/registry/default/example/slider-multiple.svelte?raw").then((m) => m.default),
},
"slider-vertical": {
name: "slider-vertical",
type: "registry:example",
registryDependencies: ["slider"],
component: () => import("../lib/registry/default/example/slider-vertical.svelte").then((m) => m.default),
files: ["../lib/registry/default/example/slider-vertical.svelte"],
raw: () => import("../lib/registry/default/example/slider-vertical.svelte?raw").then((m) => m.default),
},
"sonner-demo": {
name: "sonner-demo",
type: "registry:example",
Expand Down Expand Up @@ -1836,6 +1844,14 @@ export const Index = {
files: ["../lib/registry/new-york/example/slider-multiple.svelte"],
raw: () => import("../lib/registry/new-york/example/slider-multiple.svelte?raw").then((m) => m.default),
},
"slider-vertical": {
name: "slider-vertical",
type: "registry:example",
registryDependencies: ["slider"],
component: () => import("../lib/registry/new-york/example/slider-vertical.svelte").then((m) => m.default),
files: ["../lib/registry/new-york/example/slider-vertical.svelte"],
raw: () => import("../lib/registry/new-york/example/slider-vertical.svelte?raw").then((m) => m.default),
},
"sonner-demo": {
name: "sonner-demo",
type: "registry:example",
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion sites/docs/src/routes/(app)/colors/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<svelte:head>
<style>
@import "/registry/themes.css";
@import "/themes.css";
:root {
--vis-color0: var(--primary);
--vis-color1: #ffffff;
Expand Down
2 changes: 1 addition & 1 deletion sites/docs/src/routes/(app)/themes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<svelte:head>
<style>
@import "/registry/themes.css";
@import "/themes.css";
:root {
--vis-color0: var(--primary);
--vis-color1: #ffffff;
Expand Down
33 changes: 33 additions & 0 deletions sites/docs/src/routes/registry/[...path]/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { json } from "@sveltejs/kit";

export async function GET({ params }) {
const { path } = params;

try {
const jsonFiles = import.meta.glob("../../../lib/registry-json/**/*.json", { as: "raw" });
const cssFiles = import.meta.glob("../../../lib/registry-css/**/*.css", { as: "raw" });

// Merge all modules
const modules = { ...jsonFiles, ...cssFiles };

const modulePath = Object.keys(modules).find((m) => m.endsWith(`/${path}`));

if (!modulePath) {
throw new Error(`File not found: ${path}`);
}

// Import the matched module
const rawContent = await modules[modulePath]();

// Return raw JSON response
return new Response(rawContent, {
headers: {
"Content-Type": "application/json",
"Cache-Control": "no-store, max-age=0",
},
});
} catch (error) {
console.error(error);
return json({ error: "Resource not found" }, { status: 404 });
}
}

0 comments on commit 511a555

Please sign in to comment.