@brightsideoy/kama 0.1.0-alpha.16 → 0.1.0-alpha.161
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.md +169 -0
- package/bin/cli.js +686 -155
- package/content/definitions/block-layouts/three-column.yaml +20 -0
- package/content/definitions/block-layouts/two-column.yaml +29 -0
- package/content/definitions/blocks/button.yaml +24 -0
- package/content/definitions/blocks/header.yaml +13 -0
- package/content/definitions/blocks/header_image.yaml +21 -0
- package/content/definitions/blocks/hero.yaml +28 -0
- package/content/definitions/blocks/html.yaml +13 -0
- package/content/definitions/blocks/image_card.yaml +56 -0
- package/content/definitions/blocks/single_image.yaml +27 -0
- package/content/definitions/blocks/text.yaml +15 -0
- package/content/definitions/channels/ecommerce.yaml +28 -0
- package/content/definitions/channels/website.yaml +41 -0
- package/content/definitions/field-sets/access.yaml +27 -0
- package/content/definitions/field-sets/channel-base.yaml +50 -0
- package/content/definitions/field-sets/channel-seo.yaml +21 -0
- package/content/definitions/field-sets/comments.yaml +11 -0
- package/content/definitions/field-sets/content-block.yaml +41 -0
- package/content/definitions/field-sets/page-base.yaml +44 -0
- package/content/definitions/field-sets/page-seo.yaml +34 -0
- package/content/definitions/field-sets/page-social.yaml +78 -0
- package/content/definitions/field-sets/schema-type.yaml +43 -0
- package/content/definitions/field-sets/tree-base.yaml +31 -0
- package/content/definitions/field-sets/visibility.yaml +8 -0
- package/content/definitions/node-layouts/content.yml +12 -0
- package/content/definitions/node-layouts/landing-page.yml +27 -0
- package/content/definitions/node-layouts/single-column.yml +43 -0
- package/content/definitions/node-layouts/two-column.yml +48 -0
- package/content/definitions/nodes/address.yaml +40 -0
- package/content/definitions/nodes/article.yaml +37 -0
- package/content/definitions/nodes/event.yaml +55 -0
- package/content/definitions/nodes/external-link.yaml +29 -0
- package/content/definitions/nodes/page-skeleton.yaml +48 -0
- package/content/definitions/nodes/page.yaml +54 -0
- package/content/definitions/nodes/person.yaml +41 -0
- package/content/definitions/nodes/product.yaml +89 -0
- package/content/definitions/trees/navigation.yaml +24 -0
- package/definitions/editor/button.ts +11 -0
- package/definitions/editor/default.ts +21 -0
- package/definitions/editor/header.ts +36 -0
- package/definitions/editor/minimal.ts +15 -0
- package/definitions/validators/iban.ts +12 -0
- package/definitions/validators/magic-word.ts +7 -0
- package/dist/assets/index-C5TmJVER.css +1 -0
- package/dist/assets/index-jpMh2BZv.js +164 -0
- package/dist/dist-BNkCx-o-.js +8912 -0
- package/dist/index.html +15 -0
- package/dist/index.js +7646 -1562
- package/dist/schema-compiler.js +48 -0
- package/documentation/SCHEMAS.md +182 -0
- package/package.json +19 -17
- package/schema.sql +206 -0
- package/templates/astro-starter/astro.config.mjs +24 -0
- package/templates/astro-starter/package.json.template +20 -0
- package/templates/astro-starter/public/robots.txt +23 -0
- package/templates/astro-starter/src/components/blocks/BlockRenderer.astro +134 -0
- package/templates/astro-starter/src/components/blocks/ColumnLayout.astro +67 -0
- package/templates/astro-starter/src/components/blocks/HeaderImage.astro +132 -0
- package/templates/astro-starter/src/components/blocks/Hero.astro +218 -0
- package/templates/astro-starter/src/components/blocks/HtmlBlock.astro +25 -0
- package/templates/astro-starter/src/components/blocks/ImageBlock.astro +92 -0
- package/templates/astro-starter/src/components/blocks/TextBlock.astro +15 -0
- package/templates/astro-starter/src/components/global/Breadcrumb.astro +67 -0
- package/templates/astro-starter/src/components/global/Footer.astro +50 -0
- package/templates/astro-starter/src/components/global/Header.astro +177 -0
- package/templates/astro-starter/src/components/global/MetaHead.astro +266 -0
- package/templates/astro-starter/src/components/global/NavigationMenu.astro +318 -0
- package/templates/astro-starter/src/components/ui/KamaImage.astro +172 -0
- package/templates/astro-starter/src/layouts/SkeletonLayout.astro +47 -0
- package/templates/astro-starter/src/layouts/StandardLayout.astro +62 -0
- package/templates/astro-starter/src/lib/cms.ts +197 -0
- package/templates/astro-starter/src/lib/media/kama-image-service.ts +56 -0
- package/templates/astro-starter/src/lib/media/media-proxy.ts +129 -0
- package/templates/astro-starter/src/lib/media/media-url.ts +98 -0
- package/templates/astro-starter/src/middleware.ts +406 -0
- package/templates/astro-starter/src/pages/404.astro +46 -0
- package/templates/astro-starter/src/pages/[...slug].astro +238 -0
- package/templates/astro-starter/src/pages/llms-full.txt.ts +171 -0
- package/templates/astro-starter/src/pages/llms.txt.ts +113 -0
- package/templates/astro-starter/src/pages/media/[...path].ts +14 -0
- package/templates/astro-starter/src/pages/partials/footer.astro +69 -0
- package/templates/astro-starter/src/pages/partials/nav.astro +141 -0
- package/templates/astro-starter/src/styles/standard-theme.css +157 -0
- package/templates/astro-starter/src/utils/tiptap.ts +113 -0
- package/templates/astro-starter/tsconfig.json +0 -0
- package/templates/kama-worker/index.js +19 -0
- package/templates/kama-worker/server.js +98 -0
- package/wrangler.json +22 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// src/pages/llms-full.txt.ts
|
|
2
|
+
import type { APIRoute } from "astro";
|
|
3
|
+
import { getTree, getTreeId, getChannelId, getNodeByPath } from "../lib/cms";
|
|
4
|
+
import { renderTiptapNode } from "../utils/tiptap";
|
|
5
|
+
|
|
6
|
+
export const prerender = false;
|
|
7
|
+
|
|
8
|
+
export const GET: APIRoute = async (context) => {
|
|
9
|
+
// 1. Setup Worker Fetch Binding
|
|
10
|
+
const locals = (context.locals as any) || {};
|
|
11
|
+
const cfEnv = locals.cfContext?.env || {};
|
|
12
|
+
const cmsWorker = cfEnv.CMS_WORKER;
|
|
13
|
+
|
|
14
|
+
const envApiUrl = import.meta.env.PUBLIC_API_URL;
|
|
15
|
+
const workerApiUrl = cfEnv.PUBLIC_API_URL || (typeof process !== "undefined" ? process.env?.PUBLIC_API_URL : undefined);
|
|
16
|
+
const baseApiUrl = String(envApiUrl || workerApiUrl || "http://localhost:8787").replace(/\/$/, "");
|
|
17
|
+
|
|
18
|
+
const customFetch = async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
19
|
+
let urlStr = input instanceof URL ? input.toString() : String(input);
|
|
20
|
+
if (urlStr.startsWith("/")) urlStr = `${baseApiUrl}${urlStr}`;
|
|
21
|
+
|
|
22
|
+
const req = new Request(urlStr, init);
|
|
23
|
+
if (cmsWorker && typeof cmsWorker.fetch === "function") {
|
|
24
|
+
return cmsWorker.fetch(req);
|
|
25
|
+
}
|
|
26
|
+
return fetch(req);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const channelId = getChannelId() || import.meta.env.PUBLIC_CHANNEL_ID || "main-channel";
|
|
30
|
+
const treeId = getTreeId() || import.meta.env.PUBLIC_TREE_ID || "main-tree";
|
|
31
|
+
|
|
32
|
+
// 🎯 Extract configurable fallback home slug
|
|
33
|
+
const envHomeSlug = import.meta.env.PUBLIC_HOME_SLUG;
|
|
34
|
+
const workerHomeSlug = cfEnv.PUBLIC_HOME_SLUG || (typeof process !== "undefined" ? process.env?.PUBLIC_HOME_SLUG : undefined);
|
|
35
|
+
const homeSlug = String(envHomeSlug || workerHomeSlug || "home").trim();
|
|
36
|
+
|
|
37
|
+
const rawOrigin = import.meta.env.PUBLIC_SITE_URL || context.url.origin;
|
|
38
|
+
const siteOrigin = String(rawOrigin).replace(/\/$/, "");
|
|
39
|
+
const brandName = import.meta.env.PUBLIC_SITE_NAME || "KAMA Starter";
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
// 2. Fetch Navigation Tree first to determine root nodes
|
|
43
|
+
const rawNavTree = await getTree(treeId, channelId, customFetch).catch(() => []);
|
|
44
|
+
const navTree = Array.isArray(rawNavTree)
|
|
45
|
+
? rawNavTree
|
|
46
|
+
: (rawNavTree?.tree || rawNavTree?.items || rawNavTree?.data || []);
|
|
47
|
+
|
|
48
|
+
// Determine home page slug (first root node in tree, or fallback home slug)
|
|
49
|
+
const rootTreeSlug = navTree.length > 0 ? (navTree[0].slug || navTree[0].key || "") : "";
|
|
50
|
+
const resolvedHomeSlug = rootTreeSlug || homeSlug;
|
|
51
|
+
|
|
52
|
+
// Fetch Home Node (for global context)
|
|
53
|
+
const homeData = await getNodeByPath(resolvedHomeSlug, channelId, false, customFetch).catch(() => null);
|
|
54
|
+
|
|
55
|
+
const siteSummary = homeData?.node?.abstract || homeData?.node?.summary || "Full Application Documentation Corpus";
|
|
56
|
+
|
|
57
|
+
// 3. Header section matching llmstxt.org spec
|
|
58
|
+
let fullText = `# ${brandName} - Full Corpus\n\n`;
|
|
59
|
+
fullText += `> ${siteSummary}\n\n`;
|
|
60
|
+
fullText += `This file contains the complete unabridged text content for all pages across the application.\n\n`;
|
|
61
|
+
|
|
62
|
+
// Helper to extract text from block data (handles TipTap AST & raw strings)
|
|
63
|
+
const parseBlockText = (blockData: any): string => {
|
|
64
|
+
if (!blockData) return "";
|
|
65
|
+
let rawText = "";
|
|
66
|
+
|
|
67
|
+
if (typeof blockData === "string") {
|
|
68
|
+
rawText = blockData;
|
|
69
|
+
} else if (blockData.type === "doc") {
|
|
70
|
+
rawText = renderTiptapNode(blockData);
|
|
71
|
+
} else if (blockData.body) {
|
|
72
|
+
rawText = parseBlockText(blockData.body);
|
|
73
|
+
} else if (blockData.text) {
|
|
74
|
+
rawText = parseBlockText(blockData.text);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Convert basic HTML block tags to plain text linebreaks
|
|
78
|
+
return rawText
|
|
79
|
+
.replace(/<h[1-6][^>]*>(.*?)<\/h[1-6]>/gi, "## $1\n")
|
|
80
|
+
.replace(/<p[^>]*>(.*?)<\/p>/gi, "$1\n")
|
|
81
|
+
.replace(/<br\s*\/?>/gi, "\n")
|
|
82
|
+
.replace(/<[^>]+>/g, ""); // Strip any remaining tags
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// Recursive walker to fetch each page's full content
|
|
86
|
+
const processNodes = async (nodes: any[], depth = 1) => {
|
|
87
|
+
let sectionContent = "";
|
|
88
|
+
|
|
89
|
+
for (const item of nodes) {
|
|
90
|
+
const nodeData = item.node || item;
|
|
91
|
+
if (!nodeData || nodeData.isHidden) continue;
|
|
92
|
+
|
|
93
|
+
const itemSlug = nodeData.slug || nodeData.path || "";
|
|
94
|
+
const isRootItem = itemSlug === resolvedHomeSlug || itemSlug === "" || itemSlug === "/";
|
|
95
|
+
const itemUrl = isRootItem ? siteOrigin : `${siteOrigin}/${itemSlug.replace(/^\//, "")}`;
|
|
96
|
+
const itemTitle = nodeData.title || nodeData.label || "Untitled Page";
|
|
97
|
+
|
|
98
|
+
const fetchSlug = isRootItem ? resolvedHomeSlug : itemSlug.replace(/^\//, "");
|
|
99
|
+
|
|
100
|
+
// Fetch node's block contents
|
|
101
|
+
const pageData = await getNodeByPath(
|
|
102
|
+
fetchSlug,
|
|
103
|
+
channelId,
|
|
104
|
+
false,
|
|
105
|
+
customFetch
|
|
106
|
+
).catch(() => null);
|
|
107
|
+
|
|
108
|
+
// Add Document Title Header
|
|
109
|
+
sectionContent += `\n---\n\n`;
|
|
110
|
+
sectionContent += `# ${itemTitle}\n`;
|
|
111
|
+
sectionContent += `**URL:** ${itemUrl}\n`;
|
|
112
|
+
if (nodeData.abstract || nodeData.summary) {
|
|
113
|
+
sectionContent += `**Abstract:** ${nodeData.abstract || nodeData.summary}\n`;
|
|
114
|
+
}
|
|
115
|
+
sectionContent += `\n`;
|
|
116
|
+
|
|
117
|
+
// Render all blocks on the node
|
|
118
|
+
const regions = pageData?.content || {};
|
|
119
|
+
let blockCount = 0;
|
|
120
|
+
|
|
121
|
+
Object.entries(regions).forEach(([regionName, blocks]) => {
|
|
122
|
+
if (!Array.isArray(blocks)) return;
|
|
123
|
+
|
|
124
|
+
blocks.forEach((block: any) => {
|
|
125
|
+
const data = block.data || {};
|
|
126
|
+
const renderedText = parseBlockText(data);
|
|
127
|
+
|
|
128
|
+
if (renderedText && renderedText.trim()) {
|
|
129
|
+
sectionContent += `${renderedText.trim()}\n\n`;
|
|
130
|
+
blockCount++;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
if (blockCount === 0) {
|
|
136
|
+
sectionContent += `*(No text content available for this node)*\n\n`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Recursively process child pages
|
|
140
|
+
if (Array.isArray(item.children) && item.children.length > 0) {
|
|
141
|
+
sectionContent += await processNodes(item.children, depth + 1);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return sectionContent;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
if (navTree.length > 0) {
|
|
149
|
+
fullText += await processNodes(navTree);
|
|
150
|
+
} else {
|
|
151
|
+
fullText += `\n---\n\n# Home\n**URL:** ${siteOrigin}\n\nNo additional pages found in navigation tree.\n`;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
fullText += `\n---\n*Generated dynamically by Kama Engine.*`;
|
|
155
|
+
|
|
156
|
+
return new Response(fullText, {
|
|
157
|
+
status: 200,
|
|
158
|
+
headers: {
|
|
159
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
160
|
+
"Cache-Control": "public, max-age=3600, s-maxage=86400"
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
} catch (error) {
|
|
165
|
+
console.error("[llms-full.txt Generator Error]:", error);
|
|
166
|
+
return new Response("# Error\nCould not generate full AI context corpus.", {
|
|
167
|
+
status: 500,
|
|
168
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// src/pages/llms.txt.ts
|
|
2
|
+
import type { APIRoute } from "astro";
|
|
3
|
+
import { getTree, getTreeId, getChannelId, getNodeByPath } from "../lib/cms";
|
|
4
|
+
|
|
5
|
+
// Ensure this route is dynamically rendered (SSR)
|
|
6
|
+
export const prerender = false;
|
|
7
|
+
|
|
8
|
+
export const GET: APIRoute = async (context) => {
|
|
9
|
+
// 1. Setup Cloudflare Worker Fetch Binding safely
|
|
10
|
+
const locals = (context.locals as any) || {};
|
|
11
|
+
const cfEnv = locals.cfContext?.env || {};
|
|
12
|
+
const cmsWorker = cfEnv.CMS_WORKER;
|
|
13
|
+
|
|
14
|
+
const envApiUrl = import.meta.env.PUBLIC_API_URL;
|
|
15
|
+
const workerApiUrl = cfEnv.PUBLIC_API_URL || (typeof process !== "undefined" ? process.env?.PUBLIC_API_URL : undefined);
|
|
16
|
+
const baseApiUrl = String(envApiUrl || workerApiUrl || "http://localhost:8787").replace(/\/$/, "");
|
|
17
|
+
|
|
18
|
+
const customFetch = async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
19
|
+
let urlStr = input instanceof URL ? input.toString() : String(input);
|
|
20
|
+
if (urlStr.startsWith("/")) urlStr = `${baseApiUrl}${urlStr}`;
|
|
21
|
+
|
|
22
|
+
const req = new Request(urlStr, init);
|
|
23
|
+
if (cmsWorker && typeof cmsWorker.fetch === "function") {
|
|
24
|
+
return cmsWorker.fetch(req);
|
|
25
|
+
}
|
|
26
|
+
return fetch(req);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// 2. Load keys from environment or fallback defaults
|
|
30
|
+
const channelId = getChannelId() || import.meta.env.PUBLIC_CHANNEL_ID || "main-channel";
|
|
31
|
+
const treeId = getTreeId() || import.meta.env.PUBLIC_TREE_ID || "main-tree";
|
|
32
|
+
|
|
33
|
+
// 🎯 Extract configurable fallback home slug
|
|
34
|
+
const envHomeSlug = import.meta.env.PUBLIC_HOME_SLUG;
|
|
35
|
+
const workerHomeSlug = cfEnv.PUBLIC_HOME_SLUG || (typeof process !== "undefined" ? process.env?.PUBLIC_HOME_SLUG : undefined);
|
|
36
|
+
const homeSlug = String(envHomeSlug || workerHomeSlug || "home").trim();
|
|
37
|
+
|
|
38
|
+
const rawOrigin = import.meta.env.PUBLIC_SITE_URL || context.url.origin;
|
|
39
|
+
const siteOrigin = String(rawOrigin).replace(/\/$/, "");
|
|
40
|
+
const brandName = import.meta.env.PUBLIC_SITE_NAME || "KAMA Starter";
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
// 3. Parallel fetch for Navigation Tree first to resolve root node slug
|
|
44
|
+
const rawNavTree = await getTree(treeId, channelId, customFetch).catch(() => []);
|
|
45
|
+
const navTree = Array.isArray(rawNavTree)
|
|
46
|
+
? rawNavTree
|
|
47
|
+
: (rawNavTree?.tree || rawNavTree?.items || rawNavTree?.data || []);
|
|
48
|
+
|
|
49
|
+
const rootTreeSlug = navTree.length > 0 ? (navTree[0].slug || navTree[0].key || "") : "";
|
|
50
|
+
const resolvedHomeSlug = rootTreeSlug || homeSlug;
|
|
51
|
+
|
|
52
|
+
// Fetch Home Node summary
|
|
53
|
+
const homeData = await getNodeByPath(resolvedHomeSlug, channelId, false, customFetch).catch(() => null);
|
|
54
|
+
|
|
55
|
+
const siteSummary = homeData?.node?.abstract || homeData?.node?.summary || "Global Content Delivery at the Edge";
|
|
56
|
+
|
|
57
|
+
// 4. Build standard-compliant llms.txt Markdown
|
|
58
|
+
let markdown = `# ${brandName}\n\n`;
|
|
59
|
+
markdown += `> ${siteSummary}\n\n`;
|
|
60
|
+
markdown += `This file serves as a structured directory for AI agents and language models.\n\n`;
|
|
61
|
+
markdown += `## Site Directory\n\n`;
|
|
62
|
+
|
|
63
|
+
// Recursive tree flattener with link annotations
|
|
64
|
+
const buildList = (nodes: any[], depth = 0) => {
|
|
65
|
+
let list = "";
|
|
66
|
+
const indent = " ".repeat(depth);
|
|
67
|
+
|
|
68
|
+
for (const item of nodes) {
|
|
69
|
+
const nodeData = item.node || item;
|
|
70
|
+
if (!nodeData || nodeData.isHidden) continue;
|
|
71
|
+
|
|
72
|
+
const itemSlug = nodeData.slug || nodeData.path || "";
|
|
73
|
+
const isRootItem = itemSlug === resolvedHomeSlug || itemSlug === "" || itemSlug === "/";
|
|
74
|
+
const itemUrl = isRootItem ? siteOrigin : `${siteOrigin}/${itemSlug.replace(/^\//, "")}`;
|
|
75
|
+
|
|
76
|
+
const itemTitle = nodeData.title || nodeData.label || nodeData.menuTitle || "Untitled";
|
|
77
|
+
const abstract = nodeData.abstract || nodeData.summary || nodeData.description;
|
|
78
|
+
const annotation = abstract ? `: ${abstract.trim()}` : "";
|
|
79
|
+
|
|
80
|
+
list += `${indent}- [${itemTitle}](${itemUrl})${annotation}\n`;
|
|
81
|
+
|
|
82
|
+
if (Array.isArray(item.children) && item.children.length > 0) {
|
|
83
|
+
list += buildList(item.children, depth + 1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return list;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
if (navTree.length > 0) {
|
|
90
|
+
markdown += buildList(navTree);
|
|
91
|
+
} else {
|
|
92
|
+
const homeTitle = homeData?.node?.title || brandName;
|
|
93
|
+
markdown += `- [${homeTitle}](${siteOrigin}): Main landing page.\n`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
markdown += `\n---\n*Generated dynamically by Kama Engine.*`;
|
|
97
|
+
|
|
98
|
+
return new Response(markdown, {
|
|
99
|
+
status: 200,
|
|
100
|
+
headers: {
|
|
101
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
102
|
+
"Cache-Control": "public, max-age=3600, s-maxage=86400"
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error("[llms.txt Generator Error]:", error);
|
|
108
|
+
return new Response("# Error\nCould not generate AI directory.", {
|
|
109
|
+
status: 500,
|
|
110
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/pages/media/[...path].ts
|
|
2
|
+
import type { APIRoute } from "astro";
|
|
3
|
+
import { handleMediaProxy } from "../../lib/media/media-proxy";
|
|
4
|
+
|
|
5
|
+
export const prerender = false;
|
|
6
|
+
|
|
7
|
+
export const GET: APIRoute = async (context) => {
|
|
8
|
+
try {
|
|
9
|
+
return await handleMediaProxy(context);
|
|
10
|
+
} catch (error: any) {
|
|
11
|
+
console.error("❌ [Media Proxy Error]:", error?.message || error);
|
|
12
|
+
return new Response("Media Proxy Failed", { status: 500 });
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
---
|
|
2
|
+
// src/pages/partials/footer.astro
|
|
3
|
+
export const partial = true;
|
|
4
|
+
|
|
5
|
+
import BlockRenderer from "@/components/blocks/BlockRenderer.astro";
|
|
6
|
+
import { getChannelId } from "@/lib/cms";
|
|
7
|
+
|
|
8
|
+
const safeEnv = (Astro.locals as any).safeEnv || {};
|
|
9
|
+
const cmsWorker = safeEnv.CMS_WORKER;
|
|
10
|
+
const channelId = getChannelId() || "website";
|
|
11
|
+
|
|
12
|
+
const customFetch = (input: RequestInfo | URL, init?: RequestInit) => {
|
|
13
|
+
const reqInit = { ...init };
|
|
14
|
+
delete reqInit.cache;
|
|
15
|
+
|
|
16
|
+
let urlStr = input instanceof URL ? input.toString() : String(input);
|
|
17
|
+
if (urlStr.startsWith("/")) {
|
|
18
|
+
const baseUrl =
|
|
19
|
+
import.meta.env.PUBLIC_API_URL ||
|
|
20
|
+
safeEnv.PUBLIC_API_URL ||
|
|
21
|
+
"http://127.0.0.1:8787";
|
|
22
|
+
urlStr = `${baseUrl}${urlStr}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const req = new Request(urlStr, reqInit);
|
|
26
|
+
if (cmsWorker && typeof cmsWorker.fetch === "function")
|
|
27
|
+
return cmsWorker.fetch(req);
|
|
28
|
+
return fetch(req);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// 🎯 Resolve the Home Page slug
|
|
32
|
+
const homeSlug = String(import.meta.env.PUBLIC_HOME_SLUG || "home").trim();
|
|
33
|
+
|
|
34
|
+
let footerBlocks: any[] = [];
|
|
35
|
+
let contentMap: Record<string, any[]> = {};
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
// 🎯 Fetch the Home Page node from Kama CMS Public API
|
|
39
|
+
const res = await customFetch(
|
|
40
|
+
`/api/v1/node/${homeSlug}?channelId=${channelId}`,
|
|
41
|
+
);
|
|
42
|
+
if (res.ok) {
|
|
43
|
+
const data = await res.json();
|
|
44
|
+
|
|
45
|
+
// Kama CMS public node endpoints usually organize blocks inside a 'content' object mapped by region
|
|
46
|
+
const allContent = data.content || {};
|
|
47
|
+
|
|
48
|
+
// Extract specifically the footer region from the Home page
|
|
49
|
+
footerBlocks = allContent.footer || [];
|
|
50
|
+
contentMap = allContent;
|
|
51
|
+
}
|
|
52
|
+
} catch (e) {
|
|
53
|
+
console.error("[Partials/Footer] Failed to fetch home page blocks:", e);
|
|
54
|
+
}
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
{
|
|
58
|
+
footerBlocks && footerBlocks.length > 0 ? (
|
|
59
|
+
<BlockRenderer
|
|
60
|
+
blocks={footerBlocks}
|
|
61
|
+
contentMap={contentMap}
|
|
62
|
+
region="footer"
|
|
63
|
+
/>
|
|
64
|
+
) : (
|
|
65
|
+
<div class="footer-default">
|
|
66
|
+
<p>© {new Date().getFullYear()} all rights reserved.</p>
|
|
67
|
+
</div>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
---
|
|
2
|
+
// src/pages/partials/nav.astro
|
|
3
|
+
export const partial = true; // 🎯 Tells Astro not to wrap this in <html><body>
|
|
4
|
+
|
|
5
|
+
import { getTree, getTreeId, getChannelId } from "@/lib/cms";
|
|
6
|
+
import type { TreeNode } from "@/lib/cms";
|
|
7
|
+
|
|
8
|
+
const safeEnv = (Astro.locals as any).safeEnv || {};
|
|
9
|
+
const cmsWorker = safeEnv.CMS_WORKER;
|
|
10
|
+
|
|
11
|
+
const customFetch = (input: RequestInfo | URL, init?: RequestInit) => {
|
|
12
|
+
const reqInit = { ...init };
|
|
13
|
+
delete reqInit.cache;
|
|
14
|
+
|
|
15
|
+
let urlStr = input instanceof URL ? input.toString() : String(input);
|
|
16
|
+
if (urlStr.startsWith("/")) {
|
|
17
|
+
const baseUrl =
|
|
18
|
+
import.meta.env.PUBLIC_API_URL ||
|
|
19
|
+
safeEnv.PUBLIC_API_URL ||
|
|
20
|
+
"http://127.0.0.1:8787";
|
|
21
|
+
urlStr = `${baseUrl}${urlStr}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const req = new Request(urlStr, reqInit);
|
|
25
|
+
if (cmsWorker && typeof cmsWorker.fetch === "function")
|
|
26
|
+
return cmsWorker.fetch(req);
|
|
27
|
+
return fetch(req);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Fetch fresh tree from CMS
|
|
31
|
+
const channelId = getChannelId() || "website";
|
|
32
|
+
const treeId = getTreeId() || "main-nav";
|
|
33
|
+
let tree: TreeNode[] = [];
|
|
34
|
+
try {
|
|
35
|
+
tree = (await getTree(treeId, channelId, customFetch)) || [];
|
|
36
|
+
} catch (e) {
|
|
37
|
+
console.error("[Partials/Nav] Failed to fetch tree:", e);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Get the current path from the client's fetch request
|
|
41
|
+
const currentPath =
|
|
42
|
+
(Astro.url.searchParams.get("path") || "/").replace(/\/$/, "") || "/";
|
|
43
|
+
const homeSlug = String(import.meta.env.PUBLIC_HOME_SLUG || "home").trim();
|
|
44
|
+
|
|
45
|
+
const homeNode = tree.find(
|
|
46
|
+
item =>
|
|
47
|
+
item.slug === homeSlug ||
|
|
48
|
+
item.slug === "" ||
|
|
49
|
+
item.path === "/" ||
|
|
50
|
+
item.path === "",
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const topLevelNavItems =
|
|
54
|
+
homeNode?.children && homeNode.children.length > 0
|
|
55
|
+
? homeNode.children
|
|
56
|
+
: tree.filter(
|
|
57
|
+
item =>
|
|
58
|
+
item.slug !== homeSlug &&
|
|
59
|
+
item.slug !== "" &&
|
|
60
|
+
item.path !== "/" &&
|
|
61
|
+
item.path !== "",
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const isPathActive = (itemPath?: string) => {
|
|
65
|
+
const normItem = (itemPath || "").replace(/\/$/, "") || "/";
|
|
66
|
+
if (normItem === "/") return currentPath === "/";
|
|
67
|
+
return currentPath === normItem || currentPath.startsWith(`${normItem}/`);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const isExactActive = (itemPath?: string) => {
|
|
71
|
+
return currentPath === ((itemPath || "").replace(/\/$/, "") || "/");
|
|
72
|
+
};
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
<ul class="nav-list">
|
|
76
|
+
{
|
|
77
|
+
topLevelNavItems.map(item => {
|
|
78
|
+
const hasChildren = item.children && item.children.length > 0;
|
|
79
|
+
const isParentActive = isPathActive(item.path);
|
|
80
|
+
|
|
81
|
+
if (hasChildren) {
|
|
82
|
+
return (
|
|
83
|
+
<li class="nav-item">
|
|
84
|
+
<details class="nav-details">
|
|
85
|
+
<summary
|
|
86
|
+
class:list={[
|
|
87
|
+
"nav-button",
|
|
88
|
+
"dropdown-summary",
|
|
89
|
+
{ active: isParentActive },
|
|
90
|
+
]}
|
|
91
|
+
>
|
|
92
|
+
<span>{item.title}</span>
|
|
93
|
+
<span class="indicator">▼</span>
|
|
94
|
+
</summary>
|
|
95
|
+
<div class="submenu-container">
|
|
96
|
+
<ul class="dropdown-panel">
|
|
97
|
+
<li>
|
|
98
|
+
<a
|
|
99
|
+
href={item.path}
|
|
100
|
+
class:list={[
|
|
101
|
+
"dropdown-item",
|
|
102
|
+
"overview-item",
|
|
103
|
+
{ active: isExactActive(item.path) },
|
|
104
|
+
]}
|
|
105
|
+
>
|
|
106
|
+
{item.title} Overview
|
|
107
|
+
</a>
|
|
108
|
+
</li>
|
|
109
|
+
{item.children?.map(child => (
|
|
110
|
+
<li>
|
|
111
|
+
<a
|
|
112
|
+
href={child.path}
|
|
113
|
+
class:list={[
|
|
114
|
+
"dropdown-item",
|
|
115
|
+
{ active: isExactActive(child.path) },
|
|
116
|
+
]}
|
|
117
|
+
>
|
|
118
|
+
{child.title}
|
|
119
|
+
</a>
|
|
120
|
+
</li>
|
|
121
|
+
))}
|
|
122
|
+
</ul>
|
|
123
|
+
</div>
|
|
124
|
+
</details>
|
|
125
|
+
</li>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<li class="nav-item">
|
|
131
|
+
<a
|
|
132
|
+
href={item.path}
|
|
133
|
+
class:list={["nav-button", { active: isExactActive(item.path) }]}
|
|
134
|
+
>
|
|
135
|
+
{item.title}
|
|
136
|
+
</a>
|
|
137
|
+
</li>
|
|
138
|
+
);
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
</ul>
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/* =======================================
|
|
2
|
+
1. GLOBAL RESETS & TYPOGRAPHY
|
|
3
|
+
======================================= */
|
|
4
|
+
*,
|
|
5
|
+
*::before,
|
|
6
|
+
*::after {
|
|
7
|
+
box-sizing: border-box;
|
|
8
|
+
border-radius: 0 !important;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
html {
|
|
12
|
+
font-size: 16px;
|
|
13
|
+
-webkit-text-size-adjust: 100%;
|
|
14
|
+
-webkit-font-smoothing: antialiased;
|
|
15
|
+
-moz-osx-font-smoothing: grayscale;
|
|
16
|
+
text-rendering: optimizeLegibility;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
body {
|
|
20
|
+
margin: 0;
|
|
21
|
+
padding: 0;
|
|
22
|
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
23
|
+
font-display: swap;
|
|
24
|
+
background-color: #ffffff;
|
|
25
|
+
color: #1e293b;
|
|
26
|
+
min-height: 100vh;
|
|
27
|
+
display: flex;
|
|
28
|
+
flex-direction: column;
|
|
29
|
+
line-height: 1.65;
|
|
30
|
+
letter-spacing: -0.011em;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
h1,
|
|
34
|
+
h2,
|
|
35
|
+
h3,
|
|
36
|
+
h4,
|
|
37
|
+
h5,
|
|
38
|
+
h6 {
|
|
39
|
+
color: #0f172a;
|
|
40
|
+
font-weight: 700;
|
|
41
|
+
line-height: 1.25;
|
|
42
|
+
letter-spacing: -0.022em;
|
|
43
|
+
margin-top: 1.6em;
|
|
44
|
+
margin-bottom: 0.6em;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
h1 {
|
|
48
|
+
font-size: 2.25rem;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
h2 {
|
|
52
|
+
font-size: 1.65rem;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
h3 {
|
|
56
|
+
font-size: 1.35rem;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
p {
|
|
60
|
+
margin-top: 0;
|
|
61
|
+
margin-bottom: 1.25em;
|
|
62
|
+
color: #334155;
|
|
63
|
+
font-size: 1.03rem;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
a {
|
|
67
|
+
color: #0284c7;
|
|
68
|
+
text-decoration-thickness: 1px;
|
|
69
|
+
text-underline-offset: 3px;
|
|
70
|
+
transition: color 0.15s ease;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
a:hover {
|
|
74
|
+
color: #0369a1;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
li>p:last-child {
|
|
78
|
+
margin-bottom: 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* =======================================
|
|
82
|
+
2. MAIN LAYOUT SHELL
|
|
83
|
+
======================================= */
|
|
84
|
+
.content-block {
|
|
85
|
+
flex: 1;
|
|
86
|
+
padding: 40px 0 64px 0;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.content-container {
|
|
90
|
+
max-width: 1400px;
|
|
91
|
+
margin: 0 auto;
|
|
92
|
+
padding: 0 24px;
|
|
93
|
+
width: 100%;
|
|
94
|
+
box-sizing: border-box;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/* =======================================
|
|
98
|
+
3. ROUTER REGIONS (from slug.astro)
|
|
99
|
+
======================================= */
|
|
100
|
+
.region-header {
|
|
101
|
+
margin-bottom: 24px;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.breadcrumb-wrapper {
|
|
105
|
+
margin-bottom: 24px;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.content-layout {
|
|
109
|
+
width: 100%;
|
|
110
|
+
display: block;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.main-column {
|
|
114
|
+
width: 100%;
|
|
115
|
+
min-width: 0;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@media (min-width: 768px) {
|
|
119
|
+
.content-layout.has-sidebar {
|
|
120
|
+
display: grid !important;
|
|
121
|
+
grid-template-columns: calc(100% - 360px) 310px !important;
|
|
122
|
+
column-gap: 48px !important;
|
|
123
|
+
align-items: start !important;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.main-column {
|
|
127
|
+
grid-column: 1 / 2 !important;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.sidebar-column {
|
|
131
|
+
grid-column: 2 / 3 !important;
|
|
132
|
+
position: sticky;
|
|
133
|
+
top: 32px;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.sidebar-column {
|
|
138
|
+
background: #f8fafc;
|
|
139
|
+
border: 1px solid #e2e8f0;
|
|
140
|
+
padding: 28px;
|
|
141
|
+
box-sizing: border-box;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
@media (max-width: 767px) {
|
|
145
|
+
.sidebar-column {
|
|
146
|
+
margin-top: 40px;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.empty-content {
|
|
151
|
+
padding: 32px;
|
|
152
|
+
border: 1px dashed #cbd5e1;
|
|
153
|
+
background: #f8fafc;
|
|
154
|
+
color: #64748b;
|
|
155
|
+
font-size: 0.95rem;
|
|
156
|
+
text-align: center;
|
|
157
|
+
}
|