fumapress 0.3.1 → 0.4.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/css/generated.css CHANGED
@@ -39,6 +39,8 @@
39
39
  @source inline("createBlogLayoutPage");
40
40
  @source inline("createBlogTagPage");
41
41
  @source inline("createBlogTagsPage");
42
+ @source inline("createClientAPIPage");
43
+ @source inline("createContext");
42
44
  @source inline("createDocsLayoutPage");
43
45
  @source inline("createHomeLayout");
44
46
  @source inline("createHomeLayoutPage");
@@ -53,10 +55,13 @@
53
55
  @source inline("data");
54
56
  @source inline("data-version");
55
57
  @source inline("date");
58
+ @source inline("decoded");
56
59
  @source inline("decoration-fd-primary");
57
60
  @source inline("default");
61
+ @source inline("defined");
58
62
  @source inline("detect");
59
63
  @source inline("detector");
64
+ @source inline("do");
60
65
  @source inline("duration-150");
61
66
  @source inline("else");
62
67
  @source inline("empty");
@@ -66,6 +71,7 @@
66
71
  @source inline("export");
67
72
  @source inline("extends");
68
73
  @source inline("false");
74
+ @source inline("find");
69
75
  @source inline("fixed");
70
76
  @source inline("flex");
71
77
  @source inline("flex-1");
@@ -106,7 +112,9 @@
106
112
  @source inline("inherit");
107
113
  @source inline("inline-flex");
108
114
  @source inline("interface");
115
+ @source inline("is");
109
116
  @source inline("isLoading");
117
+ @source inline("it");
110
118
  @source inline("item");
111
119
  @source inline("items");
112
120
  @source inline("items-center");
@@ -164,6 +172,7 @@
164
172
  @source inline("page");
165
173
  @source inline("pageProps");
166
174
  @source inline("panelButtonVariants");
175
+ @source inline("payload");
167
176
  @source inline("pb-20");
168
177
  @source inline("pb-6");
169
178
  @source inline("posts");
@@ -196,6 +205,7 @@
196
205
  @source inline("rounded-lg");
197
206
  @source inline("rounded-xl");
198
207
  @source inline("schema");
208
+ @source inline("schemaId");
199
209
  @source inline("search");
200
210
  @source inline("setOpen");
201
211
  @source inline("shadow-inner");
@@ -215,6 +225,7 @@
215
225
  @source inline("static");
216
226
  @source inline("string");
217
227
  @source inline("styles");
228
+ @source inline("sure");
218
229
  @source inline("tags");
219
230
  @source inline("tagsPath");
220
231
  @source inline("text-2xl");
@@ -227,6 +238,7 @@
227
238
  @source inline("text-xs");
228
239
  @source inline("the");
229
240
  @source inline("this");
241
+ @source inline("throw");
230
242
  @source inline("title");
231
243
  @source inline("to");
232
244
  @source inline("toc");
@@ -244,12 +256,15 @@
244
256
  @source inline("useCopyButton");
245
257
  @source inline("useDocsSearch");
246
258
  @source inline("useI18n");
259
+ @source inline("useMemo");
247
260
  @source inline("useState");
248
261
  @source inline("useTOCItems");
262
+ @source inline("value");
249
263
  @source inline("variant");
250
264
  @source inline("w-full");
251
265
  @source inline("waku");
252
266
  @source inline("xl:grid-cols-4");
253
267
  @source inline("xl:grid-cols-6");
268
+ @source inline("you");
254
269
  @source inline("z-2");
255
270
  @source inline("z-20");
@@ -0,0 +1,6 @@
1
+ "use client";
2
+ import { createClientAPIPage } from "fumadocs-openapi/ui/create-client";
3
+ //#region src/components/openapi.tsx
4
+ var openapi_default = createClientAPIPage();
5
+ //#endregion
6
+ export { openapi_default as default };
@@ -0,0 +1,21 @@
1
+ "use client";
2
+ import { createContext, use, useMemo } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+ //#region src/components/openapi.payload.tsx
5
+ const Context = createContext(null);
6
+ function PayloadProvider({ payload, children }) {
7
+ return /* @__PURE__ */ jsx(Context, {
8
+ value: useMemo(() => JSON.parse(payload), [payload]),
9
+ children
10
+ });
11
+ }
12
+ function WithPayload({ schemaId, Comp, props }) {
13
+ const payload = use(Context)?.[schemaId];
14
+ if (!payload) throw new Error(`[Fumapress] Failed to find OpenAPI payload for schema "${schemaId}", do you sure it is defined in createOpenAPI()?`);
15
+ return /* @__PURE__ */ jsx(Comp, {
16
+ payload,
17
+ ...props
18
+ });
19
+ }
20
+ //#endregion
21
+ export { PayloadProvider, WithPayload };
package/dist/config.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AppContext } from "./lib/shared.js";
2
- import { Adapter, Awaitable, ServerPlugin } from "./lib/types.js";
2
+ import { Adapter, Awaitable, ServerPluginOption } from "./lib/types.js";
3
3
  import { ComponentType, ReactNode } from "react";
4
4
  import { TranslationsOption } from "fumadocs-ui/contexts/i18n";
5
5
  import { LoaderConfig, LoaderOutput } from "fumadocs-core/source";
@@ -22,12 +22,8 @@ interface Config<C extends ConfigContext = ConfigContext> {
22
22
  /** the default content loader */
23
23
  loader: LoaderOutput<C["loaderConfig"]> | (() => Awaitable<LoaderOutput<C["loaderConfig"]>>);
24
24
  site?: SiteConfig;
25
- layouts?: Partial<Layouts>;
26
- plugins?: ServerPlugin[];
27
- /** adapter for content sources, use `fumadocs-mdx` if not specified */
28
- adapters?: Adapter[];
29
25
  i18n?: I18nConfig$1<C["lang"]>;
30
- meta?: MetaConfig<C>;
26
+ meta?: MetaConfig<NoInfer<C>>;
31
27
  }
