@yysng/astro-boilerplate 1.1.18 โ†’ 1.1.20

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.18",
3
+ "version": "1.1.20",
4
4
  "description": "Astro + Sanity Boilerplate with AEO Layers 1โ€“5",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,15 +1,24 @@
1
1
  import { CONTENT_REGISTRY } from "./registry.js";
2
2
  import { readLocal } from "./storage.js";
3
+ import { getContentRoot } from "./config.js";
3
4
 
4
5
  export async function loadContent(key, env = {}) {
5
6
  const entry = CONTENT_REGISTRY[key];
6
7
  if (!entry) throw new Error(`Unknown content key: ${key}`);
7
8
 
9
+ // ๐ŸŒ Production: Cloudflare KV only
8
10
  if (env?.CONTENT_KV) {
9
11
  const stored = await env.CONTENT_KV.get(entry.file, "json");
10
12
  if (stored) return stored;
13
+
11
14
  throw new Error(`KV missing content for key "${key}" (file "${entry.file}")`);
12
15
  }
13
16
 
14
- return await readLocal(entry.file);
17
+ // ๐Ÿงช Local Node only
18
+ const root = getContentRoot();
19
+ if (!root) {
20
+ throw new Error("Content root not configured in local environment");
21
+ }
22
+
23
+ return await readLocal(root, entry.file);
15
24
  }
@@ -2,21 +2,29 @@ import fs from "fs/promises";
2
2
  import path from "path";
3
3
  import { getContentRoot } from "./config.js";
4
4
 
5
- function assertRoot() {
5
+ /**
6
+ * Local filesystem read (Node only)
7
+ */
8
+ export async function readLocal(file) {
6
9
  const root = getContentRoot();
7
- if (!root) throw new Error("Content root not configured in local environment");
8
- return root;
9
- }
10
+ if (!root) {
11
+ throw new Error("Content root not configured");
12
+ }
10
13
 
11
- export async function readLocal(file) {
12
- const root = assertRoot();
13
14
  const filePath = path.join(root, file);
14
15
  const raw = await fs.readFile(filePath, "utf-8");
15
16
  return JSON.parse(raw);
16
17
  }
17
18
 
19
+ /**
20
+ * Local filesystem write (Node only)
21
+ */
18
22
  export async function writeLocal(file, data) {
19
- const root = assertRoot();
23
+ const root = getContentRoot();
24
+ if (!root) {
25
+ throw new Error("Content root not configured");
26
+ }
27
+
20
28
  const filePath = path.join(root, file);
21
29
  await fs.writeFile(filePath, JSON.stringify(data, null, 2), "utf-8");
22
30
  }
@@ -31,13 +31,13 @@ export async function updateContent(key, incoming, env = {}) {
31
31
 
32
32
  schema.validate(merged);
33
33
 
34
- // Cloudflare
35
- if (env.CONTENT_KV) {
34
+ // ๐ŸŒ Production: Cloudflare KV
35
+ if (env?.CONTENT_KV) {
36
36
  await env.CONTENT_KV.put(entry.file, JSON.stringify(merged));
37
37
  return merged;
38
38
  }
39
39
 
40
- // Local dev
40
+ // ๐Ÿ–ฅ๏ธ Local development
41
41
  await writeLocal(entry.file, merged);
42
42
  return merged;
43
43
  }