@yysng/astro-boilerplate 1.1.26 → 1.1.27
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yysng/astro-boilerplate",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.27",
|
|
4
4
|
"description": "Astro + Sanity Boilerplate with AEO Layers 1–5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -19,5 +19,8 @@
|
|
|
19
19
|
"@portabletext/to-html": "^4.0.1",
|
|
20
20
|
"astro": "^5.0.0",
|
|
21
21
|
"sanity": "^4.0.0"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@yysng/astro-boilerplate": "^1.1.26"
|
|
22
25
|
}
|
|
23
26
|
}
|
|
@@ -5,11 +5,13 @@ export async function loadContent(key, env = {}) {
|
|
|
5
5
|
const entry = CONTENT_REGISTRY[key];
|
|
6
6
|
if (!entry) throw new Error(`Unknown content key: ${key}`);
|
|
7
7
|
|
|
8
|
+
// Edge path — ONLY KV
|
|
8
9
|
if (env?.CONTENT_KV) {
|
|
9
10
|
const stored = await env.CONTENT_KV.get(entry.file, "json");
|
|
10
|
-
if (stored)
|
|
11
|
-
|
|
11
|
+
if (!stored) throw new Error(`Missing KV content: ${entry.file}`);
|
|
12
|
+
return stored;
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
// Local dev path — filesystem only
|
|
14
16
|
return await readLocal(entry.file);
|
|
15
17
|
}
|
|
@@ -1,20 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// storage.js
|
|
2
|
+
let fs = null;
|
|
3
|
+
let path = null;
|
|
4
|
+
|
|
5
|
+
// Lazy-load Node modules ONLY when in Node
|
|
6
|
+
async function ensureNode() {
|
|
7
|
+
if (fs && path) return;
|
|
8
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
9
|
+
fs = (await import("fs/promises")).default;
|
|
10
|
+
path = (await import("path")).default;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
4
13
|
|
|
5
14
|
export async function readLocal(file) {
|
|
6
|
-
|
|
7
|
-
if (!
|
|
15
|
+
await ensureNode();
|
|
16
|
+
if (!fs || !path) {
|
|
17
|
+
throw new Error("readLocal() called in non-Node environment");
|
|
18
|
+
}
|
|
8
19
|
|
|
20
|
+
const root = process.cwd() + "/src/content";
|
|
9
21
|
const filePath = path.join(root, file);
|
|
10
22
|
const raw = await fs.readFile(filePath, "utf-8");
|
|
11
23
|
return JSON.parse(raw);
|
|
12
24
|
}
|
|
13
25
|
|
|
14
26
|
export async function writeLocal(file, data) {
|
|
15
|
-
|
|
16
|
-
if (!
|
|
27
|
+
await ensureNode();
|
|
28
|
+
if (!fs || !path) {
|
|
29
|
+
throw new Error("writeLocal() called in non-Node environment");
|
|
30
|
+
}
|
|
17
31
|
|
|
32
|
+
const root = process.cwd() + "/src/content";
|
|
18
33
|
const filePath = path.join(root, file);
|
|
19
34
|
await fs.writeFile(filePath, JSON.stringify(data, null, 2), "utf-8");
|
|
20
35
|
}
|