@yysng/astro-boilerplate 1.1.16 โ 1.1.18
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,23 +1,15 @@
|
|
|
1
1
|
import { CONTENT_REGISTRY } from "./registry.js";
|
|
2
2
|
import { readLocal } from "./storage.js";
|
|
3
|
-
import { getContentRoot } from "./config.js";
|
|
4
3
|
|
|
5
4
|
export async function loadContent(key, env = {}) {
|
|
6
5
|
const entry = CONTENT_REGISTRY[key];
|
|
7
6
|
if (!entry) throw new Error(`Unknown content key: ${key}`);
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
if (env && env.CONTENT_KV) {
|
|
8
|
+
if (env?.CONTENT_KV) {
|
|
11
9
|
const stored = await env.CONTENT_KV.get(entry.file, "json");
|
|
12
10
|
if (stored) return stored;
|
|
13
|
-
throw new Error(`
|
|
11
|
+
throw new Error(`KV missing content for key "${key}" (file "${entry.file}")`);
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
const root = getContentRoot();
|
|
18
|
-
if (!root) {
|
|
19
|
-
throw new Error("Content root not configured in local environment");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return await readLocal(root, entry.file);
|
|
14
|
+
return await readLocal(entry.file);
|
|
23
15
|
}
|
|
@@ -2,19 +2,21 @@ import fs from "fs/promises";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { getContentRoot } from "./config.js";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
function assertRoot() {
|
|
6
|
+
const root = getContentRoot();
|
|
7
|
+
if (!root) throw new Error("Content root not configured in local environment");
|
|
8
|
+
return root;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function readLocal(file) {
|
|
12
|
+
const root = assertRoot();
|
|
9
13
|
const filePath = path.join(root, file);
|
|
10
14
|
const raw = await fs.readFile(filePath, "utf-8");
|
|
11
15
|
return JSON.parse(raw);
|
|
12
16
|
}
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*/
|
|
17
|
-
export async function writeLocal(root, file, data) {
|
|
18
|
+
export async function writeLocal(file, data) {
|
|
19
|
+
const root = assertRoot();
|
|
18
20
|
const filePath = path.join(root, file);
|
|
19
21
|
await fs.writeFile(filePath, JSON.stringify(data, null, 2), "utf-8");
|
|
20
22
|
}
|