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