@yysng/astro-boilerplate 1.1.14 โ†’ 1.1.16

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.14",
3
+ "version": "1.1.16",
4
4
  "description": "Astro + Sanity Boilerplate with AEO Layers 1โ€“5",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,16 +1,23 @@
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
 
8
- // Cloudflare production
9
- if (env.CONTENT_KV) {
9
+ // ๐Ÿง  Production: Cloudflare KV
10
+ if (env && env.CONTENT_KV) {
10
11
  const stored = await env.CONTENT_KV.get(entry.file, "json");
11
12
  if (stored) return stored;
13
+ throw new Error(`Missing content in KV: ${entry.file}`);
12
14
  }
13
15
 
14
- // Local development fallback
15
- return await readLocal(entry.file);
16
+ // ๐Ÿงช Local dev: filesystem
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);
16
23
  }
@@ -2,13 +2,19 @@ import fs from "fs/promises";
2
2
  import path from "path";
3
3
  import { getContentRoot } from "./config.js";
4
4
 
5
- export async function readLocal(file) {
6
- const filePath = path.join(getContentRoot(), file);
5
+ /**
6
+ * Local filesystem read (Node only)
7
+ */
8
+ export async function readLocal(root, file) {
9
+ const filePath = path.join(root, file);
7
10
  const raw = await fs.readFile(filePath, "utf-8");
8
11
  return JSON.parse(raw);
9
12
  }
10
13
 
11
- export async function writeLocal(file, data) {
12
- const filePath = path.join(getContentRoot(), file);
14
+ /**
15
+ * Local filesystem write (Node only)
16
+ */
17
+ export async function writeLocal(root, file, data) {
18
+ const filePath = path.join(root, file);
13
19
  await fs.writeFile(filePath, JSON.stringify(data, null, 2), "utf-8");
14
20
  }