@nikala-ui/folio 0.14.0 → 0.15.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.
Files changed (160) hide show
  1. package/README.md +16 -0
  2. package/dist/cli/commands/init.js +105 -51
  3. package/dist/client/app.jsx +6 -3
  4. package/dist/client/components/docs-layout-shell.d.ts +1 -0
  5. package/dist/client/components/docs-layout-shell.jsx +1 -1
  6. package/dist/client/components/docs-page-content.jsx +9 -5
  7. package/dist/client/navigation/page-navigation.js +10 -27
  8. package/dist/client/public/algolia-logo.svg +15 -0
  9. package/dist/client/public/favicon.ico +0 -0
  10. package/dist/client/public/logo.svg +11 -0
  11. package/dist/client/routing/use-docs-router.d.ts +1 -0
  12. package/dist/client/routing/use-docs-router.js +12 -3
  13. package/dist/client/style.css +139 -55
  14. package/dist/components/ui/api-table.jsx +6 -4
  15. package/dist/components/ui/code-block.jsx +6 -4
  16. package/dist/components/ui/command.jsx +9 -5
  17. package/dist/components/ui/list.jsx +3 -1
  18. package/dist/components/ui/logo.d.ts +4 -1
  19. package/dist/components/ui/logo.jsx +8 -22
  20. package/dist/components/ui/package-manager-tabs.jsx +4 -2
  21. package/dist/components/ui/pager.jsx +4 -2
  22. package/dist/components/ui/section-heading.jsx +1 -1
  23. package/dist/components/ui/sidebar.jsx +6 -3
  24. package/dist/components/ui/spinner.jsx +3 -1
  25. package/dist/components/ui/theme-toggle.jsx +14 -12
  26. package/dist/config.d.ts +1 -0
  27. package/dist/config.js +84 -29
  28. package/dist/core/content-scanner.d.ts +2 -1
  29. package/dist/core/content-scanner.js +2 -9
  30. package/dist/core/plugin/index.d.ts +2 -0
  31. package/dist/core/plugin/index.js +1 -0
  32. package/dist/core/plugin/lifecycle-error.d.ts +19 -0
  33. package/dist/core/plugin/lifecycle-error.js +28 -0
  34. package/dist/core/plugin/lifecycle-snapshot.d.ts +1 -0
  35. package/dist/core/plugin/lifecycle-snapshot.js +156 -0
  36. package/dist/core/plugin/lifecycle.d.ts +34 -0
  37. package/dist/core/plugin/lifecycle.js +170 -0
  38. package/dist/core/route-tree.d.ts +3 -2
  39. package/dist/core/route-tree.js +40 -10
  40. package/dist/index.d.ts +7 -4
  41. package/dist/index.js +4 -3
  42. package/dist/plugin.d.ts +60 -0
  43. package/dist/plugin.js +51 -0
  44. package/dist/plugins/i18n/components/site-language-switcher.d.ts +10 -0
  45. package/dist/plugins/i18n/components/site-language-switcher.jsx +39 -0
  46. package/dist/plugins/i18n/constants.d.ts +1 -0
  47. package/dist/plugins/i18n/constants.js +1 -0
  48. package/dist/plugins/i18n/index.d.ts +11 -0
  49. package/dist/plugins/i18n/index.js +89 -0
  50. package/dist/plugins/i18n/navigation.d.ts +5 -0
  51. package/dist/plugins/i18n/navigation.js +33 -0
  52. package/dist/plugins/i18n/runtime.d.ts +19 -0
  53. package/dist/plugins/i18n/runtime.jsx +65 -0
  54. package/dist/plugins/i18n/site-locale.d.ts +12 -0
  55. package/dist/plugins/i18n/site-locale.js +119 -0
  56. package/dist/search/provider.d.ts +9 -0
  57. package/dist/search/provider.js +4 -2
  58. package/dist/server/index.d.ts +4 -1
  59. package/dist/server/index.js +69 -33
  60. package/dist/server/module-serialization.d.ts +6 -0
  61. package/dist/server/module-serialization.js +26 -0
  62. package/dist/server/plugin/components.d.ts +7 -0
  63. package/dist/server/plugin/components.js +82 -0
  64. package/dist/server/plugin/constants.d.ts +17 -0
  65. package/dist/server/plugin/constants.js +21 -0
  66. package/dist/server/{plugin.d.ts → plugin/index.d.ts} +3 -1
  67. package/dist/server/plugin/index.js +166 -0
  68. package/dist/server/plugin/lifecycle.d.ts +32 -0
  69. package/dist/server/plugin/lifecycle.js +110 -0
  70. package/dist/server/plugin/styles.d.ts +3 -0
  71. package/dist/server/plugin/styles.js +22 -0
  72. package/dist/server/plugin/virtual-modules.d.ts +11 -0
  73. package/dist/server/plugin/virtual-modules.js +121 -0
  74. package/dist/server/seo.d.ts +4 -0
  75. package/dist/server/seo.js +87 -0
  76. package/dist/templates/env.d.ts +26 -0
  77. package/dist/templates/locales/en.json +77 -0
  78. package/dist/themes/default/components/docs-landing-body.d.ts +17 -0
  79. package/dist/themes/default/components/docs-landing-body.jsx +17 -0
  80. package/dist/themes/default/components/docs-page-body.d.ts +21 -0
  81. package/dist/themes/default/components/docs-page-body.jsx +36 -0
  82. package/dist/themes/default/components/page-actions.d.ts +15 -0
  83. package/dist/themes/default/components/page-actions.jsx +60 -0
  84. package/dist/themes/default/components/page-header.d.ts +7 -0
  85. package/dist/themes/default/components/page-header.jsx +3 -0
  86. package/dist/themes/default/components/sidebar-footer.d.ts +6 -0
  87. package/dist/themes/default/components/sidebar-footer.jsx +12 -0
  88. package/dist/themes/default/components/sidebar-header.d.ts +8 -0
  89. package/dist/themes/default/components/sidebar-header.jsx +17 -0
  90. package/dist/themes/default/components/sidebar-mobile-nav.d.ts +7 -0
  91. package/dist/themes/default/components/sidebar-mobile-nav.jsx +17 -0
  92. package/dist/themes/default/components/sidebar-promo.d.ts +8 -0
  93. package/dist/themes/default/components/sidebar-promo.jsx +20 -0
  94. package/dist/themes/default/content/breadcrumbs.jsx +5 -2
  95. package/dist/themes/default/content/table-of-contents.jsx +3 -1
  96. package/dist/themes/default/hooks/use-page-copy.d.ts +6 -0
  97. package/dist/themes/default/hooks/use-page-copy.js +26 -0
  98. package/dist/themes/default/layout.jsx +30 -127
  99. package/dist/themes/default/lib/layout-visibility.d.ts +8 -0
  100. package/dist/themes/default/lib/layout-visibility.js +24 -0
  101. package/dist/themes/default/navbar.jsx +14 -7
  102. package/dist/themes/default/navigation/mobile-table-of-contents.jsx +5 -3
  103. package/dist/themes/default/navigation/sidebar-tree.d.ts +2 -0
  104. package/dist/themes/default/navigation/sidebar-tree.jsx +11 -2
  105. package/dist/themes/default/overlays/search-dialog.jsx +14 -3
  106. package/dist/themes/default/sidebar.jsx +21 -49
  107. package/dist/themes/types.d.ts +5 -0
  108. package/dist/types.d.ts +36 -0
  109. package/dist/utils/format-title.d.ts +1 -0
  110. package/dist/utils/format-title.js +11 -0
  111. package/dist/vendor/docs-src/client/page-actions.ts +69 -0
  112. package/dist/vendor/docs-src/components/ui/api-table.tsx +6 -4
  113. package/dist/vendor/docs-src/components/ui/code-block.tsx +6 -4
  114. package/dist/vendor/docs-src/components/ui/command.tsx +9 -5
  115. package/dist/vendor/docs-src/components/ui/list.tsx +4 -2
  116. package/dist/vendor/docs-src/components/ui/logo.tsx +19 -48
  117. package/dist/vendor/docs-src/components/ui/package-manager-tabs.tsx +4 -2
  118. package/dist/vendor/docs-src/components/ui/pager.tsx +4 -2
  119. package/dist/vendor/docs-src/components/ui/section-heading.tsx +5 -1
  120. package/dist/vendor/docs-src/components/ui/sidebar.tsx +7 -4
  121. package/dist/vendor/docs-src/components/ui/spinner.tsx +3 -1
  122. package/dist/vendor/docs-src/components/ui/theme-toggle.tsx +15 -13
  123. package/dist/vendor/docs-src/navigation/index.ts +2 -0
  124. package/dist/vendor/docs-src/navigation/repository-links.ts +43 -0
  125. package/dist/vendor/docs-src/navigation/sidebar-state.ts +22 -0
  126. package/dist/vendor/docs-src/navigation/sidebar-tree.ts +15 -0
  127. package/dist/vendor/docs-src/plugins/i18n/components/site-language-switcher.tsx +56 -0
  128. package/dist/vendor/docs-src/plugins/i18n/constants.ts +1 -0
  129. package/dist/vendor/docs-src/plugins/i18n/index.ts +110 -0
  130. package/dist/vendor/docs-src/plugins/i18n/navigation.ts +49 -0
  131. package/dist/vendor/docs-src/plugins/i18n/runtime.tsx +91 -0
  132. package/dist/vendor/docs-src/plugins/i18n/site-locale.ts +140 -0
  133. package/dist/vendor/docs-src/search/provider.ts +83 -0
  134. package/dist/vendor/docs-src/themes/default/components/docs-landing-body.tsx +30 -0
  135. package/dist/vendor/docs-src/themes/default/components/docs-page-body.tsx +53 -0
  136. package/dist/vendor/docs-src/themes/default/components/page-actions.tsx +105 -0
  137. package/dist/vendor/docs-src/themes/default/components/page-header.tsx +31 -0
  138. package/dist/vendor/docs-src/themes/default/components/sidebar-footer.tsx +21 -0
  139. package/dist/vendor/docs-src/themes/default/components/sidebar-header.tsx +30 -0
  140. package/dist/vendor/docs-src/themes/default/components/sidebar-mobile-nav.tsx +33 -0
  141. package/dist/vendor/docs-src/themes/default/components/sidebar-promo.tsx +37 -0
  142. package/dist/vendor/docs-src/themes/default/content/breadcrumbs.tsx +43 -0
  143. package/dist/vendor/docs-src/themes/default/content/pager.tsx +19 -0
  144. package/dist/vendor/docs-src/themes/default/content/table-of-contents.tsx +32 -0
  145. package/dist/vendor/docs-src/themes/default/hooks/use-page-copy.ts +29 -0
  146. package/dist/vendor/docs-src/themes/default/icons.ts +16 -0
  147. package/dist/vendor/docs-src/themes/default/index.ts +46 -0
  148. package/dist/vendor/docs-src/themes/default/layout.tsx +176 -0
  149. package/dist/vendor/docs-src/themes/default/lib/layout-visibility.ts +39 -0
  150. package/dist/vendor/docs-src/themes/default/navbar.tsx +130 -0
  151. package/dist/vendor/docs-src/themes/default/navigation/mobile-table-of-contents.tsx +61 -0
  152. package/dist/vendor/docs-src/themes/default/navigation/sidebar-tree.tsx +202 -0
  153. package/dist/vendor/docs-src/themes/default/overlays/search-dialog.tsx +106 -0
  154. package/dist/vendor/docs-src/themes/default/sidebar.tsx +86 -0
  155. package/dist/vendor/docs-src/themes/index.ts +4 -0
  156. package/dist/vendor/docs-src/themes/types.ts +87 -0
  157. package/dist/version.d.ts +1 -1
  158. package/dist/version.js +1 -1
  159. package/package.json +11 -4
  160. package/dist/server/plugin.js +0 -521
