@yysng/astro-boilerplate 1.1.25 → 1.1.26
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
|
@@ -2,9 +2,10 @@ let contentRoot = null;
|
|
|
2
2
|
|
|
3
3
|
export function setContentRoot(path) {
|
|
4
4
|
contentRoot = path;
|
|
5
|
-
globalThis.__CONTENT_ROOT__ = path;
|
|
6
5
|
}
|
|
7
6
|
|
|
8
7
|
export function getContentRoot() {
|
|
8
|
+
// When running on edge, we no longer require filesystem root.
|
|
9
|
+
// Loader will use import.meta.glob instead.
|
|
9
10
|
return contentRoot;
|
|
10
11
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { CONTENT_REGISTRY } from "./registry.js";
|
|
2
|
+
import { readLocal } from "./storage.js";
|
|
3
|
+
|
|
1
4
|
export async function loadContent(key, env = {}) {
|
|
2
5
|
const entry = CONTENT_REGISTRY[key];
|
|
3
6
|
if (!entry) throw new Error(`Unknown content key: ${key}`);
|
|
4
7
|
|
|
5
8
|
if (env?.CONTENT_KV) {
|
|
6
9
|
const stored = await env.CONTENT_KV.get(entry.file, "json");
|
|
7
|
-
if (
|
|
8
|
-
|
|
10
|
+
if (stored) return stored;
|
|
11
|
+
throw new Error(`KV missing content for ${entry.file}`);
|
|
9
12
|
}
|
|
10
13
|
|
|
11
|
-
// Only import storage on Node
|
|
12
|
-
const { readLocal } = await import("./storage.js");
|
|
13
14
|
return await readLocal(entry.file);
|
|
14
15
|
}
|
|
@@ -1,27 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
fs = await import("fs/promises");
|
|
5
|
-
path = await import("path");
|
|
6
|
-
}
|
|
1
|
+
import fs from "fs/promises";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { getContentRoot } from "./config.js";
|
|
7
4
|
|
|
8
5
|
export async function readLocal(file) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
6
|
+
const root = getContentRoot();
|
|
7
|
+
if (!root) throw new Error("Content root not configured");
|
|
12
8
|
|
|
13
|
-
const root = globalThis.__CONTENT_ROOT__;
|
|
14
9
|
const filePath = path.join(root, file);
|
|
15
10
|
const raw = await fs.readFile(filePath, "utf-8");
|
|
16
11
|
return JSON.parse(raw);
|
|
17
12
|
}
|
|
18
13
|
|
|
19
14
|
export async function writeLocal(file, data) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
15
|
+
const root = getContentRoot();
|
|
16
|
+
if (!root) throw new Error("Content root not configured");
|
|
23
17
|
|
|
24
|
-
const root = globalThis.__CONTENT_ROOT__;
|
|
25
18
|
const filePath = path.join(root, file);
|
|
26
19
|
await fs.writeFile(filePath, JSON.stringify(data, null, 2), "utf-8");
|
|
27
20
|
}
|