32
28
  interface Layouts<C extends ConfigContext = ConfigContext> {
33
29
  root: ComponentType<{
@@ -81,9 +77,13 @@ interface I18nConfigBuilder<Lang extends string> extends I18nConfig$1<Lang> {
81
77
  toCore: () => I18nConfig<Lang>;
82
78
  }
83
79
  interface ConfigBuilder<C extends ConfigContext> extends Config<C> {
84
- usePlugins: (...plugins: ServerPlugin<C>[]) => ConfigBuilder<C>;
80
+ getPlugins: () => ServerPluginOption<C>[];
81
+ getLayouts: () => Partial<Layouts<C>>;
82
+ getAdapters: () => Adapter<C>[];
83
+ usePlugins: (...plugins: ServerPluginOption<C>[]) => ConfigBuilder<C>;
85
84
  useLayouts: (layouts: Partial<Layouts<C>>) => ConfigBuilder<C>;
86
- useAdapters: (...adapters: Adapter[]) => ConfigBuilder<C>;
85
+ /** Add adapter for content sources, use `fumadocs-mdx` if not specified */
86
+ useAdapters: (...adapters: Adapter<C>[]) => ConfigBuilder<C>;
87
87
  }
88
88
  declare function defineConfig<C extends LoaderConfig, L extends string = string>(config: Config<{
89
89
  loaderConfig: C;
package/dist/config.js CHANGED
@@ -1,20 +1,29 @@
1
1
  //#region src/config.ts
2
2
  function defineConfig(config) {
3
+ const plugins = [];
4
+ const layouts = {};
5
+ const adapters = [];
3
6
  return {
4
7
  ...config,
5
- useAdapters(...adapters) {
6
- this.adapters ??= [];
7
- this.adapters.push(...adapters);
8
+ getPlugins() {
9
+ return plugins;
10
+ },
11
+ getAdapters() {
12
+ return adapters;
13
+ },
14
+ getLayouts() {
15
+ return layouts;
16
+ },
17
+ useAdapters(...values) {
18
+ adapters.push(...values);
8
19
  return this;
9
20
  },
10
- useLayouts(layouts) {
11
- this.layouts ??= {};
12
- Object.assign(this.layouts, layouts);
21
+ useLayouts(overrides) {
22
+ Object.assign(layouts, overrides);
13
23
  return this;
14
24
  },
15
- usePlugins(...plugins) {
16
- this.plugins ??= [];
17
- this.plugins.push(...plugins);
25
+ usePlugins(...values) {
26
+ plugins.push(...values);
18
27
  return this;
19
28
  }
20
29
  };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AppContext, AppContextData } from "./lib/shared.js";
1
+ import { AppContext } from "./lib/shared.js";
2
2
  import { BuildMode, Config, ConfigBuilder, ConfigContext, I18nConfig, I18nConfigBuilder, Layouts, MetaConfig, SiteConfig, defineConfig, defineI18nConfig } from "./config.js";
3
- import { Adapter, RouteFns, ServerPlugin } from "./lib/types.js";
4
- export { type Adapter, type AppContext, type AppContextData, BuildMode, Config, ConfigBuilder, ConfigContext, I18nConfig, I18nConfigBuilder, Layouts, MetaConfig, type RouteFns, type ServerPlugin, SiteConfig, defineConfig, defineI18nConfig };
3
+ import { Adapter, AppContextData, RouteFns, ServerPlugin, ServerPluginOption } from "./lib/types.js";
4
+ export { type Adapter, type AppContext, type AppContextData, BuildMode, Config, ConfigBuilder, ConfigContext, I18nConfig, I18nConfigBuilder, Layouts, MetaConfig, type RouteFns, type ServerPlugin, type ServerPluginOption, SiteConfig, defineConfig, defineI18nConfig };
@@ -1,6 +1,6 @@
1
- import { HomeLayoutOptions } from "./home.js";
2
1
  import { AppContext } from "../lib/shared.js";
3
2
  import { ConfigContext } from "../config.js";
3
+ import { HomeLayoutOptions } from "./home.js";
4
4
  import { Awaitable } from "../lib/types.js";
5
5
  import { BlogLayout, BlogLayoutPage } from "../plugins/blog.js";
6
6
  import { ReactNode } from "react";
@@ -1,11 +1,7 @@
1
- import { DocsLayoutContextData } from "../layouts/docs.js";
2
- import { HomeLayoutContextData } from "../layouts/home.js";
3
- import { NotebookLayoutContextData } from "../layouts/notebook.js";
4
1
  import { BuildMode, ConfigContext, I18nConfig, Layouts, MetaConfig } from "../config.js";
5
- import { Adapter, Awaitable, ServerPlugin } from "./types.js";
2
+ import { Adapter, AppContextData, Awaitable, ServerPlugin } from "./types.js";
6
3
  import { ComponentType, ReactNode } from "react";
7
- import { RootProviderProps } from "fumadocs-ui/provider/waku";
8
- import { LoaderOutput, Page } from "fumadocs-core/source";
4
+ import { LoaderOutput } from "fumadocs-core/source";
9
5
 
10
6
  //#region src/lib/shared.d.ts
11
7
  interface AppContext<C extends ConfigContext = ConfigContext> {
@@ -13,7 +9,7 @@ interface AppContext<C extends ConfigContext = ConfigContext> {
13
9
  getLoader: () => Awaitable<LoaderOutput<C["loaderConfig"]>>;
14
10
  plugins: ServerPlugin<C>[];
15
11
  adapters: Adapter<C>[];
16
- layouts: Partial<Layouts<C>>;
12
+ layouts: Layouts<C>;
17
13
  /** always `undefined`, easier way to infer types */
18
14
  $context: C;
19
15
  /**
@@ -33,15 +29,8 @@ interface AppContext<C extends ConfigContext = ConfigContext> {
33
29
  };
34
30
  };
35
31
  }
36
- interface AppContextData {
37
- "core:page-meta"?: ((page: Page) => ReactNode)[];
38
- "core:notebook-layout"?: NotebookLayoutContextData;
39
- "core:docs-layout"?: DocsLayoutContextData;
40
- "core:home-layout"?: HomeLayoutContextData;
41
- "core:provider"?: ((props: RootProviderProps) => Awaitable<RootProviderProps>)[];
42
- }
43
32
  type TransformChildren<T> = Omit<T, "children"> & {
44
33
  children?: ((nodes: ReactNode) => ReactNode)[];
45
34
  };
46
35
  //#endregion
47
- export { AppContext, AppContextData, TransformChildren };
36
+ export { AppContext, TransformChildren };
@@ -2,20 +2,39 @@ import { __toESM } from "../_virtual/_rolldown/runtime.js";
2
2
  import { getGitRootDir } from "./fs.js";
3
3
  import { fumadocsMdx } from "../adapters/mdx.js";
4
4
  import { require_deepmerge } from "../node_modules/.pnpm/@fastify_deepmerge@3.2.1/node_modules/@fastify/deepmerge/index.js";
5
+ import { disableSearchPlugin } from "../plugins/internal/disable-search.js";
5
6
  import path from "node:path";
6
7
  import { Fragment, isValidElement } from "react";
7
8
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
8
9
  //#region src/lib/shared.tsx
9
10
  var import_deepmerge = /* @__PURE__ */ __toESM(require_deepmerge());
10
- function parseConfig(config) {
11
+ async function parseConfig(config) {
12
+ let adapters = config.getAdapters();
13
+ if (adapters.length === 0) adapters = [fumadocsMdx()];
14
+ const ORDER = {
15
+ pre: -1,
16
+ post: 1,
17
+ _: 0
18
+ };
19
+ function resolvePlugins(plugins) {
20
+ const flat = plugins.flat(Infinity);
21
+ flat.push(disableSearchPlugin());
22
+ return flat.sort((a, b) => ORDER[a.enforce ?? "_"] - ORDER[b.enforce ?? "_"]);
23
+ }
24
+ const layouts = config.getLayouts();
11
25
  return {
12
26
  getLoader() {
13
27
  if (typeof config.loader === "function") return config.loader();
14
28
  return config.loader;
15
29
  },
16
- layouts: config.layouts ?? {},
17
- plugins: config.plugins ?? [],
18
- adapters: config.adapters ?? [fumadocsMdx()],
30
+ layouts: {
31
+ ...layouts,
32
+ root: layouts.root ?? (await import("../layouts/root.js")).createRootLayout(),
33
+ page: layouts.page ?? (await import("../layouts/docs.js")).createDocsLayoutPage(),
34
+ notFound: layouts.notFound ?? (await import("fumadocs-ui/layouts/home/not-found")).DefaultNotFound
35
+ },
36
+ plugins: resolvePlugins(config.getPlugins()),
37
+ adapters,
19
38
  $context: void 0,
20
39
  data: {},
21
40
  i18nConfig: config.i18n,
@@ -1,9 +1,14 @@
1
1
  import { AppContext } from "./shared.js";
2
2
  import { ConfigContext } from "../config.js";
3
+ import { DocsLayoutContextData } from "../layouts/docs.js";
4
+ import { HomeLayoutContextData } from "../layouts/home.js";
5
+ import { NotebookLayoutContextData } from "../layouts/notebook.js";
3
6
  import { ReactNode } from "react";
4
7
  import { CreateApi, CreateLayout, CreatePage, CreateRoot, CreateSlice } from "waku/router/server";
5
8
  import { TOCItemType } from "fumadocs-core/toc";
9
+ import { Page } from "fumadocs-core/source";
6
10
  import { StructuredData } from "fumadocs-core/mdx-plugins";
11
+ import { RootProviderProps } from "fumadocs-ui/provider/base";
7
12
 
8
13
  //#region src/lib/types.d.ts
9
14
  type Awaitable<T> = T | Promise<T>;
@@ -17,14 +22,21 @@ interface Adapter<C extends ConfigContext = ConfigContext> {
17
22
  "core:get-modified-date"?: (this: AppContext<C>, page: C["loaderConfig"]["page"]) => Awaitable<Date | undefined>;
18
23
  "blog:get-tags"?: (this: AppContext<C>, page: C["loaderConfig"]["page"]) => Awaitable<string[] | undefined>;
19
24
  }
20
- interface CreatePagesContext<C extends ConfigContext = ConfigContext> extends AppContext<C> {
21
- /** call this function if the page's route is already created by your plugin */
22
- markResolved: (page: C["loaderConfig"]["page"]) => void;
23
- }
24
25
  interface ServerPlugin<C extends ConfigContext = ConfigContext> {
26
+ name?: string;
27
+ /** force change the order of plugin */
28
+ enforce?: "pre" | "post";
25
29
  /** receive & modify context */
26
30
  init?: (this: AppContext<C>) => Awaitable<void>;
27
- createPages?: (this: CreatePagesContext<C>, fns: RouteFns) => Awaitable<void>;
31
+ createPages?: (this: AppContext<C>, fns: RouteFns) => Awaitable<void>;
32
+ /**
33
+ * Resolve the given page before passing to the **default** page renderer:
34
+ *
35
+ * - `object`: replace the page object.
36
+ * - `false`: render not found (will also exclude from static pre-rendering).
37
+ * - `undefined`: fallback to default.
38
+ */
39
+ resolvePage?: (this: AppContext<C>, page: C["loaderConfig"]["page"]) => Awaitable<C["loaderConfig"]["page"] | false | undefined>;
28
40
  }
29
41
  interface BaseRouteFns {
30
42
  createPage: CreatePage;
@@ -37,11 +49,20 @@ interface RouteFns extends BaseRouteFns {
37
49
  createApiIsomorphic: (config: {
38
50
  render: "static" | "dynamic";
39
51
  path: string;
40
- staticPaths?: string[][];
52
+ staticPaths?: string[] | string[][];
41
53
  handler: (req: Request, ctx: {
42
54
  params: Record<string, string | string[]>;
43
55
  }) => Promise<Response>;
44
56
  }) => void;
45
57
  }
58
+ type ServerPluginOption<C extends ConfigContext = ConfigContext> = ServerPlugin<C> | ServerPluginOption<C>[];
59
+ /** can be extended from other libraries */
60
+ interface AppContextData {
61
+ "core:page-meta"?: ((page: Page) => ReactNode)[];
62
+ "core:notebook-layout"?: NotebookLayoutContextData;
63
+ "core:docs-layout"?: DocsLayoutContextData;
64
+ "core:home-layout"?: HomeLayoutContextData;
65
+ "core:provider"?: ((props: RootProviderProps) => Awaitable<RootProviderProps>)[];
66
+ }
46
67
  //#endregion
47
- export { Adapter, Awaitable, RouteFns, ServerPlugin };
68
+ export { Adapter, AppContextData, Awaitable, RouteFns, ServerPlugin, ServerPluginOption };
@@ -12,164 +12,164 @@ function blogPlugin({ paths = {}, isBlog = (page) => page.type === "blog", layou
12
12
  tagsPath: paths.tags ?? "/blog/tags",
13
13
  isBlog
14
14
  };
15
- return { async createPages({ createPage, createLayout }) {
16
- const renderMode = this.mode === "dynamic" ? "dynamic" : "static";
17
- const source = await this.getLoader();
18
- const blogPages = [];
19
- for (const page of source.getPages()) {
20
- if (!isBlog.call(this, page)) continue;
21
- blogPages.push(page);
22
- this.markResolved(page);
23
- }
24
- const Layout = layouts.layout ?? createBlogLayout();
25
- const Page = layouts.page ?? createBlogLayoutPage();
26
- if (this.i18nConfig) {
27
- createLayout({
28
- render: renderMode,
29
- path: "/[lang]/(blog)",
30
- component: ({ lang, children }) => {
31
- return /* @__PURE__ */ jsx(Layout, {
32
- lang,
33
- blog: blogCtx,
34
- ctx: this,
35
- children
36
- });
37
- }
38
- });
39
- createPage({
40
- render: renderMode,
41
- path: "/[lang]/(blog)/[...slugs]",
42
- staticPaths: blogPages.map((page) => [page.locale, ...page.slugs]),
43
- component: async ({ slugs, lang }) => {
44
- const page = (await this.getLoader()).getPage(slugs, lang);
45
- if (!page || !isBlog.call(this, page)) unstable_notFound();
46
- return /* @__PURE__ */ jsx(Page, {
47
- lang,
48
- slugs,
49
- blog: blogCtx,
50
- page,
51
- ctx: this
52
- });
53
- }
54
- });
55
- if (blogCtx.indexPath !== false) {
56
- const IndexPage = layouts.index ?? createBlogIndexPage();
57
- createPage({
15
+ return {
16
+ name: "core:blog",
17
+ resolvePage(page) {
18
+ if (isBlog.call(this, page)) return false;
19
+ },
20
+ async createPages({ createPage, createLayout }) {
21
+ const renderMode = this.mode === "dynamic" ? "dynamic" : "static";
22
+ const blogPages = (await this.getLoader()).getPages().filter((page) => isBlog.call(this, page));
23
+ const Layout = layouts.layout ?? createBlogLayout();
24
+ const Page = layouts.page ?? createBlogLayoutPage();
25
+ if (this.i18nConfig) {
26
+ createLayout({
58
27
  render: renderMode,
59
- path: joinPathname("/[lang]/(blog)", blogCtx.indexPath),
60
- staticPaths: Object.keys(this.i18nConfig.languages),
61
- component: ({ lang }) => {
62
- return /* @__PURE__ */ jsx(IndexPage, {
28
+ path: "/[lang]/(blog)",
29
+ component: ({ lang, children }) => {
30
+ return /* @__PURE__ */ jsx(Layout, {
63
31
  lang,
64
32
  blog: blogCtx,
65
- ctx: this
33
+ ctx: this,
34
+ children
66
35
  });
67
36
  }
68
37
  });
69
- }
70
- if (blogCtx.tagsPath !== false) {
71
- const TagsPage = layouts.tags ?? createBlogTagsPage();
72
- const TagPage = layouts.tag ?? createBlogTagPage();
73
38
  createPage({
74
- path: joinPathname("/[lang]/(blog)", blogCtx.tagsPath),
75
39
  render: renderMode,
76
- staticPaths: Object.keys(this.i18nConfig.languages),
77
- component: ({ lang }) => {
78
- return /* @__PURE__ */ jsx(TagsPage, {
40
+ path: "/[lang]/(blog)/[...slugs]",
41
+ staticPaths: blogPages.map((page) => [page.locale, ...page.slugs]),
42
+ component: async ({ slugs, lang }) => {
43
+ const page = (await this.getLoader()).getPage(slugs, lang);
44
+ if (!page || !isBlog.call(this, page)) unstable_notFound();
45
+ return /* @__PURE__ */ jsx(Page, {
79
46
  lang,
47
+ slugs,
80
48
  blog: blogCtx,
49
+ page,
81
50
  ctx: this
82
51
  });
83
52
  }
84
53
  });
85
- const groupedTags = await groupTagsI18n(this, blogPages);
86
- const staticPaths = [];
87
- for (const [locale, tags] of groupedTags) for (const tag of tags.keys()) staticPaths.push([locale, tag]);
88
- createPage({
89
- path: joinPathname("/[lang]/(blog)", blogCtx.tagsPath, "[tag]"),
90
- render: renderMode,
91
- staticPaths,
92
- component: ({ lang, tag }) => {
93
- return /* @__PURE__ */ jsx(TagPage, {
94
- lang,
95
- tag,
96
- blog: blogCtx,
97
- ctx: this
98
- });
99
- }
100
- });
101
- }
102
- } else {
103
- createLayout({
104
- render: renderMode,
105
- path: "/(blog)",
106
- component: ({ children }) => {
107
- return /* @__PURE__ */ jsx(Layout, {
108
- blog: blogCtx,
109
- ctx: this,
110
- children
54
+ if (blogCtx.indexPath !== false) {
55
+ const IndexPage = layouts.index ?? createBlogIndexPage();
56
+ createPage({
57
+ render: renderMode,
58
+ path: joinPathname("/[lang]/(blog)", blogCtx.indexPath),
59
+ staticPaths: Object.keys(this.i18nConfig.languages),
60
+ component: ({ lang }) => {
61
+ return /* @__PURE__ */ jsx(IndexPage, {
62
+ lang,
63
+ blog: blogCtx,
64
+ ctx: this
65
+ });
66
+ }
111
67
  });
112
68
  }
113
- });
114
- createPage({
115
- render: renderMode,
116
- path: "/(blog)/[...slugs]",
117
- staticPaths: blogPages.map((page) => page.slugs),
118
- component: async ({ slugs }) => {
119
- const page = (await this.getLoader()).getPage(slugs);
120
- if (!page || !isBlog.call(this, page)) unstable_notFound();
121
- return /* @__PURE__ */ jsx(Page, {
122
- blog: blogCtx,
123
- slugs,
124
- page,
125
- ctx: this
69
+ if (blogCtx.tagsPath !== false) {
70
+ const TagsPage = layouts.tags ?? createBlogTagsPage();
71
+ const TagPage = layouts.tag ?? createBlogTagPage();
72
+ createPage({
73
+ path: joinPathname("/[lang]/(blog)", blogCtx.tagsPath),
74
+ render: renderMode,
75
+ staticPaths: Object.keys(this.i18nConfig.languages),
76
+ component: ({ lang }) => {
77
+ return /* @__PURE__ */ jsx(TagsPage, {
78
+ lang,
79
+ blog: blogCtx,
80
+ ctx: this
81
+ });
82
+ }
83
+ });
84
+ const groupedTags = await groupTagsI18n(this, blogPages);
85
+ const staticPaths = [];
86
+ for (const [locale, tags] of groupedTags) for (const tag of tags.keys()) staticPaths.push([locale, tag]);
87
+ createPage({
88
+ path: joinPathname("/[lang]/(blog)", blogCtx.tagsPath, "[tag]"),
89
+ render: renderMode,
90
+ staticPaths,
91
+ component: ({ lang, tag }) => {
92
+ return /* @__PURE__ */ jsx(TagPage, {
93
+ lang,
94
+ tag,
95
+ blog: blogCtx,
96
+ ctx: this
97
+ });
98
+ }
126
99
  });
127
100
  }
128
- });
129
- if (blogCtx.indexPath !== false) {
130
- const IndexPage = layouts.index ?? createBlogIndexPage();
131
- createPage({
101
+ } else {
102
+ createLayout({
132
103
  render: renderMode,
133
- path: joinPathname("/(blog)", blogCtx.indexPath),
134
- staticPaths: [],
135
- component: () => {
136
- return /* @__PURE__ */ jsx(IndexPage, {
104
+ path: "/(blog)",
105
+ component: ({ children }) => {
106
+ return /* @__PURE__ */ jsx(Layout, {
137
107
  blog: blogCtx,
138
- ctx: this
108
+ ctx: this,
109
+ children
139
110
  });
140
111
  }
141
112
  });
142
- }
143
- if (blogCtx.tagsPath !== false) {
144
- const TagsPage = layouts.tags ?? createBlogTagsPage();
145
- const TagPage = layouts.tag ?? createBlogTagPage();
146
113
  createPage({
147
- path: joinPathname("/(blog)", blogCtx.tagsPath),
148
114
  render: renderMode,
149
- staticPaths: [],
150
- component: () => {
151
- return /* @__PURE__ */ jsx(TagsPage, {
152
- blog: blogCtx,
153
- ctx: this
154
- });
155
- }
156
- });
157
- const grouped = await groupTags(this, blogPages);
158
- createPage({
159
- path: joinPathname("/(blog)", blogCtx.tagsPath, "[tag]"),
160
- render: renderMode,
161
- staticPaths: Array.from(grouped.keys()),
162
- component: ({ tag }) => {
163
- return /* @__PURE__ */ jsx(TagPage, {
164
- tag,
115
+ path: "/(blog)/[...slugs]",
116
+ staticPaths: blogPages.map((page) => page.slugs),
117
+ component: async ({ slugs }) => {
118
+ const page = (await this.getLoader()).getPage(slugs);
119
+ if (!page || !isBlog.call(this, page)) unstable_notFound();
120
+ return /* @__PURE__ */ jsx(Page, {
165
121
  blog: blogCtx,
122
+ slugs,
123
+ page,
166
124
  ctx: this
167
125
  });
168
126
  }
169
127
  });
128
+ if (blogCtx.indexPath !== false) {
129
+ const IndexPage = layouts.index ?? createBlogIndexPage();
130
+ createPage({
131
+ render: renderMode,
132
+ path: joinPathname("/(blog)", blogCtx.indexPath),
133
+ staticPaths: [],
134
+ component: () => {
135
+ return /* @__PURE__ */ jsx(IndexPage, {
136
+ blog: blogCtx,
137
+ ctx: this
138
+ });
139
+ }
140
+ });
141
+ }
142
+ if (blogCtx.tagsPath !== false) {
143
+ const TagsPage = layouts.tags ?? createBlogTagsPage();
144
+ const TagPage = layouts.tag ?? createBlogTagPage();
145
+ createPage({
146
+ path: joinPathname("/(blog)", blogCtx.tagsPath),
147
+ render: renderMode,
148
+ staticPaths: [],
149
+ component: () => {
150
+ return /* @__PURE__ */ jsx(TagsPage, {
151
+ blog: blogCtx,
152
+ ctx: this
153
+ });
154
+ }
155
+ });
156
+ const grouped = await groupTags(this, blogPages);
157
+ createPage({
158
+ path: joinPathname("/(blog)", blogCtx.tagsPath, "[tag]"),
159
+ render: renderMode,
160
+ staticPaths: Array.from(grouped.keys()),
161
+ component: ({ tag }) => {
162
+ return /* @__PURE__ */ jsx(TagPage, {
163
+ tag,
164
+ blog: blogCtx,
165
+ ctx: this
166
+ });
167
+ }
168
+ });
169
+ }
170
170
  }
171
171
  }
172
- } };
172
+ };
173
173
  }
174
174
  //#endregion
175
175
  export { blogPlugin };
@@ -13,10 +13,11 @@ function flexsearchPlugin({ buildIndex = async function buildIndexDefault(page)
13
13
  throw new Error("[Fumapress] Please specify the `buildIndex` option to flexsearchPlugin()");
14
14
  } } = {}) {
15
15
  return {
16
+ name: "core:flexsearch",
16
17
  init() {
17
- if (this.mode === "static") (this.data["core:provider"] ??= []).push(async (props) => {
18
- props.search ??= {};
19
- props.search.SearchDialog ??= (await import("../components/flexsearch-static.js")).default;
18
+ (this.data["core:provider"] ??= []).push(async (props) => {
19
+ props.search ??= { enabled: true };
20
+ if (this.mode === "static") props.search.SearchDialog ??= (await import("../components/flexsearch-static.js")).default;
20
21
  return props;
21
22
  });
22
23
  },
@@ -0,0 +1,15 @@
1
+ //#region src/plugins/internal/disable-search.ts
2
+ function disableSearchPlugin() {
3
+ return {
4
+ name: "core:disable-search-if-needed",
5
+ enforce: "post",
6
+ init() {
7
+ (this.data["core:provider"] ??= []).push((data) => {
8
+ data.search ??= { enabled: false };
9
+ return data;
10
+ });
11
+ }
12
+ };
13
+ }
14
+ //#endregion
15
+ export { disableSearchPlugin };
@@ -9,6 +9,7 @@ function llmsPlugin(options = {}) {
9
9
  }
10
10
  } } = options;
11
11
  return {
12
+ name: "core:llms.txt",
12
13
  init() {
13
14
  this.data["core:docs-layout"] ??= {};
14
15
  this.data["core:docs-layout"].renderers ??= [];
@@ -1,10 +1,17 @@
1
1
  import { ConfigContext } from "../config.js";
2
- import { ServerPlugin } from "../lib/types.js";
3
- import { OpenAPIAdapterOptions } from "../adapters/openapi.js";
4
- import { openapiPlugin as openapiLoaderPlugin } from "fumadocs-openapi/server";
2
+ import { Awaitable, ServerPlugin } from "../lib/types.js";
3
+ import { FC } from "react";
4
+ import { OpenAPIServer, openapiPlugin as openapiLoaderPlugin } from "fumadocs-openapi/server";
5
+ import { ClientApiPageProps } from "fumadocs-openapi/ui/create-client";
5
6
 
6
7
  //#region src/plugins/openapi.d.ts
7
- type OpenAPIOptions = OpenAPIAdapterOptions;
8
+ interface OpenAPIOptions {
9
+ server: OpenAPIServer;
10
+ /** must be a client component */
11
+ ClientAPIPage?: FC<ClientApiPageProps>;
12
+ /** create proxy server */
13
+ createProxy?: boolean | (() => Awaitable<ReturnType<OpenAPIServer["createProxy"]>>);
14
+ }
8
15
  /**
9
16
  * this will register the OpenAPI adapter & required layout configs.
10
17
  */
@@ -1,4 +1,6 @@
1
- import { fumadocsOpenAPI, isOpenAPI } from "../adapters/openapi.js";
1
+ import { PayloadProvider, WithPayload } from "../components/openapi.payload.js";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { unstable_notFound } from "waku/router/server";
2
4
  import { openapiPlugin as openapiLoaderPlugin } from "fumadocs-openapi/server";
3
5
  //#region src/plugins/openapi.tsx
4
6
  /**
@@ -11,11 +13,90 @@ function openapiPlugin(options) {
11
13
  return data;
12
14
  });
13
15
  }
14
- return { init() {
15
- this.adapters.push(fumadocsOpenAPI(options));
16
- initRenderers(this.data["core:docs-layout"] ??= {});
17
- initRenderers(this.data["core:notebook-layout"] ??= {});
18
- } };
16
+ return {
17
+ name: "core:openapi",
18
+ init() {
19
+ this.adapters.push(adapter(options));
20
+ initRenderers(this.data["core:docs-layout"] ??= {});
21
+ initRenderers(this.data["core:notebook-layout"] ??= {});
22
+ },
23
+ resolvePage(page) {
24
+ if (isOpenAPI(page.data)) return false;
25
+ },
26
+ async createPages({ createPage, createLayout, createApi }) {
27
+ const { server, createProxy } = options;
28
+ const renderMode = this.mode === "dynamic" ? "dynamic" : "static";
29
+ createLayout({
30
+ path: this.i18nConfig ? "/[lang]/(openapi)" : "/(openapi)",
31
+ render: renderMode,
32
+ async component({ children }) {
33
+ const payload = {};
34
+ for (const [schemaId, schema] of Object.entries(await server.getSchemas())) payload[schemaId] = {
35
+ bundled: schema.bundled,
36
+ proxyUrl: server.options.proxyUrl
37
+ };
38
+ return /* @__PURE__ */ jsx(PayloadProvider, {
39
+ payload: JSON.stringify(payload),
40
+ children
41
+ });
42
+ }
43
+ });
44
+ const staticPaths = [];
45
+ if (renderMode === "static") for (const page of (await this.getLoader()).getPages()) {
46
+ if (!isOpenAPI(page.data)) continue;
47
+ staticPaths.push(page.locale ? [page.locale, ...page.slugs] : page.slugs);
48
+ }
49
+ createPage({
50
+ render: renderMode,
51
+ path: this.i18nConfig ? "/[lang]/(openapi)/[...slugs]" : "/(openapi)/[...slugs]",
52
+ staticPaths,
53
+ component: async ({ slugs, lang }) => {
54
+ const page = (await this.getLoader()).getPage(slugs, lang);
55
+ if (!page || !isOpenAPI(page.data)) unstable_notFound();
56
+ return /* @__PURE__ */ jsx(this.layouts.page, {
57
+ slugs,
58
+ page,
59
+ ctx: this
60
+ });
61
+ }
62
+ });
63
+ if (createProxy) {
64
+ const proxyUrl = server.options.proxyUrl;
65
+ if (!proxyUrl) throw new Error(`[Fumapress] The "proxyUrl" option in createOpenAPI() is required to create proxy server`);
66
+ if (this.mode === "static") throw new Error(`[Fumapress] static mode is not compatible with proxy server`);
67
+ createApi({
68
+ path: proxyUrl,
69
+ render: "dynamic",
70
+ handlers: { all: (typeof createProxy === "function" ? await createProxy() : server.createProxy()).handle }
71
+ });
72
+ }
73
+ }
74
+ };
75
+ }
76
+ function adapter(options) {
77
+ return {
78
+ async "core:render-body"(page) {
79
+ if (isOpenAPI(page.data)) {
80
+ const ClientAPIPage = options.ClientAPIPage ?? (await import("../components/openapi.js")).default;
81
+ const props = page.data.getAPIPageProps();
82
+ return /* @__PURE__ */ jsx(WithPayload, {
83
+ schemaId: props.document,
84
+ Comp: ClientAPIPage,
85
+ props
86
+ });
87
+ }
88
+ },
89
+ "core:render-toc"(page) {
90
+ if (isOpenAPI(page.data)) return page.data.toc;
91
+ },
92
+ "core:get-structured-data"(page) {
93
+ if (isOpenAPI(page.data)) return page.data.structuredData;
94
+ }
95
+ };
96
+ }
97
+ /** @internal */
98
+ function isOpenAPI(data) {
99
+ return "getAPIPageProps" in data && typeof data.getAPIPageProps === "function";
19
100
  }
20
101
  //#endregion
21
102
  export { openapiLoaderPlugin, openapiPlugin };
@@ -13,10 +13,11 @@ function oramaSearchPlugin({ buildIndex = async function buildIndexDefault(page)
13
13
  throw new Error("[Fumapress] Please specify the `buildIndex` option to oramaSearchPlugin()");
14
14
  } } = {}) {
15
15
  return {
16
+ name: "core:orama-search",
16
17
  init() {
17
- if (this.mode === "static") (this.data["core:provider"] ??= []).push(async (props) => {
18
- props.search ??= {};
19
- props.search.SearchDialog ??= (await import("../components/orama-search-static.js")).default;
18
+ (this.data["core:provider"] ??= []).push(async (props) => {
19
+ props.search ??= { enabled: true };
20
+ if (this.mode === "static") props.search.SearchDialog ??= (await import("../components/orama-search-static.js")).default;
20
21
  return props;
21
22
  });
22
23
  },
@@ -14,6 +14,7 @@ function takumiPlugin(options = {}) {
14
14
  const width = 1200;
15
15
  const height = 630;
16
16
  return {
17
+ name: "core:takumi",
17
18
  init() {
18
19
  (this.data["core:page-meta"] ??= []).push((page) => {
19
20
  const pathname = slugsToImagePath(page.slugs, page.locale).url;
package/dist/router.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { AppContext } from "./lib/shared.js";
2
- import { Config, ConfigContext } from "./config.js";
2
+ import { ConfigBuilder, ConfigContext } from "./config.js";
3
3
  import { Awaitable, RouteFns } from "./lib/types.js";
4
4
  import * as waku from "waku";
5
5
 
6
6
  //#region src/router.d.ts
7
7
  type Options = Parameters<typeof waku.createPages>[1];
8
- declare function createRouter<C extends ConfigContext>(userConfig: Config<C>): {
8
+ declare function createRouter<C extends ConfigContext>(userConfig: ConfigBuilder<C>): {
9
9
  createPages: (fn?: (this: AppContext<C>, fns: RouteFns) => Awaitable<void>, options?: Options) => ReturnType<typeof waku.createPages>;
10
10
  };
11
11
  //#endregion
package/dist/router.js CHANGED
@@ -6,18 +6,14 @@ import { unstable_notFound, unstable_redirect } from "waku/router/server";
6
6
  //#region src/router.tsx
7
7
  function createRouter(userConfig) {
8
8
  async function init() {
9
- const context = parseConfig(userConfig);
9
+ const context = await parseConfig(userConfig);
10
10
  for (const plugin of context.plugins) await plugin.init?.call(context);
11
- return {
12
- context,
13
- root: context.layouts.root ?? (await import("./layouts/root.js")).createRootLayout(),
14
- page: context.layouts.page ?? (await import("./layouts/docs.js")).createDocsLayoutPage(),
15
- notFound: context.layouts.notFound ?? (await import("fumadocs-ui/layouts/home/not-found")).DefaultNotFound
16
- };
11
+ return context;
17
12
  }
18
13
  const createPages = (base, createPagesOptions) => {
19
14
  return waku.createPages(async (_fns) => {
20
- const { context, ...layouts } = await init();
15
+ const context = await init();
16
+ const layouts = context.layouts;
21
17
  const fns = {
22
18
  ..._fns,
23
19
  createApiIsomorphic(config) {
@@ -35,22 +31,24 @@ function createRouter(userConfig) {
35
31
  });
36
32
  }
37
33
  };
38
- await base?.call(context, fns);
39
- const resolved = /* @__PURE__ */ new Set();
40
- const createPagesCtx = {
41
- ...context,
42
- markResolved(page) {
43
- resolved.add(page);
34
+ async function resolvePage(slugs, lang) {
35
+ let page = (await context.getLoader()).getPage(slugs, lang);
36
+ if (!page) unstable_notFound();
37
+ for (const plugin of context.plugins) {
38
+ const resolved = await plugin.resolvePage?.call(context, page);
39
+ if (typeof resolved === "object") page = resolved;
40
+ else if (resolved === false) unstable_notFound();
44
41
  }
45
- };
46
- for (const plugin of context.plugins) await plugin.createPages?.call(createPagesCtx, fns);
47
- const source = await context.getLoader();
42
+ return page;
43
+ }
44
+ await base?.call(context, fns);
45
+ for (const plugin of context.plugins) await plugin.createPages?.call(context, fns);
48
46
  const staticPaths = [];
49
- for (const page of source.getPages()) {
50
- if (resolved.has(page)) continue;
47
+ const defaultRenderMode = context.mode === "dynamic" ? "dynamic" : "static";
48
+ if (defaultRenderMode === "static") outer: for (const page of (await context.getLoader()).getPages()) {
49
+ for (const plugin of context.plugins) if (await plugin.resolvePage?.call(context, page) === false) continue outer;
51
50
  staticPaths.push(page.locale ? [page.locale, ...page.slugs] : page.slugs);
52
51
  }
53
- const defaultRenderMode = context.mode === "dynamic" ? "dynamic" : "static";
54
52
  if (context.i18nConfig) {
55
53
  fns.createRoot({
56
54
  render: defaultRenderMode,
@@ -72,12 +70,10 @@ function createRouter(userConfig) {
72
70
  path: "/[lang]/[...slugs]",
73
71
  staticPaths,
74
72
  async component({ slugs, lang }) {
75
- const page = (await context.getLoader()).getPage(slugs, lang);
76
- if (!page || resolved.has(page)) unstable_notFound();
77
73
  return /* @__PURE__ */ jsx(layouts.page, {
78
74
  lang,
79
75
  slugs,
80
- page,
76
+ page: await resolvePage(slugs, lang),
81
77
  ctx: context
82
78
  });
83
79
  }
@@ -115,11 +111,9 @@ function createRouter(userConfig) {
115
111
  path: "/[...slugs]",
116
112
  staticPaths,
117
113
  async component({ slugs }) {
118
- const page = (await context.getLoader()).getPage(slugs);
119
- if (!page || resolved.has(page)) unstable_notFound();
120
114
  return /* @__PURE__ */ jsx(layouts.page, {
121
115
  slugs,
122
- page,
116
+ page: await resolvePage(slugs),
123
117
  ctx: context
124
118
  });
125
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumapress",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "An opinionated docs framework powered by Fumadocs",
5
5
  "keywords": [
6
6
  "Docs",
@@ -21,7 +21,6 @@
21
21
  ".": "./dist/index.js",
22
22
  "./adapters/mdx": "./dist/adapters/mdx.js",
23
23
  "./adapters/mdx/schema": "./dist/adapters/mdx/schema.js",
24
- "./adapters/openapi": "./dist/adapters/openapi.js",
25
24
  "./layouts/blog": "./dist/layouts/blog.js",
26
25
  "./layouts/blog.index": "./dist/layouts/blog.index.js",
27
26
  "./layouts/blog.tags": "./dist/layouts/blog.tags.js",
@@ -47,11 +46,11 @@
47
46
  },
48
47
  "dependencies": {
49
48
  "@orama/orama": "^3.1.18",
50
- "@takumi-rs/image-response": "^1.1.2",
49
+ "@takumi-rs/image-response": "^1.3.0",
51
50
  "class-variance-authority": "^0.7.1",
52
51
  "flexsearch": "^0.8.212",
53
- "fumadocs-core": "^16.8.11",
54
- "fumadocs-ui": "^16.8.11",
52
+ "fumadocs-core": "^16.8.12",
53
+ "fumadocs-ui": "^16.8.12",
55
54
  "lucide-react": "^1.16.0",
56
55
  "tailwind-merge": "^3.6.0",
57
56
  "vite": "^8.0.13",
@@ -61,10 +60,10 @@
61
60
  "@fastify/deepmerge": "^3.2.1",
62
61
  "@tailwindcss/oxide": "^4.3.0",
63
62
  "@types/mdx": "^2.0.13",
64
- "@types/node": "^25.8.0",
65
- "@types/react": "^19.2.14",
66
- "fumadocs-mdx": "^15.0.6",
67
- "fumadocs-openapi": "^10.8.5",
63
+ "@types/node": "^25.9.1",
64
+ "@types/react": "^19.2.15",
65
+ "fumadocs-mdx": "^15.0.7",
66
+ "fumadocs-openapi": "^10.9.0",
68
67
  "react": "^19.2.6",
69
68
  "react-dom": "^19.2.6",
70
69
  "tsdown": "0.22.0",
@@ -1,15 +0,0 @@
1
- import { ConfigContext } from "../config.js";
2
- import { Adapter } from "../lib/types.js";
3
- import { FC } from "react";
4
- import { OpenAPIPageData } from "fumadocs-openapi/server";
5
- import { ClientApiPageProps } from "fumadocs-openapi/ui/create-client";
6
-
7
- //#region src/adapters/openapi.d.ts
8
- interface OpenAPIAdapterOptions {
9
- ClientAPIPage: FC<ClientApiPageProps>;
10
- }
11
- declare function fumadocsOpenAPI<C extends ConfigContext>(options: OpenAPIAdapterOptions): Adapter<C>;
12
- /** @internal */
13
- declare function isOpenAPI(data: object): data is OpenAPIPageData;
14
- //#endregion
15
- export { OpenAPIAdapterOptions, fumadocsOpenAPI, isOpenAPI };
@@ -1,22 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- //#region src/adapters/openapi.tsx
3
- function fumadocsOpenAPI(options) {
4
- const { ClientAPIPage } = options;
5
- return {
6
- async "core:render-body"(page) {
7
- if (isOpenAPI(page.data)) return /* @__PURE__ */ jsx(ClientAPIPage, { ...await page.data.getClientAPIPageProps() });
8
- },
9
- "core:render-toc"(page) {
10
- if (isOpenAPI(page.data)) return page.data.toc;
11
- },
12
- "core:get-structured-data"(page) {
13
- if (isOpenAPI(page.data)) return page.data.structuredData;
14
- }
15
- };
16
- }
17
- /** @internal */
18
- function isOpenAPI(data) {
19
- return "getAPIPageProps" in data && typeof data.getAPIPageProps === "function";
20
- }
21
- //#endregion
22
- export { fumadocsOpenAPI, isOpenAPI };