@yysng/astro-boilerplate 1.1.14 → 1.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import { CONTENT_REGISTRY } from "./registry.js";
|
|
2
2
|
import { readLocal } from "./storage.js";
|
|
3
3
|
|
|
4
|
+
// Edge-safe bundled content (used when no filesystem)
|
|
5
|
+
const edgeContent = import.meta.glob("/src/content/*.json", { eager: true });
|
|
6
|
+
|
|
4
7
|
export async function loadContent(key, env = {}) {
|
|
5
8
|
const entry = CONTENT_REGISTRY[key];
|
|
6
9
|
if (!entry) throw new Error(`Unknown content key: ${key}`);
|
|
7
10
|
|
|
8
|
-
// Cloudflare production
|
|
11
|
+
// 1️⃣ Cloudflare production: KV first
|
|
9
12
|
if (env.CONTENT_KV) {
|
|
10
13
|
const stored = await env.CONTENT_KV.get(entry.file, "json");
|
|
11
14
|
if (stored) return stored;
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
//
|
|
15
|
-
|
|
17
|
+
// 2️⃣ Edge runtime fallback (no filesystem available)
|
|
18
|
+
if (!env.CONTENT_ROOT) {
|
|
19
|
+
const mod = edgeContent[`/src/content/${entry.file}`];
|
|
20
|
+
if (!mod || !mod.default) {
|
|
21
|
+
throw new Error(`Edge content not found: ${entry.file}`);
|
|
22
|
+
}
|
|
23
|
+
return mod.default;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 3️⃣ Local Node development (filesystem)
|
|
27
|
+
return await readLocal(env.CONTENT_ROOT, entry.file);
|
|
16
28
|
}
|
|
@@ -2,13 +2,19 @@ import fs from "fs/promises";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { getContentRoot } from "./config.js";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Local filesystem read (Node only)
|
|
7
|
+
*/
|
|
8
|
+
export async function readLocal(root, file) {
|
|
9
|
+
const filePath = path.join(root, file);
|
|
7
10
|
const raw = await fs.readFile(filePath, "utf-8");
|
|
8
11
|
return JSON.parse(raw);
|
|
9
12
|
}
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Local filesystem write (Node only)
|
|
16
|
+
*/
|
|
17
|
+
export async function writeLocal(root, file, data) {
|
|
18
|
+
const filePath = path.join(root, file);
|
|
13
19
|
await fs.writeFile(filePath, JSON.stringify(data, null, 2), "utf-8");
|
|
14
20
|
}
|