@clarify-labs/cli 0.6.7 → 0.7.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/output/cli.cjs +5 -4
- package/output/cli.cjs.map +1 -1
- package/output/cli.js +5 -4
- package/output/cli.js.map +1 -1
- package/output/core/config-schema.d.ts +37 -8
- package/output/core/search-language.d.ts +1 -0
- package/output/core/ssg.d.ts +1 -1
- package/output/core/temp-dir.d.ts +2 -0
- package/output/core/theme.d.ts +2 -52
- package/output/core/virtual-modules.d.ts +10 -1
- package/output/index.cjs +1 -1
- package/output/index.js +1 -1
- package/output/{plugin-hJcy-YdO.cjs → plugin-DFpkIm9j.cjs} +231 -70
- package/output/plugin-DFpkIm9j.cjs.map +1 -0
- package/output/{plugin-Cx9lFenc.js → plugin-o1rP_gts.js} +228 -73
- package/output/plugin-o1rP_gts.js.map +1 -0
- package/output/plugins/openapi/virtual-modules.d.ts +1 -1
- package/output/plugins/search-index/index.d.ts +2 -0
- package/output/types.d.ts +10 -2
- package/package.json +5 -3
- package/output/plugin-Cx9lFenc.js.map +0 -1
- package/output/plugin-hJcy-YdO.cjs.map +0 -1
package/output/core/theme.d.ts
CHANGED
|
@@ -1,54 +1,4 @@
|
|
|
1
|
+
import { themePresets } from '@clarify-labs/renderer';
|
|
1
2
|
import { ClarifyThemeConfig, ResolvedClarifyThemeConfig } from '../types.js';
|
|
2
|
-
export
|
|
3
|
-
readonly default: {
|
|
4
|
-
readonly preset: "default";
|
|
5
|
-
readonly tokens: {
|
|
6
|
-
readonly colors: {
|
|
7
|
-
readonly primary: "#047857";
|
|
8
|
-
readonly accent: "#0D9488";
|
|
9
|
-
readonly background: "#ffffff";
|
|
10
|
-
readonly foreground: "#111827";
|
|
11
|
-
readonly surface: "#ffffff";
|
|
12
|
-
readonly muted: "#64748b";
|
|
13
|
-
readonly border: "rgb(15 23 42 / 0.12)";
|
|
14
|
-
readonly codeBackground: "#f6fbf8";
|
|
15
|
-
};
|
|
16
|
-
readonly radius: {
|
|
17
|
-
readonly sm: "6px";
|
|
18
|
-
readonly md: "10px";
|
|
19
|
-
readonly lg: "14px";
|
|
20
|
-
readonly xl: "18px";
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
readonly layout: {
|
|
24
|
-
readonly maxWidth: "82rem";
|
|
25
|
-
};
|
|
26
|
-
readonly editor: false;
|
|
27
|
-
};
|
|
28
|
-
readonly base: {
|
|
29
|
-
readonly preset: "base";
|
|
30
|
-
readonly tokens: {
|
|
31
|
-
readonly colors: {
|
|
32
|
-
readonly primary: "#18181b";
|
|
33
|
-
readonly accent: "#52525b";
|
|
34
|
-
readonly background: "#ffffff";
|
|
35
|
-
readonly foreground: "#18181b";
|
|
36
|
-
readonly surface: "#ffffff";
|
|
37
|
-
readonly muted: "#71717a";
|
|
38
|
-
readonly border: "rgb(24 24 27 / 0.12)";
|
|
39
|
-
readonly codeBackground: "#f4f4f5";
|
|
40
|
-
};
|
|
41
|
-
readonly radius: {
|
|
42
|
-
readonly sm: "6px";
|
|
43
|
-
readonly md: "8px";
|
|
44
|
-
readonly lg: "12px";
|
|
45
|
-
readonly xl: "16px";
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
readonly layout: {
|
|
49
|
-
readonly maxWidth: "80rem";
|
|
50
|
-
};
|
|
51
|
-
readonly editor: false;
|
|
52
|
-
};
|
|
53
|
-
};
|
|
3
|
+
export { themePresets };
|
|
54
4
|
export declare function resolveThemeConfig(theme?: ClarifyThemeConfig): ResolvedClarifyThemeConfig;
|
|
@@ -6,6 +6,15 @@ export declare const VIRTUAL_RUNTIME = "virtual:clarify-runtime";
|
|
|
6
6
|
export declare const VIRTUAL_CLIENT_ENTRY = "virtual:clarify-entry-client";
|
|
7
7
|
export declare const RESOLVED_CLIENT_ENTRY: string;
|
|
8
8
|
export type VirtualModules = Map<string, string>;
|
|
9
|
+
type RuntimeImports = {
|
|
10
|
+
bannerComponent?: string;
|
|
11
|
+
footerComponent?: string;
|
|
12
|
+
};
|
|
13
|
+
type RuntimeModuleOptions = {
|
|
14
|
+
imports?: RuntimeImports;
|
|
15
|
+
bannerComponentSource?: 'path';
|
|
16
|
+
footerComponentSource?: 'path';
|
|
17
|
+
};
|
|
9
18
|
type BuildVirtualModulesArgs = {
|
|
10
19
|
projectConfig: ResolvedProjectConfig;
|
|
11
20
|
generateOptions: ResolvedBuildOptions;
|
|
@@ -20,7 +29,7 @@ export declare function resolveVirtualId(id: string): string;
|
|
|
20
29
|
export declare function stripVirtualPrefix(id: string): string;
|
|
21
30
|
export declare function generateConfigModule(projectConfig: ResolvedProjectConfig, buildOptions: ResolvedBuildOptions): string;
|
|
22
31
|
export declare function generateRoutesModule(routes: ContentRoute[], resolvedNavigation?: NavigationTree, projectConfig?: ResolvedProjectConfig, mode?: 'client' | 'server'): string;
|
|
23
|
-
export declare function createRuntimeModule(): string;
|
|
32
|
+
export declare function createRuntimeModule(options?: RuntimeModuleOptions): string;
|
|
24
33
|
export declare function createClientEntryModule(options?: CreateClientEntryModuleOptions): string;
|
|
25
34
|
export declare function buildVirtualModules(args: BuildVirtualModulesArgs): VirtualModules;
|
|
26
35
|
export {};
|
package/output/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_plugin = require("./plugin-
|
|
2
|
+
const require_plugin = require("./plugin-DFpkIm9j.cjs");
|
|
3
3
|
exports.clarifyPlugin = require_plugin.clarifyPlugin;
|
|
4
4
|
exports.defineConfig = require_plugin.defineConfig;
|
package/output/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as defineConfig, t as clarifyPlugin } from "./plugin-
|
|
1
|
+
import { n as defineConfig, t as clarifyPlugin } from "./plugin-o1rP_gts.js";
|
|
2
2
|
export { clarifyPlugin, defineConfig };
|
|
@@ -40,9 +40,9 @@ let gray_matter = require("gray-matter");
|
|
|
40
40
|
gray_matter = __toESM(gray_matter, 1);
|
|
41
41
|
let _apidevtools_swagger_parser = require("@apidevtools/swagger-parser");
|
|
42
42
|
_apidevtools_swagger_parser = __toESM(_apidevtools_swagger_parser, 1);
|
|
43
|
+
let node_os = require("node:os");
|
|
43
44
|
let node_fs_promises = require("node:fs/promises");
|
|
44
45
|
let zod = require("zod");
|
|
45
|
-
let node_os = require("node:os");
|
|
46
46
|
let node_url = require("node:url");
|
|
47
47
|
let vite = require("vite");
|
|
48
48
|
let node_module = require("node:module");
|
|
@@ -262,7 +262,6 @@ function createContentArtifactsPlugin() {
|
|
|
262
262
|
}
|
|
263
263
|
//#endregion
|
|
264
264
|
//#region source/plugins/html-shell/index.ts
|
|
265
|
-
var THEME_BOOTSTRAP_SCRIPT = `(function(){try{var e=localStorage.getItem('clarify:theme');var t=e==='dark'||e==='light'||e==='system'?e:'system';var r=t==='system'?window.matchMedia('(prefers-color-scheme: dark)').matches:t==='dark';document.documentElement.classList.toggle('dark',r);document.documentElement.style.colorScheme=r?'dark':'light'}catch(e){}})();`;
|
|
266
265
|
var REL_ICON_RE = /<link\s+[^>]*rel=["'][^"']*\bicon\b[^"']*["'][^>]*>/i;
|
|
267
266
|
function inferIconType(href) {
|
|
268
267
|
const path = href.split(/[?#]/, 1)[0]?.toLowerCase() ?? href.toLowerCase();
|
|
@@ -302,7 +301,7 @@ function createHtmlShellPlugin() {
|
|
|
302
301
|
...REL_ICON_RE.test(input.html) ? [] : createIconTags(ctx.projectConfig.favicon ?? ctx.projectConfig.logo),
|
|
303
302
|
{
|
|
304
303
|
tag: "script",
|
|
305
|
-
children:
|
|
304
|
+
children: (0, _clarify_labs_renderer.themeBootstrapScript)(ctx.projectConfig.theme),
|
|
306
305
|
injectTo: "head-prepend"
|
|
307
306
|
},
|
|
308
307
|
{
|
|
@@ -367,6 +366,7 @@ function navigationSections(sections) {
|
|
|
367
366
|
return sections.map((s) => ({
|
|
368
367
|
id: s.id,
|
|
369
368
|
title: s.title,
|
|
369
|
+
level: s.level,
|
|
370
370
|
badge: s.badge,
|
|
371
371
|
tags: s.tags
|
|
372
372
|
}));
|
|
@@ -761,6 +761,7 @@ function generateRoutesModule(routes, resolvedNavigation, projectConfig, mode =
|
|
|
761
761
|
const sections = r.sections && r.sections.length > 0 ? `, sections: ${JSON.stringify(r.sections.map((s) => ({
|
|
762
762
|
id: s.id,
|
|
763
763
|
title: s.title,
|
|
764
|
+
level: s.level,
|
|
764
765
|
badge: s.badge,
|
|
765
766
|
tags: s.tags
|
|
766
767
|
})))}` : "";
|
|
@@ -779,8 +780,12 @@ function generateRoutesModule(routes, resolvedNavigation, projectConfig, mode =
|
|
|
779
780
|
const navigation = resolvedNavigation ?? (projectConfig?.tabs ? projectConfig.i18n ? buildLocalizedNavigationFromTabsConfig(routes, projectConfig.tabs, projectConfig.i18n) ?? {} : buildNavigationFromTabsConfig(routes, projectConfig.tabs) : buildNavigation(routes));
|
|
780
781
|
return `${imports}\n\nexport const routes = [\n${routesArray}\n];\n\nexport const navigation = ${JSON.stringify(navigation, null, 2)};\n`;
|
|
781
782
|
}
|
|
782
|
-
function createRuntimeModule() {
|
|
783
|
-
|
|
783
|
+
function createRuntimeModule(options = {}) {
|
|
784
|
+
const imports = [options.bannerComponentSource === "path" && options.imports?.bannerComponent ? `import BannerComponent from ${moduleSpecifier(options.imports.bannerComponent)};` : void 0, options.footerComponentSource === "path" && options.imports?.footerComponent ? `import FooterComponent from ${moduleSpecifier(options.imports.footerComponent)};` : void 0].filter(Boolean).join("\n");
|
|
785
|
+
const exports = `export const openApis = {};
|
|
786
|
+
export const bannerComponent = ${options.bannerComponentSource === "path" ? "BannerComponent" : "undefined"};
|
|
787
|
+
export const footerComponent = ${options.footerComponentSource === "path" ? "FooterComponent" : "undefined"};`;
|
|
788
|
+
return imports ? `${imports}\n${exports}` : exports;
|
|
784
789
|
}
|
|
785
790
|
function createClientEntryModule(options = {}) {
|
|
786
791
|
return `
|
|
@@ -788,16 +793,29 @@ import '@clarify-labs/renderer/style.css';
|
|
|
788
793
|
import { render } from '@clarify-labs/renderer/client';
|
|
789
794
|
import { routes, navigation } from '${VIRTUAL_ROUTES}';
|
|
790
795
|
import { config } from '${VIRTUAL_CONFIG}';
|
|
791
|
-
import { openApis } from '${VIRTUAL_RUNTIME}';
|
|
792
|
-
render({ config, routes, navigation, openApis, themeEditor: ${JSON.stringify(options.themeEditor ?? false)} });`;
|
|
796
|
+
import { openApis, bannerComponent, footerComponent } from '${VIRTUAL_RUNTIME}';
|
|
797
|
+
render({ config, routes, navigation, openApis, bannerComponent, footerComponent, themeEditor: ${JSON.stringify(options.themeEditor ?? false)} });`;
|
|
793
798
|
}
|
|
794
799
|
function buildVirtualModules(args) {
|
|
795
800
|
const modules = /* @__PURE__ */ new Map();
|
|
796
801
|
const clientEntryModule = createClientEntryModule({ themeEditor: args.themeEditor });
|
|
802
|
+
const bannerComponent = args.projectConfig.banner;
|
|
803
|
+
const bannerComponentSource = typeof bannerComponent === "string" ? "path" : void 0;
|
|
804
|
+
const bannerComponentImport = typeof bannerComponent === "string" ? bannerComponent : void 0;
|
|
805
|
+
const footerComponent = args.projectConfig.footer;
|
|
806
|
+
const footerComponentSource = typeof footerComponent === "string" ? "path" : void 0;
|
|
807
|
+
const footerComponentImport = typeof footerComponent === "string" ? footerComponent : void 0;
|
|
797
808
|
modules.set(VIRTUAL_CONFIG, generateConfigModule(args.projectConfig, args.generateOptions));
|
|
798
809
|
modules.set(VIRTUAL_ROUTES, generateRoutesModule(args.routes, args.navigation, args.projectConfig, "client"));
|
|
799
810
|
modules.set(VIRTUAL_SERVER_ROUTES, generateRoutesModule(args.routes, args.navigation, args.projectConfig, "server"));
|
|
800
|
-
modules.set(VIRTUAL_RUNTIME, createRuntimeModule(
|
|
811
|
+
modules.set(VIRTUAL_RUNTIME, createRuntimeModule({
|
|
812
|
+
bannerComponentSource,
|
|
813
|
+
footerComponentSource,
|
|
814
|
+
imports: {
|
|
815
|
+
bannerComponent: bannerComponentImport,
|
|
816
|
+
footerComponent: footerComponentImport
|
|
817
|
+
}
|
|
818
|
+
}));
|
|
801
819
|
modules.set(VIRTUAL_CLIENT_ENTRY, clientEntryModule);
|
|
802
820
|
modules.set(RESOLVED_CLIENT_ENTRY, clientEntryModule);
|
|
803
821
|
for (const route of args.routes) modules.set(route.virtualModuleId, `export { default } from ${moduleSpecifier(route.filePath)};`);
|
|
@@ -806,8 +824,12 @@ function buildVirtualModules(args) {
|
|
|
806
824
|
//#endregion
|
|
807
825
|
//#region source/plugins/openapi/virtual-modules.ts
|
|
808
826
|
var openApiRegistryModuleId = VIRTUAL_RUNTIME;
|
|
809
|
-
function generateOpenAPIRegistryModule(openApis) {
|
|
810
|
-
|
|
827
|
+
function generateOpenAPIRegistryModule(openApis, runtimeModule = "") {
|
|
828
|
+
const openApisExport = `export const openApis = ${JSON.stringify(openApis)};`;
|
|
829
|
+
const openApisPlaceholder = /export const openApis = \{\};?/;
|
|
830
|
+
if (!runtimeModule) return openApisExport;
|
|
831
|
+
if (openApisPlaceholder.test(runtimeModule)) return runtimeModule.replace(openApisPlaceholder, openApisExport);
|
|
832
|
+
return runtimeModule;
|
|
811
833
|
}
|
|
812
834
|
function generateOpenAPIModule(spec, tagFilter) {
|
|
813
835
|
return `import { createElement } from 'react';
|
|
@@ -935,7 +957,7 @@ function createOpenAPIPlugin() {
|
|
|
935
957
|
return nextRoutes;
|
|
936
958
|
},
|
|
937
959
|
"modules:before": (modules, ctx) => {
|
|
938
|
-
modules.set(openApiRegistryModuleId, generateOpenAPIRegistryModule(Object.fromEntries(Object.entries(specs).map(([moduleId, entry]) => [moduleId, entry.spec]))));
|
|
960
|
+
modules.set(openApiRegistryModuleId, generateOpenAPIRegistryModule(Object.fromEntries(Object.entries(specs).map(([moduleId, entry]) => [moduleId, entry.spec])), modules.get(openApiRegistryModuleId)));
|
|
939
961
|
for (const [moduleId, entry] of Object.entries(specs)) modules.set(moduleId, generateOpenAPIModule(entry.spec, entry.tagFilter));
|
|
940
962
|
for (const route of ctx.routes.filter((route) => route.kind === "openapi" && route.diagnostic)) if (route.diagnostic) modules.set(route.virtualModuleId, generateOpenAPIErrorModule(route.diagnostic));
|
|
941
963
|
return modules;
|
|
@@ -944,6 +966,180 @@ function createOpenAPIPlugin() {
|
|
|
944
966
|
};
|
|
945
967
|
}
|
|
946
968
|
//#endregion
|
|
969
|
+
//#region source/core/search-language.ts
|
|
970
|
+
function toPagefindLanguage(locale) {
|
|
971
|
+
return locale?.trim().replace(/_/g, "-").split("-").filter(Boolean).join("-").toLowerCase() || "en";
|
|
972
|
+
}
|
|
973
|
+
//#endregion
|
|
974
|
+
//#region source/core/temp-dir.ts
|
|
975
|
+
function createClarifyTempDir(name) {
|
|
976
|
+
return (0, node_fs.mkdtempSync)((0, node_path.join)((0, node_os.tmpdir)(), `clarify-${name}-`));
|
|
977
|
+
}
|
|
978
|
+
function removeClarifyTempDir(path) {
|
|
979
|
+
if (!path) return;
|
|
980
|
+
(0, node_fs.rmSync)(path, {
|
|
981
|
+
recursive: true,
|
|
982
|
+
force: true
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
//#endregion
|
|
986
|
+
//#region source/plugins/search-index/index.ts
|
|
987
|
+
var pagefindContentTypes = {
|
|
988
|
+
".css": "text/css; charset=utf-8",
|
|
989
|
+
".js": "text/javascript; charset=utf-8",
|
|
990
|
+
".json": "application/json; charset=utf-8",
|
|
991
|
+
".wasm": "application/wasm"
|
|
992
|
+
};
|
|
993
|
+
function assertNoPagefindErrors(action, errors) {
|
|
994
|
+
if (!errors?.length) return;
|
|
995
|
+
throw new Error(`[clarify] Pagefind ${action} failed:\n${errors.join("\n")}`);
|
|
996
|
+
}
|
|
997
|
+
async function generatePagefindIndex(options) {
|
|
998
|
+
const pagefind = await import("pagefind");
|
|
999
|
+
const { errors, index } = await pagefind.createIndex({
|
|
1000
|
+
excludeSelectors: [
|
|
1001
|
+
"[data-pagefind-ignore]",
|
|
1002
|
+
"script",
|
|
1003
|
+
"style",
|
|
1004
|
+
"svg"
|
|
1005
|
+
],
|
|
1006
|
+
includeCharacters: "._-/#:@",
|
|
1007
|
+
keepIndexUrl: false,
|
|
1008
|
+
verbose: false,
|
|
1009
|
+
writePlayground: false
|
|
1010
|
+
});
|
|
1011
|
+
assertNoPagefindErrors("createIndex", errors);
|
|
1012
|
+
if (!index) throw new Error("[clarify] Pagefind did not create an index.");
|
|
1013
|
+
try {
|
|
1014
|
+
const addResult = await index.addDirectory({
|
|
1015
|
+
path: options.sourceRoot ?? options.outputRoot,
|
|
1016
|
+
glob: "**/*.html"
|
|
1017
|
+
});
|
|
1018
|
+
assertNoPagefindErrors("addDirectory", addResult.errors);
|
|
1019
|
+
assertNoPagefindErrors("writeFiles", (await index.writeFiles({ outputPath: (0, node_path.join)(options.outputRoot, "pagefind") })).errors);
|
|
1020
|
+
return addResult.page_count;
|
|
1021
|
+
} finally {
|
|
1022
|
+
await index.deleteIndex();
|
|
1023
|
+
await pagefind.close();
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
function routeSearchContent(route) {
|
|
1027
|
+
return [
|
|
1028
|
+
route.title,
|
|
1029
|
+
route.description,
|
|
1030
|
+
route.keywords?.join(" "),
|
|
1031
|
+
route.sections?.map((section) => section.title).join(" "),
|
|
1032
|
+
route.content
|
|
1033
|
+
].filter(Boolean).join("\n\n");
|
|
1034
|
+
}
|
|
1035
|
+
async function generateDevSearchIndex(ctx, root) {
|
|
1036
|
+
const pagefind = await import("pagefind");
|
|
1037
|
+
const { errors, index } = await pagefind.createIndex({
|
|
1038
|
+
includeCharacters: "._-/#:@",
|
|
1039
|
+
keepIndexUrl: false,
|
|
1040
|
+
verbose: false,
|
|
1041
|
+
writePlayground: false
|
|
1042
|
+
});
|
|
1043
|
+
assertNoPagefindErrors("createIndex", errors);
|
|
1044
|
+
if (!index) throw new Error("[clarify] Pagefind did not create an index.");
|
|
1045
|
+
try {
|
|
1046
|
+
let pageCount = 0;
|
|
1047
|
+
for (const route of ctx.routes) {
|
|
1048
|
+
const content = routeSearchContent(route);
|
|
1049
|
+
if (!content.trim()) continue;
|
|
1050
|
+
const result = await index.addCustomRecord({
|
|
1051
|
+
url: route.path,
|
|
1052
|
+
content,
|
|
1053
|
+
language: toPagefindLanguage(route.locale ?? ctx.projectConfig.i18n?.defaultLocale),
|
|
1054
|
+
meta: { title: route.title }
|
|
1055
|
+
});
|
|
1056
|
+
assertNoPagefindErrors(`addCustomRecord ${route.path}`, result.errors);
|
|
1057
|
+
pageCount += 1;
|
|
1058
|
+
}
|
|
1059
|
+
assertNoPagefindErrors("writeFiles", (await index.writeFiles({ outputPath: (0, node_path.join)(root, "pagefind") })).errors);
|
|
1060
|
+
console.log(`[clarify] Dev search index generated for ${pageCount} pages.`);
|
|
1061
|
+
} finally {
|
|
1062
|
+
await index.deleteIndex();
|
|
1063
|
+
await pagefind.close();
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
function normalizeDevPagefindPath(rawUrl, routePrefix) {
|
|
1067
|
+
const pathname = rawUrl?.split("?")[0];
|
|
1068
|
+
if (!pathname) return void 0;
|
|
1069
|
+
const normalizedPrefix = routePrefix && routePrefix !== "/" ? `/${routePrefix.replace(/^\/+|\/+$/g, "")}` : "";
|
|
1070
|
+
const pagefindPath = normalizedPrefix && pathname.startsWith(`${normalizedPrefix}/pagefind/`) ? pathname.slice(normalizedPrefix.length) : pathname;
|
|
1071
|
+
return pagefindPath.startsWith("/pagefind/") ? pagefindPath : void 0;
|
|
1072
|
+
}
|
|
1073
|
+
function serveDevPagefind(server, getRoot, ctx) {
|
|
1074
|
+
server.middlewares.use((req, res, next) => {
|
|
1075
|
+
const root = getRoot();
|
|
1076
|
+
const pagefindPath = normalizeDevPagefindPath(req.url, ctx.projectConfig.routePrefix);
|
|
1077
|
+
if (!root || !pagefindPath) {
|
|
1078
|
+
next();
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
const filePath = (0, node_path.join)(root, pagefindPath);
|
|
1082
|
+
const relativePath = (0, node_path.relative)(root, filePath);
|
|
1083
|
+
if (relativePath.startsWith("..") || relativePath === "" || !(0, node_fs.existsSync)(filePath)) {
|
|
1084
|
+
next();
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1087
|
+
const contentType = pagefindContentTypes[(0, node_path.extname)(filePath)] ?? "application/octet-stream";
|
|
1088
|
+
res.setHeader("Content-Type", contentType);
|
|
1089
|
+
(0, node_fs.createReadStream)(filePath).pipe(res);
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
function createSearchIndexPlugin() {
|
|
1093
|
+
return {
|
|
1094
|
+
name: "clarify:search-index",
|
|
1095
|
+
hooks: {
|
|
1096
|
+
async "dev:configureServer"(server, ctx) {
|
|
1097
|
+
let currentRoot;
|
|
1098
|
+
const staleRoots = /* @__PURE__ */ new Set();
|
|
1099
|
+
const replaceDevIndex = async () => {
|
|
1100
|
+
const nextRoot = createClarifyTempDir("pagefind");
|
|
1101
|
+
await generateDevSearchIndex(ctx, nextRoot);
|
|
1102
|
+
const previousRoot = currentRoot;
|
|
1103
|
+
currentRoot = nextRoot;
|
|
1104
|
+
if (previousRoot) {
|
|
1105
|
+
staleRoots.add(previousRoot);
|
|
1106
|
+
setTimeout(() => {
|
|
1107
|
+
staleRoots.delete(previousRoot);
|
|
1108
|
+
removeClarifyTempDir(previousRoot);
|
|
1109
|
+
}, 3e4).unref?.();
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
serveDevPagefind(server, () => currentRoot, ctx);
|
|
1113
|
+
await replaceDevIndex();
|
|
1114
|
+
let regenerateTimer;
|
|
1115
|
+
const regenerate = (filePath) => {
|
|
1116
|
+
if (!/\.(md|mdx|json|ya?ml)$/i.test(filePath)) return;
|
|
1117
|
+
if (regenerateTimer) clearTimeout(regenerateTimer);
|
|
1118
|
+
regenerateTimer = setTimeout(() => {
|
|
1119
|
+
replaceDevIndex().catch((err) => {
|
|
1120
|
+
console.error("[clarify] Failed to regenerate dev search index:", err);
|
|
1121
|
+
});
|
|
1122
|
+
}, 100);
|
|
1123
|
+
};
|
|
1124
|
+
server.watcher.on("add", regenerate);
|
|
1125
|
+
server.watcher.on("change", regenerate);
|
|
1126
|
+
server.watcher.on("unlink", regenerate);
|
|
1127
|
+
server.httpServer?.once("close", () => {
|
|
1128
|
+
if (regenerateTimer) clearTimeout(regenerateTimer);
|
|
1129
|
+
removeClarifyTempDir(currentRoot);
|
|
1130
|
+
for (const staleRoot of staleRoots) removeClarifyTempDir(staleRoot);
|
|
1131
|
+
});
|
|
1132
|
+
},
|
|
1133
|
+
async "build:done"(ctx) {
|
|
1134
|
+
const outputDirectory = ctx.generateOptions.outputDirectory;
|
|
1135
|
+
if (!outputDirectory) return;
|
|
1136
|
+
const pageCount = await generatePagefindIndex({ outputRoot: (0, node_path.resolve)(ctx.generateOptions.projectRoot, outputDirectory) });
|
|
1137
|
+
console.log(`[clarify] Search index generated for ${pageCount} pages.`);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
//#endregion
|
|
947
1143
|
//#region source/plugins/seo/artifacts.ts
|
|
948
1144
|
function trimTrailingSlash(value) {
|
|
949
1145
|
return value.replace(/\/+$/, "");
|
|
@@ -1039,7 +1235,8 @@ function createBuiltinPlugins(options = {}) {
|
|
|
1039
1235
|
createOpenAPIPlugin(),
|
|
1040
1236
|
createSourceLinksPlugin(),
|
|
1041
1237
|
createContentArtifactsPlugin(),
|
|
1042
|
-
createSeoPlugin()
|
|
1238
|
+
createSeoPlugin(),
|
|
1239
|
+
createSearchIndexPlugin()
|
|
1043
1240
|
];
|
|
1044
1241
|
if (options.htmlShell ?? true) plugins.push(createHtmlShellPlugin());
|
|
1045
1242
|
return plugins;
|
|
@@ -1093,15 +1290,18 @@ var clarifyNavbarLinkSchema = zod.z.object({
|
|
|
1093
1290
|
href: zod.z.string(),
|
|
1094
1291
|
external: zod.z.boolean().optional()
|
|
1095
1292
|
});
|
|
1096
|
-
var
|
|
1293
|
+
var clarifyBannerConfigOptionsSchema = zod.z.object({
|
|
1097
1294
|
content: clarifyLocalizedTextSchema,
|
|
1098
|
-
dismissible: zod.z.boolean().optional()
|
|
1099
|
-
|
|
1100
|
-
|
|
1295
|
+
dismissible: zod.z.boolean().optional(),
|
|
1296
|
+
link: clarifyNavbarLinkSchema.optional()
|
|
1297
|
+
}).strict();
|
|
1298
|
+
var clarifyBannerConfigSchema = zod.z.union([clarifyBannerConfigOptionsSchema, zod.z.string()]);
|
|
1299
|
+
var clarifyFooterLinksConfigSchema = zod.z.object({
|
|
1101
1300
|
links: zod.z.array(clarifyNavbarLinkSchema).optional(),
|
|
1102
1301
|
socials: zod.z.record(zod.z.string(), zod.z.string()).optional(),
|
|
1103
1302
|
copyright: clarifyLocalizedTextSchema.optional()
|
|
1104
|
-
});
|
|
1303
|
+
}).strict();
|
|
1304
|
+
var clarifyFooterConfigSchema = zod.z.union([clarifyFooterLinksConfigSchema, zod.z.string()]);
|
|
1105
1305
|
var clarifySourceConfigSchema = zod.z.object({
|
|
1106
1306
|
repository: zod.z.string(),
|
|
1107
1307
|
branch: zod.z.string().optional(),
|
|
@@ -1175,6 +1375,7 @@ var clarifyProjectConfigSchema = zod.z.object({
|
|
|
1175
1375
|
siteUrl: zod.z.string().optional(),
|
|
1176
1376
|
source: clarifySourceConfigSchema.optional(),
|
|
1177
1377
|
logo: clarifyLogoConfigSchema.optional(),
|
|
1378
|
+
homeUrl: zod.z.string().optional(),
|
|
1178
1379
|
favicon: clarifyFaviconConfigSchema.optional(),
|
|
1179
1380
|
theme: clarifyThemeConfigSchema.optional(),
|
|
1180
1381
|
routePrefix: zod.z.string().optional(),
|
|
@@ -1186,57 +1387,9 @@ var clarifyProjectConfigSchema = zod.z.object({
|
|
|
1186
1387
|
});
|
|
1187
1388
|
//#endregion
|
|
1188
1389
|
//#region source/core/theme.ts
|
|
1189
|
-
var clarifyThemePresets = {
|
|
1190
|
-
default: {
|
|
1191
|
-
preset: "default",
|
|
1192
|
-
tokens: {
|
|
1193
|
-
colors: {
|
|
1194
|
-
primary: "#047857",
|
|
1195
|
-
accent: "#0D9488",
|
|
1196
|
-
background: "#ffffff",
|
|
1197
|
-
foreground: "#111827",
|
|
1198
|
-
surface: "#ffffff",
|
|
1199
|
-
muted: "#64748b",
|
|
1200
|
-
border: "rgb(15 23 42 / 0.12)",
|
|
1201
|
-
codeBackground: "#f6fbf8"
|
|
1202
|
-
},
|
|
1203
|
-
radius: {
|
|
1204
|
-
sm: "6px",
|
|
1205
|
-
md: "10px",
|
|
1206
|
-
lg: "14px",
|
|
1207
|
-
xl: "18px"
|
|
1208
|
-
}
|
|
1209
|
-
},
|
|
1210
|
-
layout: { maxWidth: "82rem" },
|
|
1211
|
-
editor: false
|
|
1212
|
-
},
|
|
1213
|
-
base: {
|
|
1214
|
-
preset: "base",
|
|
1215
|
-
tokens: {
|
|
1216
|
-
colors: {
|
|
1217
|
-
primary: "#18181b",
|
|
1218
|
-
accent: "#52525b",
|
|
1219
|
-
background: "#ffffff",
|
|
1220
|
-
foreground: "#18181b",
|
|
1221
|
-
surface: "#ffffff",
|
|
1222
|
-
muted: "#71717a",
|
|
1223
|
-
border: "rgb(24 24 27 / 0.12)",
|
|
1224
|
-
codeBackground: "#f4f4f5"
|
|
1225
|
-
},
|
|
1226
|
-
radius: {
|
|
1227
|
-
sm: "6px",
|
|
1228
|
-
md: "8px",
|
|
1229
|
-
lg: "12px",
|
|
1230
|
-
xl: "16px"
|
|
1231
|
-
}
|
|
1232
|
-
},
|
|
1233
|
-
layout: { maxWidth: "80rem" },
|
|
1234
|
-
editor: false
|
|
1235
|
-
}
|
|
1236
|
-
};
|
|
1237
1390
|
function resolveThemeConfig(theme = {}) {
|
|
1238
1391
|
const preset = theme.preset ?? "default";
|
|
1239
|
-
const presetTheme =
|
|
1392
|
+
const presetTheme = _clarify_labs_renderer.themePresets[preset];
|
|
1240
1393
|
return {
|
|
1241
1394
|
preset,
|
|
1242
1395
|
tokens: {
|
|
@@ -1295,6 +1448,7 @@ function resolveProjectConfig(config = {}) {
|
|
|
1295
1448
|
siteUrl: config.siteUrl,
|
|
1296
1449
|
source: config.source,
|
|
1297
1450
|
logo: config.logo,
|
|
1451
|
+
homeUrl: config.homeUrl,
|
|
1298
1452
|
favicon: config.favicon,
|
|
1299
1453
|
routePrefix: config.routePrefix ?? "/",
|
|
1300
1454
|
theme: resolveThemeConfig(config.theme),
|
|
@@ -1550,13 +1704,13 @@ function routeOutputFiles(outputDirectory, route) {
|
|
|
1550
1704
|
var SSR_ENTRY_CODE = `import { renderToHTML } from '@clarify-labs/renderer/server';
|
|
1551
1705
|
import { routes, navigation } from 'virtual:clarify-routes/server';
|
|
1552
1706
|
import { config } from 'virtual:clarify-config';
|
|
1553
|
-
import { openApis } from 'virtual:clarify-runtime';
|
|
1707
|
+
import { openApis, bannerComponent, footerComponent } from 'virtual:clarify-runtime';
|
|
1554
1708
|
|
|
1555
1709
|
export function render(url) {
|
|
1556
|
-
return renderToHTML({ config, routes, navigation, openApis, url, themeEditor: config.theme.editor });
|
|
1710
|
+
return renderToHTML({ config, routes, navigation, openApis, bannerComponent, footerComponent, url, themeEditor: config.theme.editor });
|
|
1557
1711
|
}`;
|
|
1558
1712
|
function createTempEntryFile(content) {
|
|
1559
|
-
const entryPath = (0, node_path.join)((
|
|
1713
|
+
const entryPath = (0, node_path.join)(createClarifyTempDir("ssr"), "entry-server.ts");
|
|
1560
1714
|
(0, node_fs.writeFileSync)(entryPath, content, "utf-8");
|
|
1561
1715
|
return entryPath;
|
|
1562
1716
|
}
|
|
@@ -1596,6 +1750,7 @@ async function renderSSGRoutes(routes, projectConfig, outputDirectory, ssrBundle
|
|
|
1596
1750
|
//#endregion
|
|
1597
1751
|
//#region source/core/user-config.ts
|
|
1598
1752
|
function defineConfig(config) {
|
|
1753
|
+
validateProjectConfig(config);
|
|
1599
1754
|
return config;
|
|
1600
1755
|
}
|
|
1601
1756
|
var CONFIG_FILENAMES = [
|
|
@@ -1858,6 +2013,12 @@ Object.defineProperty(exports, "createClarifyRuntimeAliases", {
|
|
|
1858
2013
|
return createClarifyRuntimeAliases;
|
|
1859
2014
|
}
|
|
1860
2015
|
});
|
|
2016
|
+
Object.defineProperty(exports, "createClarifyTempDir", {
|
|
2017
|
+
enumerable: true,
|
|
2018
|
+
get: function() {
|
|
2019
|
+
return createClarifyTempDir;
|
|
2020
|
+
}
|
|
2021
|
+
});
|
|
1861
2022
|
Object.defineProperty(exports, "defineConfig", {
|
|
1862
2023
|
enumerable: true,
|
|
1863
2024
|
get: function() {
|
|
@@ -1877,4 +2038,4 @@ Object.defineProperty(exports, "resolveClarifySite", {
|
|
|
1877
2038
|
}
|
|
1878
2039
|
});
|
|
1879
2040
|
|
|
1880
|
-
//# sourceMappingURL=plugin-
|
|
2041
|
+
//# sourceMappingURL=plugin-DFpkIm9j.cjs.map
|