@@ -0,0 +1,65 @@
1
+ import { createContext, createEffect, createSignal, useContext } from "solid-js";
2
+ import { findLocalizedPage, getPageLocale } from "./navigation.js";
3
+ import { SITE_LOCALE_STORAGE_KEY } from "./constants.js";
4
+ // Dev mode can load the bundled client and source theme files in one realm.
5
+ // Keep one context identity across those module copies without coupling the
6
+ // server resolver to a plugin-specific filesystem path.
7
+ const runtimeGlobal = globalThis;
8
+ const SiteLocaleContext = runtimeGlobal.__folioSiteLocaleContext
9
+ || (runtimeGlobal.__folioSiteLocaleContext = createContext());
10
+ export const SiteLocaleProvider = (props) => {
11
+ const configuredInitial = props.config?.locale || props.config?.defaultLocale || "en";
12
+ const currentPage = () => props.currentPage || props.pages?.find((page) => page.url === props.currentPath);
13
+ const pageInitial = () => {
14
+ const page = currentPage();
15
+ return (page ? getPageLocale(page) : undefined) || configuredInitial;
16
+ };
17
+ const [locale, setLocale] = createSignal(pageInitial());
18
+ const locales = () => Object.keys(props.config?.translations || {}).sort();
19
+ const setSiteLocale = (next) => {
20
+ if (locales().includes(next))
21
+ setLocale(next);
22
+ };
23
+ createEffect(() => {
24
+ const currentPath = props.currentPath;
25
+ if (typeof window === "undefined")
26
+ return;
27
+ const saved = window.localStorage.getItem(SITE_LOCALE_STORAGE_KEY);
28
+ const preferredLocale = saved && locales().includes(saved) ? saved : pageInitial();
29
+ if (!currentPath) {
30
+ setSiteLocale(preferredLocale);
31
+ return;
32
+ }
33
+ const currentPage = props.pages?.find((page) => page.url === currentPath);
34
+ const localizedPage = findLocalizedPage(props.pages || [], currentPage, preferredLocale);
35
+ if (!localizedPage && currentPage) {
36
+ setSiteLocale(getPageLocale(currentPage) || configuredInitial);
37
+ return;
38
+ }
39
+ setSiteLocale(preferredLocale);
40
+ if (localizedPage && localizedPage.url !== currentPath)
41
+ props.onNavigate?.(localizedPage.url);
42
+ });
43
+ const t = (key, values = {}) => {
44
+ const translations = props.config?.translations || {};
45
+ const defaultLocale = props.config?.defaultLocale || "en";
46
+ const text = translations[locale()]?.[key] || translations[defaultLocale]?.[key] || key;
47
+ return Object.entries(values).reduce((result, [name, value]) => result.replaceAll(`{${name}}`, value), text);
48
+ };
49
+ const value = {
50
+ locale,
51
+ locales,
52
+ setLocale: (next) => {
53
+ setSiteLocale(next);
54
+ window.localStorage.setItem(SITE_LOCALE_STORAGE_KEY, next);
55
+ },
56
+ t,
57
+ };
58
+ return <SiteLocaleContext.Provider value={value}>{props.children}</SiteLocaleContext.Provider>;
59
+ };
60
+ export function useSiteLocale() {
61
+ const context = useContext(SiteLocaleContext);
62
+ if (!context)
63
+ throw new Error("useSiteLocale must be used within a SiteLocaleProvider");
64
+ return context;
65
+ }
@@ -0,0 +1,12 @@
1
+ export { SITE_LOCALE_STORAGE_KEY } from "./constants.js";
2
+ export declare const SITE_TRANSLATION_KEYS: readonly ["navigation.search", "navigation.searchLabel", "navigation.toggleSidebar", "navigation.closeSidebar", "navigation.documentation", "navigation.primary", "navigation.github", "navigation.chooseLanguage", "navigation.toggleNavigation", "navigation.toggleSidebarRail", "navigation.sidebar", "navigation.collapse", "navigation.expand", "navigation.breadcrumb", "actions.viewSource", "actions.copyPage", "actions.copyAsMarkdown", "actions.learnMore", "actions.copyDocumentationPage", "actions.openInProvider", "actions.copied", "actions.prompt", "actions.copyContext", "actions.copyCliCommand", "actions.copyCode", "actions.exitFullscreen", "actions.expandFullscreen", "tableOfContents.title", "search.placeholder", "search.empty", "search.pages", "search.by", "search.commandPlaceholder", "search.noResults", "pagination.previous", "pagination.next", "theme.toggle", "theme.light", "theme.dark", "theme.system", "theme.mode", "theme.brandAccentColor", "theme.borderRadius", "viewer.preview", "viewer.code", "viewer.desktopViewport", "viewer.tabletViewport", "viewer.mobileViewport", "viewer.desktopSize", "viewer.tabletSize", "viewer.mobileSize", "viewer.toggleBackgroundGrid", "viewer.canvasGrid", "viewer.resetPreviewCanvas", "viewer.resetCanvas", "viewer.copyAiContext", "viewer.copyCodeForAi", "viewer.copyCliInstallation", "viewer.fullscreenPreview", "viewer.exitFullscreen", "code.copied", "code.copy", "command.navigate", "command.select", "command.close", "image.avatar", "status.loading", "status.loadingLabel", "accessibility.callout", "errors.pageNotFound", "errors.pageNotFoundDescription", "apiTable.property", "apiTable.type", "apiTable.default", "apiTable.description"];
3
+ export type SiteTranslationKey = (typeof SITE_TRANSLATION_KEYS)[number];
4
+ export type SiteTranslations = Record<SiteTranslationKey, string>;
5
+ export interface DocsUiLocaleConfig {
6
+ defaultLocale?: string;
7
+ directory?: string;
8
+ locale?: string;
9
+ translations?: Record<string, Partial<SiteTranslations>>;
10
+ }
11
+ export declare function loadSiteTranslations(rootDir: string, config?: DocsUiLocaleConfig): Promise<DocsUiLocaleConfig>;
12
+ export declare function getSiteTranslation(config: DocsUiLocaleConfig | undefined, key: SiteTranslationKey): string;
@@ -0,0 +1,119 @@
1
+ import path from "node:path";
2
+ import fs from "fs-extra";
3
+ export { SITE_LOCALE_STORAGE_KEY } from "./constants.js";
4
+ export const SITE_TRANSLATION_KEYS = [
5
+ "navigation.search",
6
+ "navigation.searchLabel",
7
+ "navigation.toggleSidebar",
8
+ "navigation.closeSidebar",
9
+ "navigation.documentation",
10
+ "navigation.primary",
11
+ "navigation.github",
12
+ "navigation.chooseLanguage",
13
+ "navigation.toggleNavigation",
14
+ "navigation.toggleSidebarRail",
15
+ "navigation.sidebar",
16
+ "navigation.collapse",
17
+ "navigation.expand",
18
+ "navigation.breadcrumb",
19
+ "actions.viewSource",
20
+ "actions.copyPage",
21
+ "actions.copyAsMarkdown",
22
+ "actions.learnMore",
23
+ "actions.copyDocumentationPage",
24
+ "actions.openInProvider",
25
+ "actions.copied",
26
+ "actions.prompt",
27
+ "actions.copyContext",
28
+ "actions.copyCliCommand",
29
+ "actions.copyCode",
30
+ "actions.exitFullscreen",
31
+ "actions.expandFullscreen",
32
+ "tableOfContents.title",
33
+ "search.placeholder",
34
+ "search.empty",
35
+ "search.pages",
36
+ "search.by",
37
+ "search.commandPlaceholder",
38
+ "search.noResults",
39
+ "pagination.previous",
40
+ "pagination.next",
41
+ "theme.toggle",
42
+ "theme.light",
43
+ "theme.dark",
44
+ "theme.system",
45
+ "theme.mode",
46
+ "theme.brandAccentColor",
47
+ "theme.borderRadius",
48
+ "viewer.preview",
49
+ "viewer.code",
50
+ "viewer.desktopViewport",
51
+ "viewer.tabletViewport",
52
+ "viewer.mobileViewport",
53
+ "viewer.desktopSize",
54
+ "viewer.tabletSize",
55
+ "viewer.mobileSize",
56
+ "viewer.toggleBackgroundGrid",
57
+ "viewer.canvasGrid",
58
+ "viewer.resetPreviewCanvas",
59
+ "viewer.resetCanvas",
60
+ "viewer.copyAiContext",
61
+ "viewer.copyCodeForAi",
62
+ "viewer.copyCliInstallation",
63
+ "viewer.fullscreenPreview",
64
+ "viewer.exitFullscreen",
65
+ "code.copied",
66
+ "code.copy",
67
+ "command.navigate",
68
+ "command.select",
69
+ "command.close",
70
+ "image.avatar",
71
+ "status.loading",
72
+ "status.loadingLabel",
73
+ "accessibility.callout",
74
+ "errors.pageNotFound",
75
+ "errors.pageNotFoundDescription",
76
+ "apiTable.property",
77
+ "apiTable.type",
78
+ "apiTable.default",
79
+ "apiTable.description",
80
+ ];
81
+ const KEY_SET = new Set(SITE_TRANSLATION_KEYS);
82
+ function validateLocale(locale, value) {
83
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
84
+ throw new Error(`[folio] Translation file for locale "${locale}" must contain a JSON object`);
85
+ }
86
+ const entries = Object.entries(value);
87
+ for (const [key, translation] of entries) {
88
+ if (!KEY_SET.has(key))
89
+ throw new Error(`[folio] Unknown site translation key "${key}" in locale "${locale}"`);
90
+ if (typeof translation !== "string")
91
+ throw new Error(`[folio] Translation "${locale}.${key}" must be a string`);
92
+ }
93
+ return value;
94
+ }
95
+ export async function loadSiteTranslations(rootDir, config = {}) {
96
+ const defaultLocale = config.defaultLocale || "en";
97
+ const directory = config.directory || "locales";
98
+ const localeDir = path.resolve(rootDir, directory);
99
+ const translations = {};
100
+ if (await fs.pathExists(localeDir)) {
101
+ const files = (await fs.readdir(localeDir))
102
+ .filter((file) => file.endsWith(".json"))
103
+ .sort();
104
+ for (const file of files) {
105
+ const locale = path.basename(file, ".json");
106
+ translations[locale] = validateLocale(locale, await fs.readJson(path.join(localeDir, file)));
107
+ }
108
+ }
109
+ if (!translations[defaultLocale])
110
+ translations[defaultLocale] = {};
111
+ return { ...config, defaultLocale, directory, locale: config.locale || defaultLocale, translations };
112
+ }
113
+ export function getSiteTranslation(config, key) {
114
+ const locale = config?.locale || config?.defaultLocale || "en";
115
+ const defaultLocale = config?.defaultLocale || "en";
116
+ return config?.translations?.[locale]?.[key]
117
+ || config?.translations?.[defaultLocale]?.[key]
118
+ || key;
119
+ }
@@ -4,9 +4,18 @@ export interface SearchContext {
4
4
  query: string;
5
5
  pages: PageData[];
6
6
  }
