@nikala-ui/folio 0.14.0 → 0.15.0
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 +16 -0
- package/dist/cli/commands/init.js +21 -2
- package/dist/client/app.jsx +6 -3
- package/dist/client/components/docs-layout-shell.d.ts +1 -0
- package/dist/client/components/docs-layout-shell.jsx +1 -1
- package/dist/client/components/docs-page-content.jsx +9 -5
- package/dist/client/navigation/page-navigation.js +10 -27
- package/dist/client/public/algolia-logo.svg +15 -0
- package/dist/client/public/favicon.ico +0 -0
- package/dist/client/public/logo.svg +11 -0
- package/dist/client/routing/use-docs-router.d.ts +1 -0
- package/dist/client/routing/use-docs-router.js +12 -3
- package/dist/client/style.css +139 -55
- package/dist/components/ui/api-table.jsx +6 -4
- package/dist/components/ui/code-block.jsx +6 -4
- package/dist/components/ui/command.jsx +9 -5
- package/dist/components/ui/list.jsx +3 -1
- package/dist/components/ui/logo.d.ts +4 -1
- package/dist/components/ui/logo.jsx +8 -22
- package/dist/components/ui/package-manager-tabs.jsx +4 -2
- package/dist/components/ui/pager.jsx +4 -2
- package/dist/components/ui/section-heading.jsx +1 -1
- package/dist/components/ui/sidebar.jsx +6 -3
- package/dist/components/ui/spinner.jsx +3 -1
- package/dist/components/ui/theme-toggle.jsx +14 -12
- package/dist/config.d.ts +1 -0
- package/dist/config.js +84 -29
- package/dist/core/content-scanner.d.ts +2 -1
- package/dist/core/content-scanner.js +2 -9
- package/dist/core/plugin/index.d.ts +2 -0
- package/dist/core/plugin/index.js +1 -0
- package/dist/core/plugin/lifecycle-error.d.ts +19 -0
- package/dist/core/plugin/lifecycle-error.js +28 -0
- package/dist/core/plugin/lifecycle-snapshot.d.ts +1 -0
- package/dist/core/plugin/lifecycle-snapshot.js +156 -0
- package/dist/core/plugin/lifecycle.d.ts +34 -0
- package/dist/core/plugin/lifecycle.js +170 -0
- package/dist/core/route-tree.d.ts +3 -2
- package/dist/core/route-tree.js +40 -10
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -3
- package/dist/plugin.d.ts +60 -0
- package/dist/plugin.js +51 -0
- package/dist/plugins/i18n/components/site-language-switcher.d.ts +10 -0
- package/dist/plugins/i18n/components/site-language-switcher.jsx +39 -0
- package/dist/plugins/i18n/constants.d.ts +1 -0
- package/dist/plugins/i18n/constants.js +1 -0
- package/dist/plugins/i18n/index.d.ts +11 -0
- package/dist/plugins/i18n/index.js +89 -0
- package/dist/plugins/i18n/navigation.d.ts +5 -0
- package/dist/plugins/i18n/navigation.js +33 -0
- package/dist/plugins/i18n/runtime.d.ts +19 -0
- package/dist/plugins/i18n/runtime.jsx +65 -0
- package/dist/plugins/i18n/site-locale.d.ts +12 -0
- package/dist/plugins/i18n/site-locale.js +119 -0
- package/dist/server/index.d.ts +4 -1
- package/dist/server/index.js +69 -33
- package/dist/server/module-serialization.d.ts +6 -0
- package/dist/server/module-serialization.js +26 -0
- package/dist/server/plugin/components.d.ts +7 -0
- package/dist/server/plugin/components.js +82 -0
- package/dist/server/plugin/constants.d.ts +17 -0
- package/dist/server/plugin/constants.js +21 -0
- package/dist/server/{plugin.d.ts → plugin/index.d.ts} +3 -1
- package/dist/server/plugin/index.js +166 -0
- package/dist/server/plugin/lifecycle.d.ts +32 -0
- package/dist/server/plugin/lifecycle.js +110 -0
- package/dist/server/plugin/styles.d.ts +3 -0
- package/dist/server/plugin/styles.js +22 -0
- package/dist/server/plugin/virtual-modules.d.ts +11 -0
- package/dist/server/plugin/virtual-modules.js +88 -0
- package/dist/server/seo.d.ts +4 -0
- package/dist/server/seo.js +87 -0
- package/dist/themes/default/content/breadcrumbs.jsx +5 -2
- package/dist/themes/default/content/table-of-contents.jsx +3 -1
- package/dist/themes/default/layout.jsx +39 -12
- package/dist/themes/default/navbar.jsx +14 -7
- package/dist/themes/default/navigation/mobile-table-of-contents.jsx +3 -1
- package/dist/themes/default/navigation/sidebar-tree.d.ts +2 -0
- package/dist/themes/default/navigation/sidebar-tree.jsx +11 -2
- package/dist/themes/default/overlays/search-dialog.jsx +14 -3
- package/dist/themes/default/sidebar.jsx +7 -5
- package/dist/themes/types.d.ts +5 -0
- package/dist/types.d.ts +36 -0
- package/dist/utils/format-title.d.ts +1 -0
- package/dist/utils/format-title.js +11 -0
- package/dist/vendor/docs-src/components/ui/api-table.tsx +6 -4
- package/dist/vendor/docs-src/components/ui/code-block.tsx +6 -4
- package/dist/vendor/docs-src/components/ui/command.tsx +9 -5
- package/dist/vendor/docs-src/components/ui/list.tsx +4 -2
- package/dist/vendor/docs-src/components/ui/logo.tsx +19 -48
- package/dist/vendor/docs-src/components/ui/package-manager-tabs.tsx +4 -2
- package/dist/vendor/docs-src/components/ui/pager.tsx +4 -2
- package/dist/vendor/docs-src/components/ui/section-heading.tsx +5 -1
- package/dist/vendor/docs-src/components/ui/sidebar.tsx +7 -4
- package/dist/vendor/docs-src/components/ui/spinner.tsx +3 -1
- package/dist/vendor/docs-src/components/ui/theme-toggle.tsx +15 -13
- package/dist/vendor/docs-src/plugins/i18n/components/site-language-switcher.tsx +56 -0
- package/dist/vendor/docs-src/plugins/i18n/constants.ts +1 -0
- package/dist/vendor/docs-src/plugins/i18n/index.ts +110 -0
- package/dist/vendor/docs-src/plugins/i18n/navigation.ts +49 -0
- package/dist/vendor/docs-src/plugins/i18n/runtime.tsx +91 -0
- package/dist/vendor/docs-src/plugins/i18n/site-locale.ts +140 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +11 -4
- package/dist/server/plugin.js +0 -521
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createFolioPlugin, type FolioPlugin } from "../../plugin.js";
|
|
2
|
+
|
|
3
|
+
export * from "./site-locale.js";
|
|
4
|
+
|
|
5
|
+
export interface I18nPluginOptions {
|
|
6
|
+
defaultLocale: string;
|
|
7
|
+
locales: readonly string[];
|
|
8
|
+
frontmatterKey?: string;
|
|
9
|
+
translations?: {
|
|
10
|
+
directory?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function normalizeLocale(value: string, label: string): string {
|
|
15
|
+
const locale = value.trim();
|
|
16
|
+
if (!locale) throw new Error(`[folio:i18n] ${label} must not be empty`);
|
|
17
|
+
return locale;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function normalizeOptions(options: I18nPluginOptions): Required<I18nPluginOptions> {
|
|
21
|
+
const defaultLocale = normalizeLocale(options.defaultLocale, "defaultLocale");
|
|
22
|
+
const locales = options.locales.map((locale, index) => normalizeLocale(locale, `locales[${index}]`));
|
|
23
|
+
if (locales.length === 0) throw new Error("[folio:i18n] locales must contain at least one locale");
|
|
24
|
+
if (!locales.includes(defaultLocale)) {
|
|
25
|
+
throw new Error(`[folio:i18n] defaultLocale "${defaultLocale}" must be included in locales`);
|
|
26
|
+
}
|
|
27
|
+
if (new Set(locales).size !== locales.length) {
|
|
28
|
+
throw new Error("[folio:i18n] locales must not contain duplicates");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
defaultLocale,
|
|
33
|
+
locales,
|
|
34
|
+
frontmatterKey: options.frontmatterKey?.trim() || "locale",
|
|
35
|
+
translations: {
|
|
36
|
+
directory: options.translations?.directory?.trim() || "locales",
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function routeFromLocaleDirectory(page: { url: string; sourcePath?: string }, locale: string, defaultLocale: string): string {
|
|
42
|
+
const sourcePath = page.sourcePath?.split("/") ?? [];
|
|
43
|
+
const sourceLocale = sourcePath[0];
|
|
44
|
+
if (sourceLocale !== locale) return page.url;
|
|
45
|
+
|
|
46
|
+
const segments = page.url.split("/").filter(Boolean);
|
|
47
|
+
if (locale === defaultLocale) segments.shift();
|
|
48
|
+
return segments.length ? `/${segments.join("/")}` : "/";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function slugFromUrl(url: string): string {
|
|
52
|
+
return url === "/" ? "index" : url.slice(1).replace(/\//g, "-");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function createI18nPlugin(options: I18nPluginOptions): FolioPlugin {
|
|
56
|
+
const resolved = normalizeOptions(options);
|
|
57
|
+
|
|
58
|
+
return createFolioPlugin(() => ({
|
|
59
|
+
name: "i18n",
|
|
60
|
+
config: {
|
|
61
|
+
uiLocale: {
|
|
62
|
+
defaultLocale: resolved.defaultLocale,
|
|
63
|
+
directory: resolved.translations.directory,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
pagesGenerated: (pages) => pages.map((page) => {
|
|
67
|
+
const sourceLocale = page.sourcePath?.split("/")[0];
|
|
68
|
+
if (sourceLocale && resolved.locales.includes(sourceLocale)) {
|
|
69
|
+
const url = routeFromLocaleDirectory(page, sourceLocale, resolved.defaultLocale);
|
|
70
|
+
return {
|
|
71
|
+
...page,
|
|
72
|
+
slug: slugFromUrl(url),
|
|
73
|
+
url,
|
|
74
|
+
frontmatter: {
|
|
75
|
+
...page.frontmatter,
|
|
76
|
+
[resolved.frontmatterKey]: sourceLocale,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const declaredLocale = page.frontmatter[resolved.frontmatterKey];
|
|
82
|
+
if (declaredLocale !== undefined && String(declaredLocale) !== resolved.defaultLocale) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`[folio:i18n] non-default locale "${String(declaredLocale)}" must be stored under a matching locale directory`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return page;
|
|
88
|
+
}),
|
|
89
|
+
pageTransformed: (page) => {
|
|
90
|
+
const rawLocale = page.frontmatter[resolved.frontmatterKey];
|
|
91
|
+
const locale = rawLocale === undefined
|
|
92
|
+
? resolved.defaultLocale
|
|
93
|
+
: normalizeLocale(String(rawLocale), `frontmatter.${resolved.frontmatterKey}`);
|
|
94
|
+
|
|
95
|
+
if (!resolved.locales.includes(locale)) {
|
|
96
|
+
throw new Error(
|
|
97
|
+
`[folio:i18n] unsupported locale "${locale}"; expected one of ${resolved.locales.join(", ")}`,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
...page,
|
|
103
|
+
frontmatter: {
|
|
104
|
+
...page.frontmatter,
|
|
105
|
+
[resolved.frontmatterKey]: locale,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { PageData, SidebarItem } from "../../types.js";
|
|
2
|
+
|
|
3
|
+
export function getPageLocale(page: PageData): string | undefined {
|
|
4
|
+
const locale = page.frontmatter.locale;
|
|
5
|
+
return typeof locale === "string" ? locale : undefined;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getPageTranslationKey(page: PageData): string {
|
|
9
|
+
const locale = getPageLocale(page);
|
|
10
|
+
const sourcePath = page.sourcePath || page.url;
|
|
11
|
+
const prefix = locale ? `${locale}/` : "";
|
|
12
|
+
return locale && sourcePath.startsWith(prefix) ? sourcePath.slice(prefix.length) : sourcePath;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function findLocalizedPage(
|
|
16
|
+
pages: readonly PageData[],
|
|
17
|
+
page: PageData | undefined,
|
|
18
|
+
locale: string,
|
|
19
|
+
): PageData | undefined {
|
|
20
|
+
if (!page) return undefined;
|
|
21
|
+
const key = getPageTranslationKey(page);
|
|
22
|
+
return pages.find((candidate) => getPageLocale(candidate) === locale && getPageTranslationKey(candidate) === key);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function localizeSidebarTree(
|
|
26
|
+
tree: readonly SidebarItem[],
|
|
27
|
+
pages: readonly PageData[],
|
|
28
|
+
locale: string,
|
|
29
|
+
): SidebarItem[] {
|
|
30
|
+
const localizedPages = new Map(
|
|
31
|
+
pages
|
|
32
|
+
.filter((page) => getPageLocale(page) === locale)
|
|
33
|
+
.map((page) => [getPageTranslationKey(page), page]),
|
|
34
|
+
);
|
|
35
|
+
const pageByHref = new Map(pages.map((page) => [page.url, page]));
|
|
36
|
+
|
|
37
|
+
const localize = (item: SidebarItem): SidebarItem => {
|
|
38
|
+
const sourcePage = item.href ? pageByHref.get(item.href) : undefined;
|
|
39
|
+
const localizedPage = sourcePage ? localizedPages.get(getPageTranslationKey(sourcePage)) : undefined;
|
|
40
|
+
return {
|
|
41
|
+
...item,
|
|
42
|
+
title: localizedPage?.title || item.title,
|
|
43
|
+
href: localizedPage?.url || item.href,
|
|
44
|
+
items: item.items?.map(localize),
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return tree.map(localize);
|
|
49
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { createContext, createEffect, createSignal, useContext, type Accessor, type ParentComponent } from "solid-js";
|
|
2
|
+
import type { PageData } from "../../types.js";
|
|
3
|
+
import { findLocalizedPage, getPageLocale } from "./navigation.js";
|
|
4
|
+
import { SITE_LOCALE_STORAGE_KEY } from "./constants.js";
|
|
5
|
+
import type { DocsUiLocaleConfig, SiteTranslationKey } from "./site-locale.js";
|
|
6
|
+
|
|
7
|
+
interface SiteLocaleContextValue {
|
|
8
|
+
locale: Accessor<string>;
|
|
9
|
+
locales: Accessor<string[]>;
|
|
10
|
+
setLocale: (locale: string) => void;
|
|
11
|
+
t: (key: SiteTranslationKey, values?: Record<string, string>) => string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type SiteLocaleRuntimeGlobal = typeof globalThis & {
|
|
15
|
+
__folioSiteLocaleContext?: ReturnType<typeof createContext<SiteLocaleContextValue | undefined>>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Dev mode can load the bundled client and source theme files in one realm.
|
|
19
|
+
// Keep one context identity across those module copies without coupling the
|
|
20
|
+
// server resolver to a plugin-specific filesystem path.
|
|
21
|
+
const runtimeGlobal = globalThis as SiteLocaleRuntimeGlobal;
|
|
22
|
+
const SiteLocaleContext = runtimeGlobal.__folioSiteLocaleContext
|
|
23
|
+
|| (runtimeGlobal.__folioSiteLocaleContext = createContext<SiteLocaleContextValue>());
|
|
24
|
+
|
|
25
|
+
interface SiteLocaleProviderProps {
|
|
26
|
+
config?: DocsUiLocaleConfig;
|
|
27
|
+
pages?: readonly PageData[];
|
|
28
|
+
currentPage?: PageData;
|
|
29
|
+
currentPath?: string;
|
|
30
|
+
onNavigate?: (url: string) => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const SiteLocaleProvider: ParentComponent<SiteLocaleProviderProps> = (props) => {
|
|
34
|
+
const configuredInitial = props.config?.locale || props.config?.defaultLocale || "en";
|
|
35
|
+
const currentPage = () => props.currentPage || props.pages?.find((page) => page.url === props.currentPath);
|
|
36
|
+
const pageInitial = () => {
|
|
37
|
+
const page = currentPage();
|
|
38
|
+
return (page ? getPageLocale(page) : undefined) || configuredInitial;
|
|
39
|
+
};
|
|
40
|
+
const [locale, setLocale] = createSignal(pageInitial());
|
|
41
|
+
const locales = () => Object.keys(props.config?.translations || {}).sort();
|
|
42
|
+
const setSiteLocale = (next: string) => {
|
|
43
|
+
if (locales().includes(next)) setLocale(next);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
createEffect(() => {
|
|
47
|
+
const currentPath = props.currentPath;
|
|
48
|
+
if (typeof window === "undefined") return;
|
|
49
|
+
|
|
50
|
+
const saved = window.localStorage.getItem(SITE_LOCALE_STORAGE_KEY);
|
|
51
|
+
const preferredLocale = saved && locales().includes(saved) ? saved : pageInitial();
|
|
52
|
+
if (!currentPath) {
|
|
53
|
+
setSiteLocale(preferredLocale);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const currentPage = props.pages?.find((page) => page.url === currentPath);
|
|
58
|
+
const localizedPage = findLocalizedPage(props.pages || [], currentPage, preferredLocale);
|
|
59
|
+
if (!localizedPage && currentPage) {
|
|
60
|
+
setSiteLocale(getPageLocale(currentPage) || configuredInitial);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
setSiteLocale(preferredLocale);
|
|
64
|
+
if (localizedPage && localizedPage.url !== currentPath) props.onNavigate?.(localizedPage.url);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const t = (key: SiteTranslationKey, values: Record<string, string> = {}) => {
|
|
68
|
+
const translations = props.config?.translations || {};
|
|
69
|
+
const defaultLocale = props.config?.defaultLocale || "en";
|
|
70
|
+
const text = translations[locale()]?.[key] || translations[defaultLocale]?.[key] || key;
|
|
71
|
+
return Object.entries(values).reduce((result, [name, value]) => result.replaceAll(`{${name}}`, value), text);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const value: SiteLocaleContextValue = {
|
|
75
|
+
locale,
|
|
76
|
+
locales,
|
|
77
|
+
setLocale: (next) => {
|
|
78
|
+
setSiteLocale(next);
|
|
79
|
+
window.localStorage.setItem(SITE_LOCALE_STORAGE_KEY, next);
|
|
80
|
+
},
|
|
81
|
+
t,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
return <SiteLocaleContext.Provider value={value}>{props.children}</SiteLocaleContext.Provider>;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export function useSiteLocale(): SiteLocaleContextValue {
|
|
88
|
+
const context = useContext(SiteLocaleContext);
|
|
89
|
+
if (!context) throw new Error("useSiteLocale must be used within a SiteLocaleProvider");
|
|
90
|
+
return context;
|
|
91
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
|
|
4
|
+
export { SITE_LOCALE_STORAGE_KEY } from "./constants.js";
|
|
5
|
+
|
|
6
|
+
export const SITE_TRANSLATION_KEYS = [
|
|
7
|
+
"navigation.search",
|
|
8
|
+
"navigation.searchLabel",
|
|
9
|
+
"navigation.toggleSidebar",
|
|
10
|
+
"navigation.closeSidebar",
|
|
11
|
+
"navigation.documentation",
|
|
12
|
+
"navigation.primary",
|
|
13
|
+
"navigation.github",
|
|
14
|
+
"navigation.chooseLanguage",
|
|
15
|
+
"navigation.toggleNavigation",
|
|
16
|
+
"navigation.toggleSidebarRail",
|
|
17
|
+
"navigation.sidebar",
|
|
18
|
+
"navigation.collapse",
|
|
19
|
+
"navigation.expand",
|
|
20
|
+
"navigation.breadcrumb",
|
|
21
|
+
"actions.viewSource",
|
|
22
|
+
"actions.copyPage",
|
|
23
|
+
"actions.copyAsMarkdown",
|
|
24
|
+
"actions.learnMore",
|
|
25
|
+
"actions.copyDocumentationPage",
|
|
26
|
+
"actions.openInProvider",
|
|
27
|
+
"actions.copied",
|
|
28
|
+
"actions.prompt",
|
|
29
|
+
"actions.copyContext",
|
|
30
|
+
"actions.copyCliCommand",
|
|
31
|
+
"actions.copyCode",
|
|
32
|
+
"actions.exitFullscreen",
|
|
33
|
+
"actions.expandFullscreen",
|
|
34
|
+
"tableOfContents.title",
|
|
35
|
+
"search.placeholder",
|
|
36
|
+
"search.empty",
|
|
37
|
+
"search.pages",
|
|
38
|
+
"search.by",
|
|
39
|
+
"search.commandPlaceholder",
|
|
40
|
+
"search.noResults",
|
|
41
|
+
"pagination.previous",
|
|
42
|
+
"pagination.next",
|
|
43
|
+
"theme.toggle",
|
|
44
|
+
"theme.light",
|
|
45
|
+
"theme.dark",
|
|
46
|
+
"theme.system",
|
|
47
|
+
"theme.mode",
|
|
48
|
+
"theme.brandAccentColor",
|
|
49
|
+
"theme.borderRadius",
|
|
50
|
+
"viewer.preview",
|
|
51
|
+
"viewer.code",
|
|
52
|
+
"viewer.desktopViewport",
|
|
53
|
+
"viewer.tabletViewport",
|
|
54
|
+
"viewer.mobileViewport",
|
|
55
|
+
"viewer.desktopSize",
|
|
56
|
+
"viewer.tabletSize",
|
|
57
|
+
"viewer.mobileSize",
|
|
58
|
+
"viewer.toggleBackgroundGrid",
|
|
59
|
+
"viewer.canvasGrid",
|
|
60
|
+
"viewer.resetPreviewCanvas",
|
|
61
|
+
"viewer.resetCanvas",
|
|
62
|
+
"viewer.copyAiContext",
|
|
63
|
+
"viewer.copyCodeForAi",
|
|
64
|
+
"viewer.copyCliInstallation",
|
|
65
|
+
"viewer.fullscreenPreview",
|
|
66
|
+
"viewer.exitFullscreen",
|
|
67
|
+
"code.copied",
|
|
68
|
+
"code.copy",
|
|
69
|
+
"command.navigate",
|
|
70
|
+
"command.select",
|
|
71
|
+
"command.close",
|
|
72
|
+
"image.avatar",
|
|
73
|
+
"status.loading",
|
|
74
|
+
"status.loadingLabel",
|
|
75
|
+
"accessibility.callout",
|
|
76
|
+
"errors.pageNotFound",
|
|
77
|
+
"errors.pageNotFoundDescription",
|
|
78
|
+
"apiTable.property",
|
|
79
|
+
"apiTable.type",
|
|
80
|
+
"apiTable.default",
|
|
81
|
+
"apiTable.description",
|
|
82
|
+
] as const;
|
|
83
|
+
|
|
84
|
+
export type SiteTranslationKey = (typeof SITE_TRANSLATION_KEYS)[number];
|
|
85
|
+
export type SiteTranslations = Record<SiteTranslationKey, string>;
|
|
86
|
+
|
|
87
|
+
export interface DocsUiLocaleConfig {
|
|
88
|
+
defaultLocale?: string;
|
|
89
|
+
directory?: string;
|
|
90
|
+
locale?: string;
|
|
91
|
+
translations?: Record<string, Partial<SiteTranslations>>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const KEY_SET = new Set<string>(SITE_TRANSLATION_KEYS);
|
|
95
|
+
|
|
96
|
+
function validateLocale(locale: string, value: unknown): Partial<SiteTranslations> {
|
|
97
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
98
|
+
throw new Error(`[folio] Translation file for locale "${locale}" must contain a JSON object`);
|
|
99
|
+
}
|
|
100
|
+
const entries = Object.entries(value);
|
|
101
|
+
for (const [key, translation] of entries) {
|
|
102
|
+
if (!KEY_SET.has(key)) throw new Error(`[folio] Unknown site translation key "${key}" in locale "${locale}"`);
|
|
103
|
+
if (typeof translation !== "string") throw new Error(`[folio] Translation "${locale}.${key}" must be a string`);
|
|
104
|
+
}
|
|
105
|
+
return value as Partial<SiteTranslations>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export async function loadSiteTranslations(
|
|
109
|
+
rootDir: string,
|
|
110
|
+
config: DocsUiLocaleConfig = {},
|
|
111
|
+
): Promise<DocsUiLocaleConfig> {
|
|
112
|
+
const defaultLocale = config.defaultLocale || "en";
|
|
113
|
+
const directory = config.directory || "locales";
|
|
114
|
+
const localeDir = path.resolve(rootDir, directory);
|
|
115
|
+
const translations: Record<string, Partial<SiteTranslations>> = {};
|
|
116
|
+
|
|
117
|
+
if (await fs.pathExists(localeDir)) {
|
|
118
|
+
const files = (await fs.readdir(localeDir))
|
|
119
|
+
.filter((file) => file.endsWith(".json"))
|
|
120
|
+
.sort();
|
|
121
|
+
for (const file of files) {
|
|
122
|
+
const locale = path.basename(file, ".json");
|
|
123
|
+
translations[locale] = validateLocale(locale, await fs.readJson(path.join(localeDir, file)));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!translations[defaultLocale]) translations[defaultLocale] = {};
|
|
128
|
+
return { ...config, defaultLocale, directory, locale: config.locale || defaultLocale, translations };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function getSiteTranslation(
|
|
132
|
+
config: DocsUiLocaleConfig | undefined,
|
|
133
|
+
key: SiteTranslationKey,
|
|
134
|
+
): string {
|
|
135
|
+
const locale = config?.locale || config?.defaultLocale || "en";
|
|
136
|
+
const defaultLocale = config?.defaultLocale || "en";
|
|
137
|
+
return config?.translations?.[locale]?.[key]
|
|
138
|
+
|| config?.translations?.[defaultLocale]?.[key]
|
|
139
|
+
|| key;
|
|
140
|
+
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const FOLIO_VERSION = "0.
|
|
1
|
+
export declare const FOLIO_VERSION = "0.15.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const FOLIO_VERSION = "0.
|
|
1
|
+
export const FOLIO_VERSION = "0.15.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nikala-ui/folio",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Zero-config, fast, and elegant documentation engine for SolidJS, built on Nikala UI and Tailwind CSS v4",
|
|
6
6
|
"type": "module",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"import": "./dist/index.js"
|
|
16
16
|
},
|
|
17
17
|
"./plugin": {
|
|
18
|
-
"types": "./dist/server/plugin.d.ts",
|
|
19
|
-
"import": "./dist/server/plugin.js"
|
|
18
|
+
"types": "./dist/server/plugin/index.d.ts",
|
|
19
|
+
"import": "./dist/server/plugin/index.js"
|
|
20
20
|
},
|
|
21
21
|
"./config": {
|
|
22
22
|
"types": "./dist/config.d.ts",
|
|
@@ -53,7 +53,11 @@
|
|
|
53
53
|
"typecheck": "bunx tsc --noEmit -p tsconfig.json",
|
|
54
54
|
"test": "bun test tests",
|
|
55
55
|
"test:browser": "bun tests/ssr-preview.playwright.ts",
|
|
56
|
+
"test:browser-i18n": "bun tests/i18n-browser.playwright.ts",
|
|
57
|
+
"test:browser-hmr": "bun tests/dev-hmr.playwright.ts",
|
|
56
58
|
"test:generated": "bun tests/generated-project.smoke.ts",
|
|
59
|
+
"plugin:perf": "bun scripts/plugin-performance.ts",
|
|
60
|
+
"plugin:memory": "bun scripts/plugin-memory-evidence.ts",
|
|
57
61
|
"package:check": "bun run build && bun scripts/check-package.ts",
|
|
58
62
|
"bundle:check": "bun run docs:build && bun scripts/check-bundle.ts",
|
|
59
63
|
"bump": "bun scripts/bump.ts",
|
|
@@ -61,7 +65,8 @@
|
|
|
61
65
|
"docs:dev": "bun run build && bun dist/cli/index.js dev",
|
|
62
66
|
"docs:build": "bun run build && bun dist/cli/index.js build -o .docs-dist",
|
|
63
67
|
"docs:preview": "bun run build && bun dist/cli/index.js build -o .docs-dist && bun dist/cli/index.js preview -o .docs-dist",
|
|
64
|
-
"
|
|
68
|
+
"index:search": "bun scripts/index-search.ts",
|
|
69
|
+
"check": "bun run typecheck && bun run build && bun run test && bun run docs:build",
|
|
65
70
|
"dev": "tsc -p tsconfig.build.json --watch"
|
|
66
71
|
},
|
|
67
72
|
"dependencies": {
|
|
@@ -94,8 +99,10 @@
|
|
|
94
99
|
"tailwindcss": ">=4.0.0"
|
|
95
100
|
},
|
|
96
101
|
"devDependencies": {
|
|
102
|
+
"@nikala-ui/folio-algolia": "0.2.0",
|
|
97
103
|
"@types/fs-extra": "^11.0.4",
|
|
98
104
|
"@types/node": "^26.1.1",
|
|
105
|
+
"bun-types": "1.3.14",
|
|
99
106
|
"playwright": "1.63.0",
|
|
100
107
|
"solid-js": "^1.9.14",
|
|
101
108
|
"tailwindcss": "^4.0.7",
|