@zyrab/domo-ssg 0.4.0 β 0.5.0
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/README +14 -14
- package/package.json +6 -5
- package/src/file-utils.js +1 -1
- package/src/index.js +3 -3
- package/src/route-handler.js +6 -5
- package/src/route-traversal.js +0 -1
- package/src/sitemap.js +1 -1
- package/src/utils.js +25 -0
package/README
CHANGED
|
@@ -5,18 +5,18 @@ Write JavaScript templates using [@zyrab/domo](https://www.npmjs.com/package/@zy
|
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Features
|
|
9
9
|
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
10
|
+
- Declarative page structure with `Domo` and `DomoSVG`
|
|
11
|
+
- Simple nested route tree (`routes.js`)
|
|
12
|
+
- Custom layout wrapper (`layout.js`)
|
|
13
|
+
- Virtual DOM-like output (no DOM dependency during build)
|
|
14
|
+
- Hydration-ready: automatic inline scripts for events
|
|
15
|
+
- Built-in cleanup and sitemap generation
|
|
16
16
|
|
|
17
17
|
---
|
|
18
18
|
|
|
19
|
-
##
|
|
19
|
+
## Installation
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
22
|
pnpm add -D @zyrab/domo-ssg
|
|
@@ -24,7 +24,7 @@ pnpm add -D @zyrab/domo-ssg
|
|
|
24
24
|
|
|
25
25
|
Note: Use in a pnpm monorepo if you're working with other Domo packages like @zyrab/domo or @zyrab/domo-router.
|
|
26
26
|
|
|
27
|
-
##
|
|
27
|
+
## Usage
|
|
28
28
|
|
|
29
29
|
### 1. Scaffold basic structure
|
|
30
30
|
|
|
@@ -56,7 +56,7 @@ layout.js;
|
|
|
56
56
|
pnpm build
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
#
|
|
59
|
+
# Project Structure
|
|
60
60
|
|
|
61
61
|
| File | Purpose |
|
|
62
62
|
| ---------------- | ----------------------------------- |
|
|
@@ -64,10 +64,10 @@ pnpm build
|
|
|
64
64
|
| `layout.js` | Optional layout wrapper |
|
|
65
65
|
| `domo.config.js` | Customize output dir, base URL, etc |
|
|
66
66
|
|
|
67
|
-
#
|
|
67
|
+
# Example Route File
|
|
68
68
|
|
|
69
69
|
```js
|
|
70
|
-
import
|
|
70
|
+
import Domo from "@zyrab/domo";
|
|
71
71
|
|
|
72
72
|
export const routes = {
|
|
73
73
|
"/": () => Domo("div").txt("Hello Home"),
|
|
@@ -75,7 +75,7 @@ export const routes = {
|
|
|
75
75
|
};
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
#
|
|
78
|
+
# Configuration (domo.config.js)
|
|
79
79
|
|
|
80
80
|
```js
|
|
81
81
|
export default {
|
|
@@ -87,6 +87,6 @@ export default {
|
|
|
87
87
|
};
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
#
|
|
90
|
+
# License
|
|
91
91
|
|
|
92
92
|
MIT β Β© Zyrab
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyrab/domo-ssg",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "A Static Site Generator (SSG) for Domo-based projects.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -17,15 +17,16 @@
|
|
|
17
17
|
"author": "Zyrab",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@zyrab/domo": "^1.
|
|
21
|
-
"@zyrab/domo-
|
|
20
|
+
"@zyrab/domo": "^1.3.0",
|
|
21
|
+
"@zyrab/domo-og": "0.1.0",
|
|
22
|
+
"@zyrab/domo-router": "^0.1.1"
|
|
22
23
|
},
|
|
23
|
-
"devDependencies": {},
|
|
24
24
|
"publishConfig": {
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
|
-
"src/"
|
|
28
|
+
"src/",
|
|
29
|
+
"README"
|
|
29
30
|
],
|
|
30
31
|
"scripts": {
|
|
31
32
|
"build": "node src/index.js",
|
package/src/file-utils.js
CHANGED
|
@@ -25,7 +25,7 @@ export function writeHTML(outputDir, routePath, html) {
|
|
|
25
25
|
const outPath = path.join(outputDir, fileName, "index.html");
|
|
26
26
|
ensureDir(outPath);
|
|
27
27
|
fs.writeFileSync(outPath, html, "utf8");
|
|
28
|
-
console.log(`Generated: ${path.relative(outputDir, outPath)}`);
|
|
28
|
+
// console.log(`Generated: ${path.relative(outputDir, outPath)}`);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
package/src/index.js
CHANGED
|
@@ -13,9 +13,9 @@ async function main() {
|
|
|
13
13
|
const { renderLayout } = await import(pathToFileURL(config.layout).href);
|
|
14
14
|
|
|
15
15
|
console.log("π Starting Domo SSG build...");
|
|
16
|
-
console.log(
|
|
17
|
-
console.log(
|
|
18
|
-
console.log(
|
|
16
|
+
console.log(`π Output directory: ${config.outDir}`);
|
|
17
|
+
console.log(`πΊοΈ Routes file: ${config.routesFile}`);
|
|
18
|
+
console.log(`π§© Layout file: ${config.layout}`);
|
|
19
19
|
|
|
20
20
|
// 1. Clean the output directory
|
|
21
21
|
cleanOutputDir(config.outDir, config.exclude);
|
package/src/route-handler.js
CHANGED
|
@@ -3,7 +3,7 @@ import Router from "@zyrab/domo-router";
|
|
|
3
3
|
import { getConfig } from "./config.js";
|
|
4
4
|
import { writeHTML } from "./file-utils.js";
|
|
5
5
|
import { writeJs } from "./event-utils.js";
|
|
6
|
-
import { normalizeAssets } from "./utils.js";
|
|
6
|
+
import { normalizeAssets, tryGenerateOgImage } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Helper to join URL path segments correctly.
|
|
@@ -34,19 +34,19 @@ export async function handleRoute(params, renderLayout) {
|
|
|
34
34
|
const { outDir, baseUrl, lang, author, theme, assets } = getConfig();
|
|
35
35
|
const { path, props = {}, component, scripts = [], styles = [], fonts = [], meta = {} } = params;
|
|
36
36
|
try {
|
|
37
|
-
// Set router info for server-side context
|
|
38
37
|
Router.setInfo(path, props);
|
|
39
38
|
|
|
40
39
|
// Render the component content
|
|
41
40
|
const content = await component(props);
|
|
42
41
|
|
|
43
|
-
// --- Write JS file ---
|
|
44
42
|
const embededScript = writeJs(content, outDir, path);
|
|
45
|
-
|
|
43
|
+
|
|
44
|
+
const ogImage = await tryGenerateOgImage(meta, outDir, path);
|
|
45
|
+
|
|
46
46
|
const fontPaths = normalizeAssets([fonts, assets.fonts]);
|
|
47
47
|
const stylePaths = normalizeAssets([styles, assets.styles]);
|
|
48
48
|
const scriptPaths = normalizeAssets([embededScript, scripts, assets.scripts]);
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
const html = await renderLayout(content, {
|
|
51
51
|
scripts: scriptPaths,
|
|
52
52
|
styles: stylePaths,
|
|
@@ -57,6 +57,7 @@ export async function handleRoute(params, renderLayout) {
|
|
|
57
57
|
author,
|
|
58
58
|
theme,
|
|
59
59
|
...meta,
|
|
60
|
+
ogImage: ogImage || meta.ogImage,
|
|
60
61
|
});
|
|
61
62
|
|
|
62
63
|
// Write the generated HTML to a file
|
package/src/route-traversal.js
CHANGED
package/src/sitemap.js
CHANGED
|
@@ -76,5 +76,5 @@ ${urls
|
|
|
76
76
|
</urlset>`;
|
|
77
77
|
|
|
78
78
|
fs.writeFileSync(path.join(outputDir, "sitemap.xml"), xml, "utf8");
|
|
79
|
-
console.log(
|
|
79
|
+
console.log(`π§ Generated sitemap.xml at: ${path.join(outputDir, "sitemap.xml")}`);
|
|
80
80
|
}
|
package/src/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Router from "@zyrab/domo-router";
|
|
1
2
|
export function normalizeAssets(arr) {
|
|
2
3
|
if (!arr) return []; // Handle null/undefined safely
|
|
3
4
|
const flatArray = Array.isArray(arr) ? arr.flat() : [arr]; // Support single string/object
|
|
@@ -17,3 +18,27 @@ export function normalizeAssets(arr) {
|
|
|
17
18
|
|
|
18
19
|
return result;
|
|
19
20
|
}
|
|
21
|
+
|
|
22
|
+
export async function tryGenerateOgImage(routeMeta, outputDir, path) {
|
|
23
|
+
if (!routeMeta.generateOgImage) return;
|
|
24
|
+
const slug = Router.info().segments.at(-1).slice(1);
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const { generateOgImage: generate } = await import("@zyrab/domo-og");
|
|
28
|
+
|
|
29
|
+
const ogPath = generate({
|
|
30
|
+
...routeMeta,
|
|
31
|
+
outputDir,
|
|
32
|
+
slug,
|
|
33
|
+
routeKey: path,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return ogPath;
|
|
37
|
+
} catch (err) {
|
|
38
|
+
if (err.code === "ERR_MODULE_NOT_FOUND" || err.message.includes("Cannot find module")) {
|
|
39
|
+
console.warn(`β οΈ OG image generation skipped for "${slug}" β install 'domo-og' to enable this feature.`);
|
|
40
|
+
} else {
|
|
41
|
+
console.warn(`β οΈ OG image generation failed for "${slug}":\n${err.stack}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|