@zyrab/domo-ssg 0.5.3 → 0.5.4
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 +3 -3
- package/src/config.js +3 -4
- package/src/file-utils.js +0 -2
- package/src/index.js +4 -14
- package/src/route-handler.js +1 -1
- package/src/route-traversal.js +4 -4
- package/src/sitemap.js +16 -17
- package/src/utils.js +11 -13
- /package/{README → README.md} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyrab/domo-ssg",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "A Static Site Generator (SSG) for Domo-based projects.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@zyrab/domo": "^1.3.0",
|
|
21
|
-
"@zyrab/domo-
|
|
22
|
-
"@zyrab/domo-
|
|
21
|
+
"@zyrab/domo-og": "0.2.0",
|
|
22
|
+
"@zyrab/domo-router": "^0.3.1"
|
|
23
23
|
},
|
|
24
24
|
"publishConfig": {
|
|
25
25
|
"access": "public"
|
package/src/config.js
CHANGED
|
@@ -8,13 +8,12 @@ export async function loadConfig() {
|
|
|
8
8
|
if (mergedConfig) return mergedConfig;
|
|
9
9
|
const userConfigPath = path.resolve(process.cwd(), "domo.config.js");
|
|
10
10
|
|
|
11
|
-
// Default configuration values
|
|
12
11
|
const defaultConfig = {
|
|
13
12
|
outDir: "./dist",
|
|
14
13
|
routesFile: "./routes.js",
|
|
15
14
|
layout: "./layout.js",
|
|
16
15
|
lang: "en",
|
|
17
|
-
author: "
|
|
16
|
+
author: "Zyrab",
|
|
18
17
|
exclude: ["css", "js", "assets", "robots.txt", "admin"],
|
|
19
18
|
baseUrl: "http://localhost:3000",
|
|
20
19
|
};
|
|
@@ -24,7 +23,7 @@ export async function loadConfig() {
|
|
|
24
23
|
const importedConfig = await import(pathToFileURL(userConfigPath).href);
|
|
25
24
|
userConfig = importedConfig.default || importedConfig;
|
|
26
25
|
} catch (error) {
|
|
27
|
-
console.warn(
|
|
26
|
+
console.warn(`[Domo-SSG] No custom config file found at ${configFilePath}. Using default settings.`);
|
|
28
27
|
}
|
|
29
28
|
mergedConfig = {
|
|
30
29
|
...defaultConfig,
|
|
@@ -38,7 +37,7 @@ export async function loadConfig() {
|
|
|
38
37
|
|
|
39
38
|
export function getConfig() {
|
|
40
39
|
if (!mergedConfig) {
|
|
41
|
-
throw new Error("Interal Error: Config has not been loaded yet. Call loadConfig() first.");
|
|
40
|
+
throw new Error("[Domo-SSG] Interal Error: Config has not been loaded yet. Call loadConfig() first.");
|
|
42
41
|
}
|
|
43
42
|
return mergedConfig;
|
|
44
43
|
}
|
package/src/file-utils.js
CHANGED
|
@@ -42,9 +42,7 @@ export function cleanOutputDir(outputDir, exclude) {
|
|
|
42
42
|
const entryPath = path.join(outputDir, entry);
|
|
43
43
|
fs.rmSync(entryPath, { recursive: true, force: true });
|
|
44
44
|
}
|
|
45
|
-
console.log(`📁 Cleaned output directory: ${outputDir}`);
|
|
46
45
|
} else {
|
|
47
46
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
48
|
-
console.log(`📁 Created output directory: ${outputDir}`);
|
|
49
47
|
}
|
|
50
48
|
}
|
package/src/index.js
CHANGED
|
@@ -4,35 +4,25 @@ import { loadConfig } from "./config.js";
|
|
|
4
4
|
import { cleanOutputDir } from "./file-utils.js";
|
|
5
5
|
import { generateSitemap } from "./sitemap.js";
|
|
6
6
|
import { buildRoutes } from "./route-traversal.js";
|
|
7
|
-
import "dotenv/config";
|
|
8
7
|
|
|
9
8
|
async function main() {
|
|
10
|
-
process.env.DOMO_SSG = "true";
|
|
11
9
|
const config = await loadConfig();
|
|
12
10
|
|
|
13
|
-
// Import layout and route tree using pathToFileURL and .href for dynamic imports
|
|
14
11
|
const { routes } = await import(pathToFileURL(config.routesFile).href);
|
|
15
12
|
const { renderLayout } = await import(pathToFileURL(config.layout).href);
|
|
16
13
|
|
|
17
|
-
console.log("
|
|
18
|
-
console.log(`📁 Output directory: ${config.outDir}`);
|
|
19
|
-
console.log(`🗺️ Routes file: ${config.routesFile}`);
|
|
20
|
-
console.log(`🧩 Layout file: ${config.layout}`);
|
|
14
|
+
console.log("[Domo-SSG] Starting Domo SSG build...");
|
|
21
15
|
|
|
22
|
-
// 1. Clean the output directory
|
|
23
16
|
cleanOutputDir(config.outDir, config.exclude);
|
|
24
17
|
|
|
25
|
-
// 2. Build all routes recursively
|
|
26
18
|
await buildRoutes(routes, renderLayout);
|
|
27
19
|
|
|
28
|
-
// 3. Generate sitemap
|
|
29
20
|
generateSitemap(config.outDir, config.baseUrl, config.exclude);
|
|
30
21
|
|
|
31
|
-
console.log("
|
|
22
|
+
console.log("[Domo-SSG] build complete!");
|
|
32
23
|
}
|
|
33
24
|
|
|
34
|
-
// Execute the build process
|
|
35
25
|
main().catch((error) => {
|
|
36
|
-
console.error("
|
|
37
|
-
process.exit(1);
|
|
26
|
+
console.error("[Domo-SSG] build failed:", error);
|
|
27
|
+
process.exit(1);
|
|
38
28
|
});
|
package/src/route-handler.js
CHANGED
|
@@ -63,6 +63,6 @@ export async function handleRoute(params, renderLayout) {
|
|
|
63
63
|
// Write the generated HTML to a file
|
|
64
64
|
writeHTML(outDir, path, html);
|
|
65
65
|
} catch (e) {
|
|
66
|
-
console.warn(
|
|
66
|
+
console.warn(`[Domo-SSG] Error rendering ${path}:\n${e.stack}`);
|
|
67
67
|
}
|
|
68
68
|
}
|
package/src/route-traversal.js
CHANGED
|
@@ -25,14 +25,14 @@ export async function buildRoutes(routes, renderLayout, parentPath = "", props =
|
|
|
25
25
|
const resolvedParams = await routeNode.routeParams(parentRouteName);
|
|
26
26
|
|
|
27
27
|
if (!Array.isArray(resolvedParams) || resolvedParams.length === 0) {
|
|
28
|
-
console.warn(
|
|
28
|
+
console.warn(`[Domo-SSG] No items returned for dynamic route at ${currentRoute}`);
|
|
29
29
|
continue;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
for (const item of resolvedParams) {
|
|
33
33
|
const segment = item[paramName];
|
|
34
34
|
if (!segment) {
|
|
35
|
-
console.warn(
|
|
35
|
+
console.warn(`[Domo-SSG] Missing parameter:'${paramName}' in item for dynamic route at ${currentRoute}`);
|
|
36
36
|
continue;
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -46,7 +46,7 @@ export async function buildRoutes(routes, renderLayout, parentPath = "", props =
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
} catch (e) {
|
|
49
|
-
console.warn(
|
|
49
|
+
console.warn(`[Domo-SSG] Skipped dynamic route generation for ${currentRoute}: ${e.message}`);
|
|
50
50
|
}
|
|
51
51
|
continue;
|
|
52
52
|
}
|
|
@@ -56,7 +56,7 @@ export async function buildRoutes(routes, renderLayout, parentPath = "", props =
|
|
|
56
56
|
await buildRoutes(routeNode, renderLayout, currentRoute, { ...props });
|
|
57
57
|
}
|
|
58
58
|
if (!routeNode.component && Object.keys(routeNode).length > 0) {
|
|
59
|
-
console.warn(
|
|
59
|
+
console.warn(`[Domo-SSG] Route "${currentRoute}" has no component but contains other data.`);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
package/src/sitemap.js
CHANGED
|
@@ -39,9 +39,7 @@ export function generateSitemap(outputDir, baseUrl, exclude = []) {
|
|
|
39
39
|
let urlPath = "/" + relative.replace(/\\/g, "/");
|
|
40
40
|
|
|
41
41
|
// Root correction
|
|
42
|
-
if (urlPath === "//" || urlPath === "/.")
|
|
43
|
-
urlPath = "/";
|
|
44
|
-
}
|
|
42
|
+
if (urlPath === "//" || urlPath === "/.") urlPath = "/";
|
|
45
43
|
|
|
46
44
|
const stats = fs.statSync(indexPath);
|
|
47
45
|
const lastmod = stats.mtime.toISOString();
|
|
@@ -61,20 +59,21 @@ export function generateSitemap(outputDir, baseUrl, exclude = []) {
|
|
|
61
59
|
|
|
62
60
|
walk(outputDir);
|
|
63
61
|
|
|
64
|
-
const xml =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
62
|
+
const xml = `
|
|
63
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
64
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
65
|
+
${urls
|
|
66
|
+
.map(
|
|
67
|
+
({ loc, lastmod, priority, changefreq }) => `
|
|
68
|
+
<url>
|
|
69
|
+
<loc>${loc}</loc>
|
|
70
|
+
<lastmod>${lastmod}</lastmod>
|
|
71
|
+
<changefreq>${changefreq}</changefreq>
|
|
72
|
+
<priority>${priority}</priority>
|
|
73
|
+
</url>`,
|
|
74
|
+
)
|
|
75
|
+
.join("\n")}
|
|
76
|
+
</urlset>`;
|
|
77
77
|
|
|
78
78
|
fs.writeFileSync(path.join(outputDir, "sitemap.xml"), xml, "utf8");
|
|
79
|
-
console.log(`🧭 Generated sitemap.xml at: ${path.join(outputDir, "sitemap.xml")}`);
|
|
80
79
|
}
|
package/src/utils.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import Router from "@zyrab/domo-router";
|
|
2
|
+
|
|
2
3
|
export function normalizeAssets(arr) {
|
|
3
|
-
if (!arr) return [];
|
|
4
|
-
const flatArray = Array.isArray(arr) ? arr.flat() : [arr];
|
|
4
|
+
if (!arr) return [];
|
|
5
|
+
const flatArray = Array.isArray(arr) ? arr.flat() : [arr];
|
|
5
6
|
const result = [];
|
|
6
7
|
|
|
7
8
|
for (const item of flatArray) {
|
|
8
|
-
if (!item) continue;
|
|
9
|
-
if (typeof item === "string") {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
result.push(item);
|
|
13
|
-
} else if (typeof item === "object" && !item.href) {
|
|
14
|
-
// For objects without href, attempt to normalize keys like { src: "..." }
|
|
9
|
+
if (!item) continue;
|
|
10
|
+
if (typeof item === "string") result.push({ href: item });
|
|
11
|
+
else if (typeof item === "object" && item.href) result.push(item);
|
|
12
|
+
else if (typeof item === "object" && !item.href) {
|
|
15
13
|
if (item.src) result.push({ ...item, href: item.src });
|
|
16
14
|
}
|
|
17
15
|
}
|
|
@@ -19,7 +17,7 @@ export function normalizeAssets(arr) {
|
|
|
19
17
|
return result;
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
export async function tryGenerateOgImage(routeMeta,
|
|
20
|
+
export async function tryGenerateOgImage(routeMeta, ogOutputPath, path) {
|
|
23
21
|
if (!routeMeta.generateOgImage) return;
|
|
24
22
|
const slug = Router.info().segments.at(-1).slice(1);
|
|
25
23
|
|
|
@@ -28,7 +26,7 @@ export async function tryGenerateOgImage(routeMeta, outputDir, path) {
|
|
|
28
26
|
|
|
29
27
|
const ogPath = generate({
|
|
30
28
|
...routeMeta,
|
|
31
|
-
|
|
29
|
+
ogOutputPath,
|
|
32
30
|
slug,
|
|
33
31
|
routeKey: path,
|
|
34
32
|
});
|
|
@@ -36,9 +34,9 @@ export async function tryGenerateOgImage(routeMeta, outputDir, path) {
|
|
|
36
34
|
return ogPath;
|
|
37
35
|
} catch (err) {
|
|
38
36
|
if (err.code === "ERR_MODULE_NOT_FOUND" || err.message.includes("Cannot find module")) {
|
|
39
|
-
console.warn(
|
|
37
|
+
console.warn(`[Domo-SSG] OG image generation skipped for "${slug}" — install 'domo-og' to enable this feature.`);
|
|
40
38
|
} else {
|
|
41
|
-
console.warn(
|
|
39
|
+
console.warn(`[Domo-SSG] OG image generation failed for "${slug}":\n${err.stack}`);
|
|
42
40
|
}
|
|
43
41
|
}
|
|
44
42
|
}
|
/package/{README → README.md}
RENAMED
|
File without changes
|