@yysng/astro-boilerplate 1.1.26 → 1.1.28

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.26",
3
+ "version": "1.1.28",
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) return stored;
11
- throw new Error(`KV missing content for ${entry.file}`);
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
  }
@@ -0,0 +1,7 @@
1
+ export async function readLocal() {
2
+ throw new Error("Local filesystem is not available in Edge runtime");
3
+ }
4
+
5
+ export async function writeLocal() {
6
+ throw new Error("Local filesystem is not available in Edge runtime");
7
+ }
@@ -1,20 +1,10 @@
1
- import fs from "fs/promises";
2
- import path from "path";
3
- import { getContentRoot } from "./config.js";
1
+ let storage;
4
2
 
5
- export async function readLocal(file) {
6
- const root = getContentRoot();
7
- if (!root) throw new Error("Content root not configured");
8
-
9
- const filePath = path.join(root, file);
10
- const raw = await fs.readFile(filePath, "utf-8");
11
- return JSON.parse(raw);
3
+ if (typeof process !== "undefined" && process.versions?.node) {
4
+ storage = await import("./storage.node.js");
5
+ } else {
6
+ storage = await import("./storage.edge.js");
12
7
  }
13
8
 
14
- export async function writeLocal(file, data) {
15
- const root = getContentRoot();
16
- if (!root) throw new Error("Content root not configured");
17
-
18
- const filePath = path.join(root, file);
19
- await fs.writeFile(filePath, JSON.stringify(data, null, 2), "utf-8");
20
- }
9
+ export const readLocal = storage.readLocal;
10
+ export const writeLocal = storage.writeLocal;
@@ -0,0 +1,16 @@
1
+ import fs from "fs/promises";
2
+ import path from "path";
3
+ import { getContentRoot } from "./config.js";
4
+
5
+ export async function readLocal(file) {
6
+ const root = getContentRoot();
7
+ const filePath = path.join(root, file);
8
+ const raw = await fs.readFile(filePath, "utf-8");
9
+ return JSON.parse(raw);
10
+ }
11
+
12
+ export async function writeLocal(file, data) {
13
+ const root = getContentRoot();
14
+ const filePath = path.join(root, file);
15
+ await fs.writeFile(filePath, JSON.stringify(data, null, 2), "utf-8");
16
+ }