@publish.os/nextjs 0.0.1-alpha.1
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 +7 -0
- package/dist/cache/tags.cjs +76 -0
- package/dist/cache/tags.d.cts +12 -0
- package/dist/cache/tags.d.ts +12 -0
- package/dist/cache/tags.js +51 -0
- package/dist/components/color-palette.cjs +408 -0
- package/dist/components/color-palette.d.cts +5 -0
- package/dist/components/color-palette.d.ts +5 -0
- package/dist/components/color-palette.js +388 -0
- package/dist/components/nav-breadcrumb.cjs +141 -0
- package/dist/components/nav-breadcrumb.d.cts +9 -0
- package/dist/components/nav-breadcrumb.d.ts +9 -0
- package/dist/components/nav-breadcrumb.js +107 -0
- package/dist/components/page-list.cjs +68 -0
- package/dist/components/page-list.d.cts +11 -0
- package/dist/components/page-list.d.ts +11 -0
- package/dist/components/page-list.js +33 -0
- package/dist/components/providers.cjs +44 -0
- package/dist/components/providers.d.cts +8 -0
- package/dist/components/providers.d.ts +8 -0
- package/dist/components/providers.js +20 -0
- package/dist/components/site-header.cjs +302 -0
- package/dist/components/site-header.d.cts +12 -0
- package/dist/components/site-header.d.ts +12 -0
- package/dist/components/site-header.js +268 -0
- package/dist/components/theme-toggle.cjs +147 -0
- package/dist/components/theme-toggle.d.cts +5 -0
- package/dist/components/theme-toggle.d.ts +5 -0
- package/dist/components/theme-toggle.js +123 -0
- package/dist/config/createNextConfig.cjs +52 -0
- package/dist/config/createNextConfig.d.cts +8 -0
- package/dist/config/createNextConfig.d.ts +8 -0
- package/dist/config/createNextConfig.js +27 -0
- package/dist/index.cjs +347 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +299 -0
- package/dist/layouts/group.cjs +157 -0
- package/dist/layouts/group.d.cts +15 -0
- package/dist/layouts/group.d.ts +15 -0
- package/dist/layouts/group.js +132 -0
- package/dist/mdx/error-boundary.cjs +94 -0
- package/dist/mdx/error-boundary.d.cts +13 -0
- package/dist/mdx/error-boundary.d.ts +13 -0
- package/dist/mdx/error-boundary.js +70 -0
- package/dist/mdx/error-fallback.cjs +58 -0
- package/dist/mdx/error-fallback.d.cts +9 -0
- package/dist/mdx/error-fallback.d.ts +9 -0
- package/dist/mdx/error-fallback.js +33 -0
- package/dist/mdx/mdx.cjs +182 -0
- package/dist/mdx/mdx.d.cts +10 -0
- package/dist/mdx/mdx.d.ts +10 -0
- package/dist/mdx/mdx.js +147 -0
- package/dist/pages/group.cjs +162 -0
- package/dist/pages/group.d.cts +15 -0
- package/dist/pages/group.d.ts +15 -0
- package/dist/pages/group.js +136 -0
- package/dist/pages/leaf.cjs +203 -0
- package/dist/pages/leaf.d.cts +23 -0
- package/dist/pages/leaf.d.ts +23 -0
- package/dist/pages/leaf.js +176 -0
- package/dist/pages/root.cjs +127 -0
- package/dist/pages/root.d.cts +14 -0
- package/dist/pages/root.d.ts +14 -0
- package/dist/pages/root.js +101 -0
- package/dist/resolvers/manifest-resolver.cjs +107 -0
- package/dist/resolvers/manifest-resolver.d.cts +13 -0
- package/dist/resolvers/manifest-resolver.d.ts +13 -0
- package/dist/resolvers/manifest-resolver.js +79 -0
- package/dist/routes/llms.cjs +101 -0
- package/dist/routes/llms.d.cts +7 -0
- package/dist/routes/llms.d.ts +7 -0
- package/dist/routes/llms.js +76 -0
- package/dist/routes/robots.cjs +94 -0
- package/dist/routes/robots.d.cts +5 -0
- package/dist/routes/robots.d.ts +5 -0
- package/dist/routes/robots.js +69 -0
- package/dist/routes/sitemap.cjs +108 -0
- package/dist/routes/sitemap.d.cts +5 -0
- package/dist/routes/sitemap.d.ts +5 -0
- package/dist/routes/sitemap.js +83 -0
- package/dist/types.cjs +18 -0
- package/dist/types.d.cts +144 -0
- package/dist/types.d.ts +144 -0
- package/dist/types.js +0 -0
- package/dist/utils/cn.cjs +49 -0
- package/dist/utils/cn.d.cts +15 -0
- package/dist/utils/cn.d.ts +15 -0
- package/dist/utils/cn.js +24 -0
- package/dist/utils/pretty-date.cjs +55 -0
- package/dist/utils/pretty-date.d.cts +6 -0
- package/dist/utils/pretty-date.d.ts +6 -0
- package/dist/utils/pretty-date.js +30 -0
- package/package.json +100 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/resolvers/manifest-resolver.ts
|
|
21
|
+
var manifest_resolver_exports = {};
|
|
22
|
+
__export(manifest_resolver_exports, {
|
|
23
|
+
listStaticParams: () => listStaticParams,
|
|
24
|
+
resolveGroup: () => resolveGroup,
|
|
25
|
+
resolveGroupLayout: () => resolveGroupLayout,
|
|
26
|
+
resolveLeaf: () => resolveLeaf
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(manifest_resolver_exports);
|
|
29
|
+
function findNodeInTree(nodes, id) {
|
|
30
|
+
for (const node of nodes) {
|
|
31
|
+
if (node.id === id) return node;
|
|
32
|
+
if (node.type === "section" || node.type === "folder") {
|
|
33
|
+
const found = findNodeInTree(node.children, id);
|
|
34
|
+
if (found) return found;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
function pageNode(page) {
|
|
40
|
+
return {
|
|
41
|
+
type: "page",
|
|
42
|
+
id: page.id,
|
|
43
|
+
title: page.title,
|
|
44
|
+
path: page.path,
|
|
45
|
+
group: page.group,
|
|
46
|
+
description: page.description,
|
|
47
|
+
status: page.status,
|
|
48
|
+
publishedAt: page.publishedAt,
|
|
49
|
+
updatedAt: page.updatedAt,
|
|
50
|
+
authors: page.authors,
|
|
51
|
+
tags: page.tags,
|
|
52
|
+
meta: page.meta
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function groupNode(group) {
|
|
56
|
+
return {
|
|
57
|
+
type: "section",
|
|
58
|
+
id: group.key,
|
|
59
|
+
title: group.title,
|
|
60
|
+
path: group.path,
|
|
61
|
+
group: group.key,
|
|
62
|
+
children: group.tree
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function resolveLeaf(manifest, group, slug) {
|
|
66
|
+
const slugPath = Array.isArray(slug) ? slug.join("/") : slug;
|
|
67
|
+
const page = manifest.pages.find((p) => p.group === group && p.slug === slugPath) ?? null;
|
|
68
|
+
if (!page) return null;
|
|
69
|
+
const groupData = manifest.groups[group];
|
|
70
|
+
if (!groupData) return null;
|
|
71
|
+
return {
|
|
72
|
+
site: manifest.site,
|
|
73
|
+
tree: groupData.tree,
|
|
74
|
+
node: findNodeInTree(groupData.tree, page.id) ?? pageNode(page),
|
|
75
|
+
page,
|
|
76
|
+
currentPath: page.path,
|
|
77
|
+
group
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function resolveGroup(manifest, group) {
|
|
81
|
+
const groupData = manifest.groups[group];
|
|
82
|
+
if (!groupData) return null;
|
|
83
|
+
return {
|
|
84
|
+
site: manifest.site,
|
|
85
|
+
tree: groupData.tree,
|
|
86
|
+
node: groupNode(groupData),
|
|
87
|
+
currentPath: groupData.path,
|
|
88
|
+
group
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function resolveGroupLayout(manifest, group, children) {
|
|
92
|
+
const resolved = resolveGroup(manifest, group);
|
|
93
|
+
if (!resolved) return null;
|
|
94
|
+
return { ...resolved, children };
|
|
95
|
+
}
|
|
96
|
+
function listStaticParams(manifest, group) {
|
|
97
|
+
const groupData = manifest.groups[group];
|
|
98
|
+
if (!groupData) return [];
|
|
99
|
+
return groupData.pages.map((page) => ({ slug: page.slug.split("/") }));
|
|
100
|
+
}
|
|
101
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
102
|
+
0 && (module.exports = {
|
|
103
|
+
listStaticParams,
|
|
104
|
+
resolveGroup,
|
|
105
|
+
resolveGroupLayout,
|
|
106
|
+
resolveLeaf
|
|
107
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ManifestLike, IndexPageProps, LayoutProps, PageProps } from '../types.cjs';
|
|
3
|
+
|
|
4
|
+
type ResolvedLeaf = PageProps;
|
|
5
|
+
type ResolvedGroup = Omit<IndexPageProps, "children">;
|
|
6
|
+
declare function resolveLeaf(manifest: ManifestLike, group: string, slug: string | string[]): ResolvedLeaf | null;
|
|
7
|
+
declare function resolveGroup(manifest: ManifestLike, group: string): ResolvedGroup | null;
|
|
8
|
+
declare function resolveGroupLayout(manifest: ManifestLike, group: string, children: React.ReactNode): LayoutProps | null;
|
|
9
|
+
declare function listStaticParams(manifest: ManifestLike, group: string): Array<{
|
|
10
|
+
slug: string[];
|
|
11
|
+
}>;
|
|
12
|
+
|
|
13
|
+
export { type ResolvedGroup, type ResolvedLeaf, listStaticParams, resolveGroup, resolveGroupLayout, resolveLeaf };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ManifestLike, IndexPageProps, LayoutProps, PageProps } from '../types.js';
|
|
3
|
+
|
|
4
|
+
type ResolvedLeaf = PageProps;
|
|
5
|
+
type ResolvedGroup = Omit<IndexPageProps, "children">;
|
|
6
|
+
declare function resolveLeaf(manifest: ManifestLike, group: string, slug: string | string[]): ResolvedLeaf | null;
|
|
7
|
+
declare function resolveGroup(manifest: ManifestLike, group: string): ResolvedGroup | null;
|
|
8
|
+
declare function resolveGroupLayout(manifest: ManifestLike, group: string, children: React.ReactNode): LayoutProps | null;
|
|
9
|
+
declare function listStaticParams(manifest: ManifestLike, group: string): Array<{
|
|
10
|
+
slug: string[];
|
|
11
|
+
}>;
|
|
12
|
+
|
|
13
|
+
export { type ResolvedGroup, type ResolvedLeaf, listStaticParams, resolveGroup, resolveGroupLayout, resolveLeaf };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// src/resolvers/manifest-resolver.ts
|
|
2
|
+
function findNodeInTree(nodes, id) {
|
|
3
|
+
for (const node of nodes) {
|
|
4
|
+
if (node.id === id) return node;
|
|
5
|
+
if (node.type === "section" || node.type === "folder") {
|
|
6
|
+
const found = findNodeInTree(node.children, id);
|
|
7
|
+
if (found) return found;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
function pageNode(page) {
|
|
13
|
+
return {
|
|
14
|
+
type: "page",
|
|
15
|
+
id: page.id,
|
|
16
|
+
title: page.title,
|
|
17
|
+
path: page.path,
|
|
18
|
+
group: page.group,
|
|
19
|
+
description: page.description,
|
|
20
|
+
status: page.status,
|
|
21
|
+
publishedAt: page.publishedAt,
|
|
22
|
+
updatedAt: page.updatedAt,
|
|
23
|
+
authors: page.authors,
|
|
24
|
+
tags: page.tags,
|
|
25
|
+
meta: page.meta
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function groupNode(group) {
|
|
29
|
+
return {
|
|
30
|
+
type: "section",
|
|
31
|
+
id: group.key,
|
|
32
|
+
title: group.title,
|
|
33
|
+
path: group.path,
|
|
34
|
+
group: group.key,
|
|
35
|
+
children: group.tree
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function resolveLeaf(manifest, group, slug) {
|
|
39
|
+
const slugPath = Array.isArray(slug) ? slug.join("/") : slug;
|
|
40
|
+
const page = manifest.pages.find((p) => p.group === group && p.slug === slugPath) ?? null;
|
|
41
|
+
if (!page) return null;
|
|
42
|
+
const groupData = manifest.groups[group];
|
|
43
|
+
if (!groupData) return null;
|
|
44
|
+
return {
|
|
45
|
+
site: manifest.site,
|
|
46
|
+
tree: groupData.tree,
|
|
47
|
+
node: findNodeInTree(groupData.tree, page.id) ?? pageNode(page),
|
|
48
|
+
page,
|
|
49
|
+
currentPath: page.path,
|
|
50
|
+
group
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function resolveGroup(manifest, group) {
|
|
54
|
+
const groupData = manifest.groups[group];
|
|
55
|
+
if (!groupData) return null;
|
|
56
|
+
return {
|
|
57
|
+
site: manifest.site,
|
|
58
|
+
tree: groupData.tree,
|
|
59
|
+
node: groupNode(groupData),
|
|
60
|
+
currentPath: groupData.path,
|
|
61
|
+
group
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function resolveGroupLayout(manifest, group, children) {
|
|
65
|
+
const resolved = resolveGroup(manifest, group);
|
|
66
|
+
if (!resolved) return null;
|
|
67
|
+
return { ...resolved, children };
|
|
68
|
+
}
|
|
69
|
+
function listStaticParams(manifest, group) {
|
|
70
|
+
const groupData = manifest.groups[group];
|
|
71
|
+
if (!groupData) return [];
|
|
72
|
+
return groupData.pages.map((page) => ({ slug: page.slug.split("/") }));
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
listStaticParams,
|
|
76
|
+
resolveGroup,
|
|
77
|
+
resolveGroupLayout,
|
|
78
|
+
resolveLeaf
|
|
79
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/routes/llms.ts
|
|
21
|
+
var llms_exports = {};
|
|
22
|
+
__export(llms_exports, {
|
|
23
|
+
createLlmsTxtRoute: () => createLlmsTxtRoute
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(llms_exports);
|
|
26
|
+
var import_cache = require("next/cache");
|
|
27
|
+
|
|
28
|
+
// src/cache/tags.ts
|
|
29
|
+
var import_node_crypto = require("crypto");
|
|
30
|
+
var MAX_TAG_LEN = 256;
|
|
31
|
+
var MAX_SEGMENT_LEN = 80;
|
|
32
|
+
var TAG_PATTERN = /^[a-z0-9:_./-]+$/;
|
|
33
|
+
function sha256(value) {
|
|
34
|
+
return (0, import_node_crypto.createHash)("sha256").update(value).digest("hex").slice(0, 16);
|
|
35
|
+
}
|
|
36
|
+
function safeSegment(value) {
|
|
37
|
+
const raw = value.trim().toLowerCase() || "root";
|
|
38
|
+
const normalized = raw.replace(/\\/g, "/").replace(/\/+/g, "/").replace(/^\//, "").replace(/\/$/, "").replace(/[^a-z0-9:_./-]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
39
|
+
const segment = normalized || "root";
|
|
40
|
+
if (segment.length <= MAX_SEGMENT_LEN) return segment;
|
|
41
|
+
return `${segment.slice(0, 48)}.${sha256(segment)}`;
|
|
42
|
+
}
|
|
43
|
+
function assertTag(tag) {
|
|
44
|
+
if (tag.length > MAX_TAG_LEN || !TAG_PATTERN.test(tag)) {
|
|
45
|
+
return `tag:${sha256(tag)}`;
|
|
46
|
+
}
|
|
47
|
+
return tag;
|
|
48
|
+
}
|
|
49
|
+
var tags = {
|
|
50
|
+
site() {
|
|
51
|
+
return "site";
|
|
52
|
+
},
|
|
53
|
+
pages() {
|
|
54
|
+
return "pages";
|
|
55
|
+
},
|
|
56
|
+
group(group) {
|
|
57
|
+
return assertTag(`group:${safeSegment(group)}`);
|
|
58
|
+
},
|
|
59
|
+
page(group, slug) {
|
|
60
|
+
const path = Array.isArray(slug) ? slug.join("/") : slug;
|
|
61
|
+
return assertTag(`page:${safeSegment(group)}:${safeSegment(path)}`);
|
|
62
|
+
},
|
|
63
|
+
manifest(contentHash) {
|
|
64
|
+
return assertTag(`manifest:${safeSegment(contentHash)}`);
|
|
65
|
+
},
|
|
66
|
+
sitemap() {
|
|
67
|
+
return "sitemap";
|
|
68
|
+
},
|
|
69
|
+
robots() {
|
|
70
|
+
return "robots";
|
|
71
|
+
},
|
|
72
|
+
llms(scope = "root") {
|
|
73
|
+
return assertTag(`llms:${safeSegment(scope)}`);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/routes/llms.ts
|
|
78
|
+
async function llmsTxt(manifest, scope = "root") {
|
|
79
|
+
"use cache";
|
|
80
|
+
(0, import_cache.cacheLife)("page");
|
|
81
|
+
(0, import_cache.cacheTag)(tags.site(), tags.llms(scope), tags.manifest(manifest.contentHash));
|
|
82
|
+
const pages = manifest.pages.filter(
|
|
83
|
+
(page) => page.status === "published" && (scope === "root" || page.group === scope)
|
|
84
|
+
);
|
|
85
|
+
const lines = pages.map((page) => `- [${page.title}](${page.path})`);
|
|
86
|
+
return `# ${manifest.site.title}
|
|
87
|
+
|
|
88
|
+
${lines.join("\n")}
|
|
89
|
+
`;
|
|
90
|
+
}
|
|
91
|
+
function createLlmsTxtRoute(manifest, options = {}) {
|
|
92
|
+
return async function GET() {
|
|
93
|
+
return new Response(await llmsTxt(manifest, options.scope), {
|
|
94
|
+
headers: { "content-type": "text/plain; charset=utf-8" }
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
createLlmsTxtRoute
|
|
101
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// src/routes/llms.ts
|
|
2
|
+
import { cacheLife, cacheTag } from "next/cache";
|
|
3
|
+
|
|
4
|
+
// src/cache/tags.ts
|
|
5
|
+
import { createHash } from "crypto";
|
|
6
|
+
var MAX_TAG_LEN = 256;
|
|
7
|
+
var MAX_SEGMENT_LEN = 80;
|
|
8
|
+
var TAG_PATTERN = /^[a-z0-9:_./-]+$/;
|
|
9
|
+
function sha256(value) {
|
|
10
|
+
return createHash("sha256").update(value).digest("hex").slice(0, 16);
|
|
11
|
+
}
|
|
12
|
+
function safeSegment(value) {
|
|
13
|
+
const raw = value.trim().toLowerCase() || "root";
|
|
14
|
+
const normalized = raw.replace(/\\/g, "/").replace(/\/+/g, "/").replace(/^\//, "").replace(/\/$/, "").replace(/[^a-z0-9:_./-]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
15
|
+
const segment = normalized || "root";
|
|
16
|
+
if (segment.length <= MAX_SEGMENT_LEN) return segment;
|
|
17
|
+
return `${segment.slice(0, 48)}.${sha256(segment)}`;
|
|
18
|
+
}
|
|
19
|
+
function assertTag(tag) {
|
|
20
|
+
if (tag.length > MAX_TAG_LEN || !TAG_PATTERN.test(tag)) {
|
|
21
|
+
return `tag:${sha256(tag)}`;
|
|
22
|
+
}
|
|
23
|
+
return tag;
|
|
24
|
+
}
|
|
25
|
+
var tags = {
|
|
26
|
+
site() {
|
|
27
|
+
return "site";
|
|
28
|
+
},
|
|
29
|
+
pages() {
|
|
30
|
+
return "pages";
|
|
31
|
+
},
|
|
32
|
+
group(group) {
|
|
33
|
+
return assertTag(`group:${safeSegment(group)}`);
|
|
34
|
+
},
|
|
35
|
+
page(group, slug) {
|
|
36
|
+
const path = Array.isArray(slug) ? slug.join("/") : slug;
|
|
37
|
+
return assertTag(`page:${safeSegment(group)}:${safeSegment(path)}`);
|
|
38
|
+
},
|
|
39
|
+
manifest(contentHash) {
|
|
40
|
+
return assertTag(`manifest:${safeSegment(contentHash)}`);
|
|
41
|
+
},
|
|
42
|
+
sitemap() {
|
|
43
|
+
return "sitemap";
|
|
44
|
+
},
|
|
45
|
+
robots() {
|
|
46
|
+
return "robots";
|
|
47
|
+
},
|
|
48
|
+
llms(scope = "root") {
|
|
49
|
+
return assertTag(`llms:${safeSegment(scope)}`);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/routes/llms.ts
|
|
54
|
+
async function llmsTxt(manifest, scope = "root") {
|
|
55
|
+
"use cache";
|
|
56
|
+
cacheLife("page");
|
|
57
|
+
cacheTag(tags.site(), tags.llms(scope), tags.manifest(manifest.contentHash));
|
|
58
|
+
const pages = manifest.pages.filter(
|
|
59
|
+
(page) => page.status === "published" && (scope === "root" || page.group === scope)
|
|
60
|
+
);
|
|
61
|
+
const lines = pages.map((page) => `- [${page.title}](${page.path})`);
|
|
62
|
+
return `# ${manifest.site.title}
|
|
63
|
+
|
|
64
|
+
${lines.join("\n")}
|
|
65
|
+
`;
|
|
66
|
+
}
|
|
67
|
+
function createLlmsTxtRoute(manifest, options = {}) {
|
|
68
|
+
return async function GET() {
|
|
69
|
+
return new Response(await llmsTxt(manifest, options.scope), {
|
|
70
|
+
headers: { "content-type": "text/plain; charset=utf-8" }
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
createLlmsTxtRoute
|
|
76
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/routes/robots.ts
|
|
21
|
+
var robots_exports = {};
|
|
22
|
+
__export(robots_exports, {
|
|
23
|
+
createRobotsTxtRoute: () => createRobotsTxtRoute
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(robots_exports);
|
|
26
|
+
var import_cache = require("next/cache");
|
|
27
|
+
|
|
28
|
+
// src/cache/tags.ts
|
|
29
|
+
var import_node_crypto = require("crypto");
|
|
30
|
+
var MAX_TAG_LEN = 256;
|
|
31
|
+
var MAX_SEGMENT_LEN = 80;
|
|
32
|
+
var TAG_PATTERN = /^[a-z0-9:_./-]+$/;
|
|
33
|
+
function sha256(value) {
|
|
34
|
+
return (0, import_node_crypto.createHash)("sha256").update(value).digest("hex").slice(0, 16);
|
|
35
|
+
}
|
|
36
|
+
function safeSegment(value) {
|
|
37
|
+
const raw = value.trim().toLowerCase() || "root";
|
|
38
|
+
const normalized = raw.replace(/\\/g, "/").replace(/\/+/g, "/").replace(/^\//, "").replace(/\/$/, "").replace(/[^a-z0-9:_./-]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
39
|
+
const segment = normalized || "root";
|
|
40
|
+
if (segment.length <= MAX_SEGMENT_LEN) return segment;
|
|
41
|
+
return `${segment.slice(0, 48)}.${sha256(segment)}`;
|
|
42
|
+
}
|
|
43
|
+
function assertTag(tag) {
|
|
44
|
+
if (tag.length > MAX_TAG_LEN || !TAG_PATTERN.test(tag)) {
|
|
45
|
+
return `tag:${sha256(tag)}`;
|
|
46
|
+
}
|
|
47
|
+
return tag;
|
|
48
|
+
}
|
|
49
|
+
var tags = {
|
|
50
|
+
site() {
|
|
51
|
+
return "site";
|
|
52
|
+
},
|
|
53
|
+
pages() {
|
|
54
|
+
return "pages";
|
|
55
|
+
},
|
|
56
|
+
group(group) {
|
|
57
|
+
return assertTag(`group:${safeSegment(group)}`);
|
|
58
|
+
},
|
|
59
|
+
page(group, slug) {
|
|
60
|
+
const path = Array.isArray(slug) ? slug.join("/") : slug;
|
|
61
|
+
return assertTag(`page:${safeSegment(group)}:${safeSegment(path)}`);
|
|
62
|
+
},
|
|
63
|
+
manifest(contentHash) {
|
|
64
|
+
return assertTag(`manifest:${safeSegment(contentHash)}`);
|
|
65
|
+
},
|
|
66
|
+
sitemap() {
|
|
67
|
+
return "sitemap";
|
|
68
|
+
},
|
|
69
|
+
robots() {
|
|
70
|
+
return "robots";
|
|
71
|
+
},
|
|
72
|
+
llms(scope = "root") {
|
|
73
|
+
return assertTag(`llms:${safeSegment(scope)}`);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/routes/robots.ts
|
|
78
|
+
async function robotsTxt(manifest) {
|
|
79
|
+
"use cache";
|
|
80
|
+
(0, import_cache.cacheLife)("page");
|
|
81
|
+
(0, import_cache.cacheTag)(tags.site(), tags.robots(), tags.manifest(manifest.contentHash));
|
|
82
|
+
return "User-agent: *\nAllow: /\nSitemap: /sitemap.xml\n";
|
|
83
|
+
}
|
|
84
|
+
function createRobotsTxtRoute(manifest) {
|
|
85
|
+
return async function GET() {
|
|
86
|
+
return new Response(await robotsTxt(manifest), {
|
|
87
|
+
headers: { "content-type": "text/plain; charset=utf-8" }
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
+
0 && (module.exports = {
|
|
93
|
+
createRobotsTxtRoute
|
|
94
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// src/routes/robots.ts
|
|
2
|
+
import { cacheLife, cacheTag } from "next/cache";
|
|
3
|
+
|
|
4
|
+
// src/cache/tags.ts
|
|
5
|
+
import { createHash } from "crypto";
|
|
6
|
+
var MAX_TAG_LEN = 256;
|
|
7
|
+
var MAX_SEGMENT_LEN = 80;
|
|
8
|
+
var TAG_PATTERN = /^[a-z0-9:_./-]+$/;
|
|
9
|
+
function sha256(value) {
|
|
10
|
+
return createHash("sha256").update(value).digest("hex").slice(0, 16);
|
|
11
|
+
}
|
|
12
|
+
function safeSegment(value) {
|
|
13
|
+
const raw = value.trim().toLowerCase() || "root";
|
|
14
|
+
const normalized = raw.replace(/\\/g, "/").replace(/\/+/g, "/").replace(/^\//, "").replace(/\/$/, "").replace(/[^a-z0-9:_./-]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
15
|
+
const segment = normalized || "root";
|
|
16
|
+
if (segment.length <= MAX_SEGMENT_LEN) return segment;
|
|
17
|
+
return `${segment.slice(0, 48)}.${sha256(segment)}`;
|
|
18
|
+
}
|
|
19
|
+
function assertTag(tag) {
|
|
20
|
+
if (tag.length > MAX_TAG_LEN || !TAG_PATTERN.test(tag)) {
|
|
21
|
+
return `tag:${sha256(tag)}`;
|
|
22
|
+
}
|
|
23
|
+
return tag;
|
|
24
|
+
}
|
|
25
|
+
var tags = {
|
|
26
|
+
site() {
|
|
27
|
+
return "site";
|
|
28
|
+
},
|
|
29
|
+
pages() {
|
|
30
|
+
return "pages";
|
|
31
|
+
},
|
|
32
|
+
group(group) {
|
|
33
|
+
return assertTag(`group:${safeSegment(group)}`);
|
|
34
|
+
},
|
|
35
|
+
page(group, slug) {
|
|
36
|
+
const path = Array.isArray(slug) ? slug.join("/") : slug;
|
|
37
|
+
return assertTag(`page:${safeSegment(group)}:${safeSegment(path)}`);
|
|
38
|
+
},
|
|
39
|
+
manifest(contentHash) {
|
|
40
|
+
return assertTag(`manifest:${safeSegment(contentHash)}`);
|
|
41
|
+
},
|
|
42
|
+
sitemap() {
|
|
43
|
+
return "sitemap";
|
|
44
|
+
},
|
|
45
|
+
robots() {
|
|
46
|
+
return "robots";
|
|
47
|
+
},
|
|
48
|
+
llms(scope = "root") {
|
|
49
|
+
return assertTag(`llms:${safeSegment(scope)}`);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/routes/robots.ts
|
|
54
|
+
async function robotsTxt(manifest) {
|
|
55
|
+
"use cache";
|
|
56
|
+
cacheLife("page");
|
|
57
|
+
cacheTag(tags.site(), tags.robots(), tags.manifest(manifest.contentHash));
|
|
58
|
+
return "User-agent: *\nAllow: /\nSitemap: /sitemap.xml\n";
|
|
59
|
+
}
|
|
60
|
+
function createRobotsTxtRoute(manifest) {
|
|
61
|
+
return async function GET() {
|
|
62
|
+
return new Response(await robotsTxt(manifest), {
|
|
63
|
+
headers: { "content-type": "text/plain; charset=utf-8" }
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
createRobotsTxtRoute
|
|
69
|
+
};
|