7
+ export interface SearchAdapterRuntime {
8
+ /** Browser module that exports the adapter factory. */
9
+ module: string;
10
+ /** Named export containing a factory that receives the optional adapter options. */
11
+ exportName: string;
12
+ /** JSON-serializable options passed to the browser adapter factory. */
13
+ options?: unknown;
14
+ }
7
15
  export interface SearchAdapter {
8
16
  name: string;
9
17
  search: (context: SearchContext) => PageData[] | Promise<PageData[]>;
18
+ runtime?: SearchAdapterRuntime;
10
19
  }
11
20
  export type ConfiguredSearchProvider = NonNullable<DocsConfig["search"]>["provider"];
12
21
  export interface ResolvedSearchProvider {
@@ -17,7 +17,7 @@ export const localSearchAdapter = {
17
17
  */
18
18
  export function resolveSearchProvider(search) {
19
19
  const configuredProvider = search?.provider;
20
- if (configuredProvider && typeof configuredProvider !== "string") {
20
+ if (configuredProvider && typeof configuredProvider !== "string" && typeof configuredProvider.search === "function") {
21
21
  return {
22
22
  requested: configuredProvider.name,
23
23
  active: configuredProvider.name,
@@ -25,7 +25,9 @@ export function resolveSearchProvider(search) {
25
25
  implementation: configuredProvider,
26
26
  };
27
27
  }
28
- const requested = configuredProvider?.trim() || LOCAL_SEARCH_PROVIDER;
28
+ const requested = typeof configuredProvider === "string"
29
+ ? configuredProvider.trim() || LOCAL_SEARCH_PROVIDER
30
+ : configuredProvider?.name || LOCAL_SEARCH_PROVIDER;
29
31
  return {
30
32
  requested,
31
33
  active: LOCAL_SEARCH_PROVIDER,
@@ -1,5 +1,6 @@
1
1
  import { type ViteDevServer } from "vite";
2
2
  import type { DocsConfig } from "../types.js";
3
+ import { type FolioBuildSession } from "./plugin/lifecycle.js";
3
4
  export interface DocsServerOptions {
4
5
  root?: string;
5
6
  docsDir?: string;
@@ -8,10 +9,12 @@ export interface DocsServerOptions {
8
9
  open?: boolean;
9
10
  config?: DocsConfig;
10
11
  outDir?: string;
12
+ /** Shared plugin lifecycle for one production build. */
13
+ lifecycleSession?: FolioBuildSession;
11
14
  }
12
15
  export declare function getClientDir(): string;
13
16
  export declare function createDocsServer(options?: DocsServerOptions): Promise<ViteDevServer>;
14
17
  export declare function buildDocs(options?: DocsServerOptions): Promise<void>;
15
18
  export declare function createDocsRequestHandler(options?: DocsServerOptions): Promise<(request: Request) => Promise<Response>>;
16
19
  export declare function previewDocs(options?: DocsServerOptions): Promise<void>;
17
- export * from "./plugin.js";
20
+ export * from "./plugin/index.js";
@@ -8,9 +8,11 @@ import solidPlugin from "vite-plugin-solid";
8
8
  import tailwindcss from "@tailwindcss/vite";
9
9
  import fs from "fs-extra";
10
10
  import matter from "gray-matter";
11
- import { nikalaDocsPlugin } from "./plugin.js";
12
- import { loadConfig } from "../config.js";
11
+ import { nikalaDocsPlugin } from "./plugin/index.js";
12
+ import { loadConfig, resolvePluginConfig } from "../config.js";
13
13
  import { scanContent } from "../core/content-scanner.js";
14
+ import { getPageLastModified, isPageIndexable, renderSeoMetadata } from "./seo.js";
15
+ import { createFolioBuildSession } from "./plugin/lifecycle.js";
14
16
  const __filename = fileURLToPath(import.meta.url);
15
17
  const __dirname = path.dirname(__filename);
16
18
  export function getClientDir() {
@@ -104,6 +106,7 @@ function getSharedConfig(options, isDev = false, isSSR = false) {
104
106
  const root = options.root ? path.resolve(process.cwd(), options.root) : process.cwd();
105
107
  const clientDir = getClientDir();
106
108
  const publicDir = path.join(root, "public");
109
+ const sourcePublicDir = path.resolve(__dirname, "../../src/client/public");
107
110
  const solidJsDir = getSolidJsDir();
108
111
  const docsSrc = getDocsSourceDir();
109
112
  const localSrc = path.join(root, "src");
@@ -111,6 +114,7 @@ function getSharedConfig(options, isDev = false, isSSR = false) {
111
114
  const localHooks = path.join(localSrc, "hooks");
112
115
  const localLib = path.join(localSrc, "lib");
113
116
  const localProviders = path.join(localSrc, "providers");
117
+ const localPlugins = path.join(localSrc, "plugins");
114
118
  const componentsSrc = fs.existsSync(localComponents) ? localComponents : path.join(docsSrc, "components/ui");
115
119
  const hooksSource = fs.existsSync(localHooks) ? localHooks : path.join(docsSrc, "hooks");
116
120
  const libSource = fs.existsSync(localLib) ? localLib : path.join(docsSrc, "lib");
@@ -122,14 +126,18 @@ function getSharedConfig(options, isDev = false, isSSR = false) {
122
126
  const solidEntry = isSSR ? "dist/server.js" : isDev ? "dist/dev.js" : "dist/solid.js";
123
127
  aliases.push({ find: "solid-js/web", replacement: path.join(solidJsDir, webEntry) }, { find: "solid-js/store", replacement: path.join(solidJsDir, storeEntry) }, { find: "solid-js/html", replacement: path.join(solidJsDir, "html/dist/html.js") }, { find: "solid-js/h", replacement: path.join(solidJsDir, "h/dist/h.js") }, { find: "solid-js", replacement: path.join(solidJsDir, solidEntry) });
124
128
  }
125
- aliases.push({ find: "@/lib", replacement: libSource }, { find: "@/providers", replacement: providersSource }, { find: /^@\/components\/ui\/(.*)$/, replacement: path.join(componentsSrc, "$1") }, { find: /^@\/hooks\/(.*)$/, replacement: path.join(hooksSource, "$1") });
129
+ aliases.push({ find: "@/lib", replacement: libSource }, { find: "@/providers", replacement: providersSource }, ...(fs.existsSync(localPlugins) ? [{ find: /^@\/plugins\/(.*)$/, replacement: path.join(localPlugins, "$1") }] : []), { find: /^@\/components\/(.*)$/, replacement: path.join(path.dirname(componentsSrc), "$1") }, { find: /^@\/components\/ui\/(.*)$/, replacement: path.join(componentsSrc, "$1") }, { find: /^@\/hooks\/(.*)$/, replacement: path.join(hooksSource, "$1") });
126
130
  return {
127
131
  root: clientDir,
128
132
  // The consuming documentation project owns its public Vite environment
129
133
  // variables (for example VITE_ALGOLIA_*). Vite's root is the packaged
130
134
  // Folio client, so point env loading back at the consumer project.
131
135
  envDir: root,
132
- publicDir: fs.existsSync(publicDir) ? publicDir : path.join(clientDir, "public"),
136
+ publicDir: fs.existsSync(publicDir)
137
+ ? publicDir
138
+ : isDev && fs.existsSync(sourcePublicDir)
139
+ ? sourcePublicDir
140
+ : path.join(clientDir, "public"),
133
141
  resolve: {
134
142
  alias: aliases,
135
143
  dedupe: ["solid-js", "solid-js/web", "solid-js/store"],
@@ -145,6 +153,7 @@ function getSharedConfig(options, isDev = false, isSSR = false) {
145
153
  docsDir: options.docsDir ? path.resolve(root, options.docsDir) : undefined,
146
154
  configRoot: root,
147
155
  config: options.config,
156
+ lifecycleSession: options.lifecycleSession,
148
157
  }),
149
158
  tailwindcss(),
150
159
  solidPlugin({
@@ -334,11 +343,9 @@ async function renderWithTimeout(renderer, url) {
334
343
  new Promise((_, reject) => setTimeout(() => reject(new Error("SSR render timed out")), 10_000)),
335
344
  ]);
336
345
  }
337
- async function prerenderDocs(options, outDir, template) {
346
+ async function prerenderDocs(options, outDir, template, pages) {
338
347
  const root = options.root ? path.resolve(process.cwd(), options.root) : process.cwd();
339
- const config = options.config || await loadConfig(root);
340
- const contentDir = path.resolve(root, options.docsDir || config.contentDir || "docs");
341
- const pages = await scanContent(contentDir);
348
+ const config = options.config ? resolvePluginConfig(options.config) : await loadConfig(root);
342
349
  if (!pages.length)
343
350
  return;
344
351
  const renderer = await createSsrRenderer(options);
@@ -355,12 +362,7 @@ async function prerenderDocs(options, outDir, template) {
355
362
  console.warn(`[folio] SSR fallback for ${page.url}:`, error instanceof Error ? error.message : error);
356
363
  }
357
364
  }
358
- const title = escapeHtml(`${page.title} - ${config.title || "Documentation"}`);
359
- const description = escapeHtml(page.description || config.description || "");
360
- const canonical = config.siteUrl
361
- ? `<link rel="canonical" href="${escapeHtml(`${config.siteUrl.replace(/\/$/, "")}${page.url === "/" ? "/" : page.url}`)}">`
362
- : "";
363
- const metadata = `<title>${title}</title>${description ? `<meta name="description" content="${description}">` : ""}${canonical}`;
365
+ const metadata = renderSeoMetadata(config, page);
364
366
  const html = addHydrationScript(template, renderer?.hydrationScript)
365
367
  .replace(/<title>[^<]*<\/title>/i, metadata)
366
368
  .replace('<div id="root"></div>', `<div id="root" data-prerendered>${content}</div>`);
@@ -370,7 +372,13 @@ async function prerenderDocs(options, outDir, template) {
370
372
  }
371
373
  if (config.siteUrl) {
372
374
  const base = config.siteUrl.replace(/\/$/, "");
373
- const urls = pages.map((page) => `<url><loc>${escapeHtml(`${base}${page.url === "/" ? "/" : page.url}`)}</loc></url>`).join("");
375
+ const urls = pages
376
+ .filter(isPageIndexable)
377
+ .map((page) => {
378
+ const lastmod = getPageLastModified(page);
379
+ return `<url><loc>${escapeHtml(`${base}${page.url === "/" ? "/" : page.url}`)}</loc>${lastmod ? `<lastmod>${lastmod}</lastmod>` : ""}</url>`;
380
+ })
381
+ .join("");
374
382
  await fs.writeFile(path.join(outDir, "sitemap.xml"), `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${urls}</urlset>`);
375
383
  await fs.writeFile(path.join(outDir, "robots.txt"), `User-agent: *\nAllow: /\nSitemap: ${base}/sitemap.xml\n`);
376
384
  }
@@ -437,17 +445,50 @@ export async function createDocsServer(options = {}) {
437
445
  export async function buildDocs(options = {}) {
438
446
  const root = options.root ? path.resolve(process.cwd(), options.root) : process.cwd();
439
447
  const outDir = options.outDir ? path.resolve(root, options.outDir) : path.resolve(root, "dist");
440
- const shared = getSharedConfig(options, false);
441
- await build({
442
- ...shared,
443
- build: {
444
- outDir,
445
- emptyOutDir: true,
446
- },
448
+ const config = options.config ? resolvePluginConfig(options.config) : await loadConfig(root);
449
+ const contentDir = path.resolve(root, options.docsDir || config.contentDir || "docs");
450
+ const lifecycleSession = options.lifecycleSession || createFolioBuildSession({
451
+ plugins: config.plugins,
452
+ config,
453
+ rootDir: root,
454
+ contentDir,
455
+ outputDir: outDir,
456
+ mode: "production",
447
457
  });
448
- const templatePath = path.join(outDir, "index.html");
449
- const template = await fs.readFile(templatePath, "utf-8");
450
- await prerenderDocs(options, outDir, template);
458
+ const buildOptions = { ...options, config, lifecycleSession };
459
+ let lifecycleEnded = false;
460
+ try {
461
+ await build({
462
+ ...getSharedConfig(buildOptions, false),
463
+ build: {
464
+ outDir,
465
+ emptyOutDir: true,
466
+ },
467
+ });
468
+ const templatePath = path.join(outDir, "index.html");
469
+ const template = await fs.readFile(templatePath, "utf-8");
470
+ const pages = await lifecycleSession.pages();
471
+ await prerenderDocs(buildOptions, outDir, template, pages);
472
+ await lifecycleSession.generate();
473
+ lifecycleEnded = true;
474
+ await lifecycleSession.buildEnd({ success: true, outputDir: outDir, pages });
475
+ }
476
+ catch (error) {
477
+ if (lifecycleEnded)
478
+ throw error;
479
+ try {
480
+ lifecycleEnded = true;
481
+ await lifecycleSession.buildEnd({
482
+ success: false,
483
+ outputDir: outDir,
484
+ pages: lifecycleSession.getPages(),
485
+ });
486
+ }
487
+ catch (lifecycleError) {
488
+ throw lifecycleError;
489
+ }
490
+ throw lifecycleSession.getFailure() ?? error;
491
+ }
451
492
  }
452
493
  function contentType(filePath) {
453
494
  const extension = path.extname(filePath).toLowerCase();
@@ -473,7 +514,7 @@ function addHydrationScript(template, hydrationScript) {
473
514
  export async function createDocsRequestHandler(options = {}) {
474
515
  const root = options.root ? path.resolve(process.cwd(), options.root) : process.cwd();
475
516
  const outDir = options.outDir ? path.resolve(root, options.outDir) : path.resolve(root, "dist");
476
- const config = options.config || await loadConfig(root);
517
+ const config = options.config ? resolvePluginConfig(options.config) : await loadConfig(root);
477
518
  const contentDir = path.resolve(root, options.docsDir || config.contentDir || "docs");
478
519
  const pages = await scanContent(contentDir);
479
520
  const template = await fs.readFile(path.join(outDir, "index.html"), "utf-8");
@@ -495,13 +536,8 @@ export async function createDocsRequestHandler(options = {}) {
495
536
  if (renderer) {
496
537
  try {
497
538
  const rendered = await renderWithTimeout(renderer, page.url);
498
- const title = escapeHtml(`${page.title} - ${config.title || "Documentation"}`);
499
- const description = escapeHtml(page.description || config.description || "");
500
- const canonical = config.siteUrl
501
- ? `<link rel="canonical" href="${escapeHtml(`${config.siteUrl.replace(/\/$/, "")}${page.url === "/" ? "/" : page.url}`)}">`
502
- : "";
503
539
  const html = addHydrationScript(template, renderer.hydrationScript)
504
- .replace(/<title>[^<]*<\/title>/i, `<title>${title}</title>${description ? `<meta name="description" content="${description}">` : ""}${canonical}`)
540
+ .replace(/<title>[^<]*<\/title>/i, renderSeoMetadata(config, page))
505
541
  .replace('<div id="root"></div>', `<div id="root" data-prerendered>${rendered}</div>`);
506
542
  return new Response(html, { headers: { "content-type": "text/html; charset=utf-8" } });
507
543
  }
@@ -565,4 +601,4 @@ async function listenWithFallback(server, startPort, host) {
565
601
  }
566
602
  throw new Error(`No available port found from ${startPort}`);
567
603
  }
568
- export * from "./plugin.js";
604
+ export * from "./plugin/index.js";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Serialize a value for inclusion in a generated JavaScript module.
3
+ * JSON.stringify alone does not escape characters that can be interpreted as
4
+ * markup or JavaScript separators when generated code is embedded elsewhere.
5
+ */
6
+ export declare function serializeModuleValue(value: unknown): string;
@@ -0,0 +1,26 @@
1
+ const unsafeJavaScriptCharacters = {
2
+ "<": "\\u003C",
3
+ ">": "\\u003E",
4
+ "/": "\\u002F",
5
+ "\\": "\\u005C",
6
+ "\b": "\\b",
7
+ "\f": "\\f",
8
+ "\n": "\\n",
9
+ "\r": "\\r",
10
+ "\t": "\\t",
11
+ "\0": "\\0",
12
+ "\u2028": "\\u2028",
13
+ "\u2029": "\\u2029",
14
+ };
15
+ /**
16
+ * Serialize a value for inclusion in a generated JavaScript module.
17
+ * JSON.stringify alone does not escape characters that can be interpreted as
18
+ * markup or JavaScript separators when generated code is embedded elsewhere.
19
+ */
20
+ export function serializeModuleValue(value) {
21
+ const serialized = JSON.stringify(value);
22
+ if (serialized === undefined) {
23
+ throw new TypeError("Cannot serialize undefined module value");
24
+ }
25
+ return serialized.replace(/[<>\/\b\f\n\r\t\0\u2028\u2029]/g, (character) => unsafeJavaScriptCharacters[character]);
26
+ }
@@ -0,0 +1,7 @@
1
+ export declare function toLucideComponentName(name: string): string;
2
+ export declare function getComponentSourceDir(rootDir: string, moduleDir: string): string;
3
+ export declare function collectComponentExports(directory: string): Array<{
4
+ name: string;
5
+ file: string;
6
+ }>;
7
+ export declare function collectStaticComponentFiles(componentDir: string, themeDirs: string[]): Set<string>;
@@ -0,0 +1,82 @@
1
+ import path from "node:path";
2
+ import fs from "fs-extra";
3
+ export function toLucideComponentName(name) {
4
+ return name.trim().split(/[-_\s]+/).filter(Boolean)
5
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
6
+ }
7
+ export function getComponentSourceDir(rootDir, moduleDir) {
8
+ const localSource = path.resolve(rootDir, "src/components/ui");
9
+ if (fs.existsSync(localSource))
10
+ return localSource;
11
+ const candidates = [
12
+ path.resolve(moduleDir, "../vendor/docs-src/components/ui"),
13
+ path.resolve(moduleDir, "../../src/components/ui"),
14
+ path.resolve(moduleDir, "../components/ui"),
15
+ ];
16
+ const source = candidates.find((candidate) => fs.existsSync(candidate));
17
+ if (source)
18
+ return source;
19
+ throw new Error("Folio local component sources are missing");
20
+ }
21
+ export function collectComponentExports(directory) {
22
+ if (!fs.existsSync(directory))
23
+ return [];
24
+ return fs.readdirSync(directory, { withFileTypes: true })
25
+ .filter((entry) => entry.isFile() && /\.(?:tsx?|jsx?)$/.test(entry.name) && !/^index\./.test(entry.name))
26
+ .flatMap((entry) => {
27
+ const file = path.join(directory, entry.name);
28
+ const source = fs.readFileSync(file, "utf8");
29
+ const names = new Set();
30
+ for (const match of source.matchAll(/export\s+(?:const|function|class)\s+([A-Z][A-Za-z0-9_$]*)/g))
31
+ names.add(match[1]);
32
+ for (const match of source.matchAll(/export\s*\{([^}]+)\}/g)) {
33
+ for (const name of match[1].split(",")) {
34
+ const exported = name.trim().split(/\s+as\s+/).at(-1);
35
+ if (exported && /^[A-Z][A-Za-z0-9_$]*$/.test(exported))
36
+ names.add(exported);
37
+ }
38
+ }
39
+ return [...names].sort().map((name) => ({ name, file }));
40
+ }).sort((a, b) => a.name.localeCompare(b.name));
41
+ }
42
+ function collectSourceFiles(directory) {
43
+ if (!fs.existsSync(directory))
44
+ return [];
45
+ return fs.readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
46
+ const file = path.join(directory, entry.name);
47
+ if (entry.isDirectory())
48
+ return collectSourceFiles(file);
49
+ return entry.isFile() && /\.(?:tsx?|jsx?)$/.test(entry.name) ? [file] : [];
50
+ });
51
+ }
52
+ function resolveComponentFile(directory, importPath) {
53
+ const base = path.join(directory, importPath);
54
+ return [base, ...[".ts", ".tsx", ".js", ".jsx"].map((ext) => base + ext),
55
+ ...["index.ts", "index.tsx", "index.js", "index.jsx"].map((entry) => path.join(base, entry))]
56
+ .find((file) => fs.existsSync(file));
57
+ }
58
+ export function collectStaticComponentFiles(componentDir, themeDirs) {
59
+ const staticFiles = new Set();
60
+ const pending = themeDirs.flatMap((directory) => collectSourceFiles(directory));
61
+ while (pending.length) {
62
+ const file = pending.pop();
63
+ if (!fs.existsSync(file))
64
+ continue;
65
+ const source = fs.readFileSync(file, "utf8");
66
+ for (const match of source.matchAll(/from\s+["']@\/components\/ui\/([^"']+)["']/g)) {
67
+ const importedFile = resolveComponentFile(componentDir, match[1]);
68
+ if (importedFile && !staticFiles.has(importedFile)) {
69
+ staticFiles.add(importedFile);
70
+ pending.push(importedFile);
71
+ }
72
+ }
73
+ for (const match of source.matchAll(/from\s+["'](\.\.?\/[^"']+)["']/g)) {
74
+ const importedFile = resolveComponentFile(path.dirname(file), match[1]);
75
+ if (importedFile && importedFile.startsWith(`${path.resolve(componentDir)}${path.sep}`) && !staticFiles.has(importedFile)) {
76
+ staticFiles.add(importedFile);
77
+ pending.push(importedFile);
78
+ }
79
+ }
80
+ }
81
+ return staticFiles;
82
+ }
@@ -0,0 +1,17 @@
1
+ export declare const VIRTUAL_CONFIG_ID = "virtual:folio-config";
2
+ export declare const RESOLVED_CONFIG_ID: string;
3
+ export declare const VIRTUAL_TREE_ID = "virtual:folio-tree";
4
+ export declare const RESOLVED_TREE_ID: string;
5
+ export declare const VIRTUAL_ROUTES_ID = "virtual:folio-routes";
6
+ export declare const RESOLVED_ROUTES_ID: string;
7
+ export declare const VIRTUAL_SOURCES_ID = "virtual:folio-sources";
8
+ export declare const RESOLVED_SOURCES_ID: string;
9
+ export declare const VIRTUAL_COMPONENTS_ID = "virtual:folio-components";
10
+ export declare const RESOLVED_COMPONENTS_ID: string;
11
+ export declare const VIRTUAL_ICONS_ID = "virtual:folio-icons";
12
+ export declare const RESOLVED_ICONS_ID: string;
13
+ export declare const VIRTUAL_THEME_ID = "virtual:folio-theme";
14
+ export declare const RESOLVED_THEME_ID: string;
15
+ export declare const VIRTUAL_SHIKI_ID = "virtual:folio-shiki-stub";
16
+ export declare const RESOLVED_SHIKI_ID: string;
17
+ export declare const CONFIG_FILENAMES: Set<string>;
@@ -0,0 +1,21 @@
1
+ export const VIRTUAL_CONFIG_ID = "virtual:folio-config";
2
+ export const RESOLVED_CONFIG_ID = "\0" + VIRTUAL_CONFIG_ID;
3
+ export const VIRTUAL_TREE_ID = "virtual:folio-tree";
4
+ export const RESOLVED_TREE_ID = "\0" + VIRTUAL_TREE_ID;
5
+ export const VIRTUAL_ROUTES_ID = "virtual:folio-routes";
6
+ export const RESOLVED_ROUTES_ID = "\0" + VIRTUAL_ROUTES_ID;
7
+ export const VIRTUAL_SOURCES_ID = "virtual:folio-sources";
8
+ export const RESOLVED_SOURCES_ID = "\0" + VIRTUAL_SOURCES_ID;
9
+ export const VIRTUAL_COMPONENTS_ID = "virtual:folio-components";
10
+ export const RESOLVED_COMPONENTS_ID = "\0" + VIRTUAL_COMPONENTS_ID;
11
+ export const VIRTUAL_ICONS_ID = "virtual:folio-icons";
12
+ export const RESOLVED_ICONS_ID = "\0" + VIRTUAL_ICONS_ID;
13
+ export const VIRTUAL_THEME_ID = "virtual:folio-theme";
14
+ export const RESOLVED_THEME_ID = "\0" + VIRTUAL_THEME_ID;
15
+ export const VIRTUAL_SHIKI_ID = "virtual:folio-shiki-stub";
16
+ export const RESOLVED_SHIKI_ID = "\0" + VIRTUAL_SHIKI_ID;
17
+ export const CONFIG_FILENAMES = new Set([
18
+ "docs.config.ts", "docs.config.js", "docs.config.mjs",
19
+ "nikala.docs.config.ts", "nikala.docs.config.js", "nikala.docs.config.mjs",
20
+ "nikala.config.ts", "nikala.config.js",
21
+ ]);
@@ -1,9 +1,11 @@
1
1
  import type { Plugin } from "vite";
2
- import type { DocsConfig } from "../types.js";
2
+ import type { DocsConfig } from "../../types.js";
3
+ import { type FolioBuildSession } from "./lifecycle.js";
3
4
  export interface NikalaDocsPluginOptions {
4
5
  docsDir?: string;
5
6
  configRoot?: string;
6
7
  configFile?: string;
7
8
  config?: DocsConfig;
9
+ lifecycleSession?: FolioBuildSession;
8
10
  }
9
11
  export declare function nikalaDocsPlugin(options?: NikalaDocsPluginOptions): Plugin;