@yysng/astro-boilerplate 1.1.0 → 1.1.3
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
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
let CONTENT_ROOT = null;
|
|
2
|
+
|
|
3
|
+
export function setContentRoot(path) {
|
|
4
|
+
CONTENT_ROOT = path;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function getContentRoot() {
|
|
8
|
+
if (!CONTENT_ROOT) {
|
|
9
|
+
throw new Error("Content root not configured. Call setContentRoot() from the site.");
|
|
10
|
+
}
|
|
11
|
+
return CONTENT_ROOT;
|
|
12
|
+
}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import fs from "fs/promises";
|
|
2
|
+
import path from "path";
|
|
2
3
|
import { CONTENT_REGISTRY } from "./registry.js";
|
|
4
|
+
import { getContentRoot } from "./config.js";
|
|
3
5
|
|
|
4
6
|
export async function loadContent(key) {
|
|
5
7
|
const entry = CONTENT_REGISTRY[key];
|
|
8
|
+
if (!entry) throw new Error(`Unknown content key: ${key}`);
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const fileUrl = new URL(`../${entry.file}`, import.meta.url);
|
|
12
|
-
const raw = await fs.readFile(fileUrl, "utf-8");
|
|
13
|
-
const data = JSON.parse(raw);
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
10
|
+
const filePath = path.join(getContentRoot(), entry.file);
|
|
11
|
+
const raw = await fs.readFile(filePath, "utf-8");
|
|
12
|
+
return JSON.parse(raw);
|
|
13
|
+
}
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
export const CONTENT_REGISTRY = {
|
|
2
|
-
hero: {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
,
|
|
2
|
+
hero: {
|
|
3
|
+
file: "hero.json",
|
|
4
|
+
section: "HeroSection"
|
|
5
|
+
},
|
|
8
6
|
about: {
|
|
9
|
-
file: "
|
|
7
|
+
file: "about.json",
|
|
10
8
|
section: "AboutSection"
|
|
11
9
|
},
|
|
12
10
|
cta: {
|
|
13
|
-
file: "
|
|
11
|
+
file: "cta.json",
|
|
14
12
|
section: "CTASection"
|
|
15
13
|
},
|
|
16
14
|
testimonials: {
|
|
17
|
-
file: "
|
|
15
|
+
file: "testimonials.json",
|
|
18
16
|
section: "TertimonialSection"
|
|
19
17
|
}
|
|
20
|
-
};
|
|
18
|
+
};
|
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
import fs from "fs/promises";
|
|
2
|
+
import path from "path";
|
|
2
3
|
import { CONTENT_REGISTRY } from "./registry.js";
|
|
3
4
|
import { schemas } from "./schemas.js";
|
|
5
|
+
import { getContentRoot } from "./config.js";
|
|
4
6
|
|
|
5
7
|
export async function updateContent(key, data) {
|
|
6
8
|
const entry = CONTENT_REGISTRY[key];
|
|
9
|
+
if (!entry) throw new Error(`Unknown content key: ${key}`);
|
|
7
10
|
|
|
8
|
-
if (!entry) {
|
|
9
|
-
throw new Error(`Unknown content key: ${key}`);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// 🔒 Schema validation
|
|
13
11
|
const schema = schemas[key];
|
|
14
|
-
if (!schema) {
|
|
15
|
-
throw new Error(`No schema defined for content key: ${key}`);
|
|
16
|
-
}
|
|
17
|
-
|
|
12
|
+
if (!schema) throw new Error(`No schema for ${key}`);
|
|
18
13
|
schema.validate(data);
|
|
19
14
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
fileUrl,
|
|
24
|
-
JSON.stringify(data, null, 2),
|
|
25
|
-
"utf-8"
|
|
26
|
-
);
|
|
27
|
-
}
|
|
15
|
+
const filePath = path.join(getContentRoot(), entry.file);
|
|
16
|
+
await fs.writeFile(filePath, JSON.stringify(data, null, 2), "utf-8");
|
|
17
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// Public API of @yysng/astro-boilerplate
|
|
2
|
-
|
|
3
1
|
export { loadContent } from "./content-system/loader.js";
|
|
4
2
|
export { updateContent } from "./content-system/updater.js";
|
|
5
3
|
export { CONTENT_REGISTRY } from "./content-system/registry.js";
|
|
4
|
+
export {
|
|
5
|
+
setContentRoot
|
|
6
|
+
} from "./content-system/config.js";
|
|
File without changes
|