@yysng/astro-boilerplate 1.1.30 → 1.1.32
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,17 +1,17 @@
|
|
|
1
1
|
import { CONTENT_REGISTRY } from "./registry.js";
|
|
2
|
-
import { readLocal } from "
|
|
2
|
+
import { readLocal } from "@yysng/astro-boilerplate/content-storage";
|
|
3
3
|
|
|
4
4
|
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
|
-
//
|
|
8
|
+
// Edge → KV only
|
|
9
9
|
if (env?.CONTENT_KV) {
|
|
10
10
|
const stored = await env.CONTENT_KV.get(entry.file, "json");
|
|
11
|
-
if (stored)
|
|
12
|
-
|
|
11
|
+
if (!stored) throw new Error(`KV missing content for key "${key}"`);
|
|
12
|
+
return stored;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
//
|
|
16
|
-
return
|
|
15
|
+
// Node → filesystem only
|
|
16
|
+
return readLocal(entry.file, env);
|
|
17
17
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { readLocal, writeLocal } from "./storage.edge.js";
|
|
@@ -1,12 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
let impl;
|
|
4
|
-
|
|
5
|
-
if (isEdge) {
|
|
6
|
-
impl = await import("./storage.edge.js");
|
|
7
|
-
} else {
|
|
8
|
-
impl = await import("./storage.node.js");
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const readLocal = impl.readLocal;
|
|
12
|
-
export const writeLocal = impl.writeLocal;
|
|
1
|
+
export { readLocal, writeLocal } from "./storage.node.js";
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { schemas } from "./schemas.js";
|
|
2
2
|
import { loadContent } from "./loader.js";
|
|
3
|
-
import { writeLocal }
|
|
3
|
+
import { writeLocal }from "@yysng/astro-boilerplate/content-storage";
|
|
4
4
|
import { CONTENT_REGISTRY } from "./registry.js";
|
|
5
5
|
|
|
6
6
|
function mergeDefined(existing, incoming) {
|
|
7
7
|
const result = { ...existing };
|
|
8
|
-
for (const
|
|
9
|
-
const
|
|
10
|
-
if (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
result[key] = mergeDefined(existing[key] || {}, value);
|
|
8
|
+
for (const k in incoming) {
|
|
9
|
+
const v = incoming[k];
|
|
10
|
+
if (v === undefined) continue;
|
|
11
|
+
if (typeof v === "object" && v && !Array.isArray(v)) {
|
|
12
|
+
result[k] = mergeDefined(existing[k] || {}, v);
|
|
14
13
|
} else {
|
|
15
|
-
result[
|
|
14
|
+
result[k] = v;
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
17
|
return result;
|
|
@@ -33,6 +32,6 @@ export async function updateContent(key, incoming, env = {}) {
|
|
|
33
32
|
return merged;
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
await writeLocal(entry.file, merged);
|
|
35
|
+
await writeLocal(entry.file, merged, env);
|
|
37
36
|
return merged;
|
|
38
37
|
}
|