fumapress 0.2.4 → 0.2.5

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
@@ -6,20 +6,24 @@
6
6
  @source inline("await");
7
7
  @source inline("body");
8
8
  @source inline("border-b");
9
+ @source inline("children");
9
10
  @source inline("className");
10
11
  @source inline("client");
11
12
  @source inline("const");
12
13
  @source inline("core:docs-layout");
13
14
  @source inline("core:home-layout");
15
+ @source inline("core:notebook-layout");
14
16
  @source inline("core:provider");
15
17
  @source inline("core:render-body");
16
18
  @source inline("core:render-toc");
17
19
  @source inline("create");
18
20
  @source inline("createDocsLayout");
19
21
  @source inline("createHomeLayout");
22
+ @source inline("createNotebookLayout");
20
23
  @source inline("createRootLayout");
21
24
  @source inline("data");
22
25
  @source inline("data-version");
26
+ @source inline("date");
23
27
  @source inline("default");
24
28
  @source inline("else");
25
29
  @source inline("empty");
@@ -52,6 +56,7 @@
52
56
  @source inline("lang");
53
57
  @source inline("language");
54
58
  @source inline("languages");
59
+ @source inline("lastModified");
55
60
  @source inline("layoutData");
56
61
  @source inline("layoutProps");
57
62
  @source inline("let");
@@ -69,6 +74,7 @@
69
74
  @source inline("page");
70
75
  @source inline("pageProps");
71
76
  @source inline("pb-6");
77
+ @source inline("props");
72
78
  @source inline("providerProps");
73
79
  @source inline("pt-2");
74
80
  @source inline("query");
@@ -76,7 +82,6 @@
76
82
  @source inline("react");
77
83
  @source inline("render");
78
84
  @source inline("renderCtx");
79
- @source inline("renderPageMeta");
80
85
  @source inline("renderRootMeta");
81
86
  @source inline("result");
82
87
  @source inline("return");
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { AppContext, AppContextData } from "./lib/shared.js";
2
2
  import { BuildMode, Config, ConfigBuilder, ConfigContext, I18nConfig, I18nConfigBuilder, Layouts, SiteConfig, defineConfig, defineI18nConfig } from "./config.js";
3
- import { Adapter, ServerPlugin } from "./lib/types.js";
4
- export { type Adapter, type AppContext, type AppContextData, BuildMode, Config, ConfigBuilder, ConfigContext, I18nConfig, I18nConfigBuilder, Layouts, type ServerPlugin, SiteConfig, defineConfig, defineI18nConfig };
3
+ import { Adapter, RouteFns, ServerPlugin } from "./lib/types.js";
4
+ export { type Adapter, type AppContext, type AppContextData, BuildMode, Config, ConfigBuilder, ConfigContext, I18nConfig, I18nConfigBuilder, Layouts, type RouteFns, type ServerPlugin, SiteConfig, defineConfig, defineI18nConfig };
@@ -1,4 +1,4 @@
1
- import { AppContext } from "../lib/shared.js";
1
+ import { AppContext, TransformChildren } from "../lib/shared.js";
2
2
  import { ConfigContext, Layouts } from "../config.js";
3
3
  import { Awaitable } from "../lib/types.js";
4
4
  import { ReactNode } from "react";
@@ -12,16 +12,18 @@ interface DocsLayoutOptions<C extends ConfigContext = ConfigContext> {
12
12
  lang?: string;
13
13
  }, page: C["loaderConfig"]["page"]) => Awaitable<{
14
14
  markdownUrl?: string;
15
+ lastModified?: Date | null;
15
16
  body?: ReactNode;
16
- layoutProps?: Partial<DocsLayoutProps>;
17
- pageProps?: DocsPageProps;
17
+ layoutProps?: TransformChildren<Partial<DocsLayoutProps>>;
18
+ pageProps?: TransformChildren<DocsPageProps>;
18
19
  }>;
19
20
  }
20
21
  interface DocsLayoutRenderData {
21
22
  markdownUrl?: string;
23
+ lastModified?: Date | null;
22
24
  body: ReactNode;
23
- layoutProps: DocsLayoutProps;
24
- pageProps: DocsPageProps;
25
+ layoutProps: TransformChildren<DocsLayoutProps>;
26
+ pageProps: TransformChildren<DocsPageProps>;
25
27
  }
26
28
  interface DocsLayoutContextData {
27
29
  renderers?: ((this: {
@@ -1,8 +1,8 @@
1
- import { baseOptions, getGitHubFileUrl, renderPageMeta } from "../lib/shared.js";
1
+ import { TransformChildrenSlot, baseOptions, getGitHubFileUrl, renderPageMeta } from "../lib/shared.js";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import { unstable_notFound } from "waku/router/server";
4
4
  import { DocsLayout } from "fumadocs-ui/layouts/docs";
5
- import { DocsBody, DocsDescription, DocsPage, DocsTitle, MarkdownCopyButton, ViewOptionsPopover } from "fumadocs-ui/layouts/docs/page";
5
+ import { DocsBody, DocsDescription, DocsPage, DocsTitle, MarkdownCopyButton, PageLastUpdate, ViewOptionsPopover } from "fumadocs-ui/layouts/docs/page";
6
6
  //#region src/layouts/docs.tsx
7
7
  function createDocsLayout({ render } = {}) {
8
8
  async function defaultRender(page) {
@@ -53,31 +53,29 @@ function createDocsLayout({ render } = {}) {
53
53
  const renderCtx = { page };
54
54
  for (const r of layoutData.renderers) result = await r.call(renderCtx, result);
55
55
  }
56
- return /* @__PURE__ */ jsxs(DocsLayout, {
57
- ...result.layoutProps,
58
- children: [
59
- renderPageMeta(page, props),
60
- result.layoutProps.children,
61
- /* @__PURE__ */ jsxs(DocsPage, {
62
- ...result.pageProps,
63
- children: [
64
- result.pageProps.children,
65
- /* @__PURE__ */ jsx(DocsTitle, { children: page.data.title }),
66
- /* @__PURE__ */ jsx(DocsDescription, {
67
- className: "mb-0",
68
- children: page.data.description
69
- }),
70
- /* @__PURE__ */ jsxs("div", {
71
- className: "flex flex-row gap-2 items-center border-b pt-2 pb-6",
72
- children: [result.markdownUrl && /* @__PURE__ */ jsx(MarkdownCopyButton, { markdownUrl: result.markdownUrl }), /* @__PURE__ */ jsx(ViewOptionsPopover, {
73
- markdownUrl: result.markdownUrl,
74
- githubUrl: page.absolutePath ? getGitHubFileUrl(props, page.absolutePath) : void 0
75
- })]
76
- }),
77
- /* @__PURE__ */ jsx(DocsBody, { children: result.body })
78
- ]
79
- })
80
- ]
56
+ return /* @__PURE__ */ jsxs(TransformChildrenSlot, {
57
+ Comp: DocsLayout,
58
+ props: result.layoutProps,
59
+ children: [renderPageMeta(page, props), /* @__PURE__ */ jsxs(TransformChildrenSlot, {
60
+ Comp: DocsPage,
61
+ props: result.pageProps,
62
+ children: [
63
+ /* @__PURE__ */ jsx(DocsTitle, { children: page.data.title }),
64
+ /* @__PURE__ */ jsx(DocsDescription, {
65
+ className: "mb-0",
66
+ children: page.data.description
67
+ }),
68
+ /* @__PURE__ */ jsxs("div", {
69
+ className: "flex flex-row gap-2 items-center border-b pt-2 pb-6",
70
+ children: [result.markdownUrl && /* @__PURE__ */ jsx(MarkdownCopyButton, { markdownUrl: result.markdownUrl }), /* @__PURE__ */ jsx(ViewOptionsPopover, {
71
+ markdownUrl: result.markdownUrl,
72
+ githubUrl: page.absolutePath ? getGitHubFileUrl(props, page.absolutePath) : void 0
73
+ })]
74
+ }),
75
+ /* @__PURE__ */ jsx(DocsBody, { children: result.body }),
76
+ result.lastModified && /* @__PURE__ */ jsx(PageLastUpdate, { date: result.lastModified })
77
+ ]
78
+ })]
81
79
  });
82
80
  };
83
81
  }
@@ -1,4 +1,4 @@
1
- import { AppContext } from "../lib/shared.js";
1
+ import { AppContext, TransformChildren } from "../lib/shared.js";
2
2
  import { ConfigContext, Layouts } from "../config.js";
3
3
  import { Awaitable } from "../lib/types.js";
4
4
  import { ReactNode } from "react";
@@ -9,12 +9,12 @@ import { Page } from "fumadocs-core/source";
9
9
  interface HomeLayoutOptions<C extends ConfigContext = ConfigContext> {
10
10
  render?: (this: AppContext<C>, page: C["loaderConfig"]["page"]) => Awaitable<{
11
11
  body?: ReactNode;
12
- layoutProps?: Partial<HomeLayoutProps>;
12
+ layoutProps?: TransformChildren<Partial<HomeLayoutProps>>;
13
13
  }>;
14
14
  }
15
15
  interface HomeLayoutRenderData {
16
16
  body: ReactNode;
17
- layoutProps: HomeLayoutProps;
17
+ layoutProps: TransformChildren<HomeLayoutProps>;
18
18
  }
19
19
  interface HomeLayoutContextData {
20
20
  renderers?: ((this: {
@@ -1,4 +1,4 @@
1
- import { baseOptions, renderPageMeta } from "../lib/shared.js";
1
+ import { TransformChildrenSlot, baseOptions, renderPageMeta } from "../lib/shared.js";
2
2
  import { jsxs } from "react/jsx-runtime";
3
3
  import { unstable_notFound } from "waku/router/server";
4
4
  import { HomeLayout } from "fumadocs-ui/layouts/home";
@@ -24,8 +24,9 @@ function createHomeLayout({ render }) {
24
24
  const renderCtx = { page };
25
25
  for (const r of layoutData.renderers) result = await r.call(renderCtx, result);
26
26
  }
27
- return /* @__PURE__ */ jsxs(HomeLayout, {
28
- ...result.layoutProps,
27
+ return /* @__PURE__ */ jsxs(TransformChildrenSlot, {
28
+ Comp: HomeLayout,
29
+ props: result.layoutProps,
29
30
  children: [renderPageMeta(page, props), result.body]
30
31
  });
31
32
  };
@@ -0,0 +1,37 @@
1
+ import { AppContext, TransformChildren } from "../lib/shared.js";
2
+ import { ConfigContext, Layouts } from "../config.js";
3
+ import { Awaitable } from "../lib/types.js";
4
+ import { ReactNode } from "react";
5
+ import { DocsLayoutProps } from "fumadocs-ui/layouts/notebook";
6
+ import { DocsPageProps } from "fumadocs-ui/layouts/notebook/page";
7
+ import { Page } from "fumadocs-core/source";
8
+
9
+ //#region src/layouts/notebook.d.ts
10
+ interface NotebookLayoutOptions<C extends ConfigContext = ConfigContext> {
11
+ render?: (this: AppContext<C> & {
12
+ lang?: string;
13
+ }, page: C["loaderConfig"]["page"]) => Awaitable<{
14
+ markdownUrl?: string;
15
+ lastModified?: Date | null;
16
+ body?: ReactNode;
17
+ layoutProps?: TransformChildren<Partial<DocsLayoutProps>>;
18
+ pageProps?: TransformChildren<DocsPageProps>;
19
+ }>;
20
+ }
21
+ interface NotebookLayoutRenderData {
22
+ markdownUrl?: string;
23
+ lastModified?: Date | null;
24
+ body: ReactNode;
25
+ layoutProps: TransformChildren<DocsLayoutProps>;
26
+ pageProps: TransformChildren<DocsPageProps>;
27
+ }
28
+ interface NotebookLayoutContextData {
29
+ renderers?: ((this: {
30
+ page: Page;
31
+ }, data: NotebookLayoutRenderData) => Awaitable<NotebookLayoutRenderData>)[];
32
+ }
33
+ declare function createNotebookLayout<C extends ConfigContext = ConfigContext>({
34
+ render
35
+ }?: NotebookLayoutOptions<NoInfer<C>>): Layouts<C>["page"];
36
+ //#endregion
37
+ export { NotebookLayoutContextData, NotebookLayoutOptions, NotebookLayoutRenderData, createNotebookLayout };
@@ -0,0 +1,83 @@
1
+ import { TransformChildrenSlot, baseOptions, getGitHubFileUrl, renderPageMeta } from "../lib/shared.js";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { unstable_notFound } from "waku/router/server";
4
+ import { DocsLayout } from "fumadocs-ui/layouts/notebook";
5
+ import { DocsBody, DocsDescription, DocsPage, DocsTitle, MarkdownCopyButton, PageLastUpdate, ViewOptionsPopover } from "fumadocs-ui/layouts/notebook/page";
6
+ //#region src/layouts/notebook.tsx
7
+ function createNotebookLayout({ render } = {}) {
8
+ async function defaultRender(page) {
9
+ let body;
10
+ let toc;
11
+ for (const adapter of this.adapters) {
12
+ body = await adapter["core:render-body"]?.call(this, page);
13
+ if (body !== void 0) break;
14
+ }
15
+ for (const adapter of this.adapters) {
16
+ toc = await adapter["core:render-toc"]?.call(this, page);
17
+ if (toc !== void 0) break;
18
+ }
19
+ if (body === void 0) throw new Error("[Fumapress] Please specify the `render` option in createNotebookLayout()");
20
+ return {
21
+ body,
22
+ pageProps: { toc }
23
+ };
24
+ }
25
+ return async function Layout(props) {
26
+ const { slugs, lang, getLoader, data: { "core:notebook-layout": layoutData } } = props;
27
+ const source = await getLoader();
28
+ const page = source.getPage(slugs, lang);
29
+ if (!page) unstable_notFound();
30
+ const _raw = await (render ?? defaultRender).call(props, page);
31
+ let result;
32
+ if (_raw.body === void 0 || _raw.pageProps === void 0) {
33
+ const _default = await defaultRender.call(props, page);
34
+ result = {
35
+ markdownUrl: _raw.markdownUrl,
36
+ pageProps: _raw.pageProps ?? _default.pageProps,
37
+ body: _raw.body ?? _default.body,
38
+ layoutProps: {
39
+ tree: source.getPageTree(lang),
40
+ ..._raw.layoutProps ?? baseOptions(props)
41
+ }
42
+ };
43
+ } else result = {
44
+ body: _raw.body,
45
+ pageProps: _raw.pageProps,
46
+ markdownUrl: _raw.markdownUrl,
47
+ layoutProps: {
48
+ tree: source.getPageTree(lang),
49
+ ..._raw.layoutProps ?? baseOptions(props)
50
+ }
51
+ };
52
+ if (layoutData?.renderers) {
53
+ const renderCtx = { page };
54
+ for (const r of layoutData.renderers) result = await r.call(renderCtx, result);
55
+ }
56
+ return /* @__PURE__ */ jsxs(TransformChildrenSlot, {
57
+ Comp: DocsLayout,
58
+ props: result.layoutProps,
59
+ children: [renderPageMeta(page, props), /* @__PURE__ */ jsxs(TransformChildrenSlot, {
60
+ Comp: DocsPage,
61
+ props: result.pageProps,
62
+ children: [
63
+ /* @__PURE__ */ jsx(DocsTitle, { children: page.data.title }),
64
+ /* @__PURE__ */ jsx(DocsDescription, {
65
+ className: "mb-0",
66
+ children: page.data.description
67
+ }),
68
+ /* @__PURE__ */ jsxs("div", {
69
+ className: "flex flex-row gap-2 items-center border-b pt-2 pb-6",
70
+ children: [result.markdownUrl && /* @__PURE__ */ jsx(MarkdownCopyButton, { markdownUrl: result.markdownUrl }), /* @__PURE__ */ jsx(ViewOptionsPopover, {
71
+ markdownUrl: result.markdownUrl,
72
+ githubUrl: page.absolutePath ? getGitHubFileUrl(props, page.absolutePath) : void 0
73
+ })]
74
+ }),
75
+ /* @__PURE__ */ jsx(DocsBody, { children: result.body }),
76
+ result.lastModified && /* @__PURE__ */ jsx(PageLastUpdate, { date: result.lastModified })
77
+ ]
78
+ })]
79
+ });
80
+ };
81
+ }
82
+ //#endregion
83
+ export { createNotebookLayout };
@@ -3,7 +3,7 @@ import { RootProviderProps } from "fumadocs-ui/provider/waku";
3
3
 
4
4
  //#region src/layouts/root.d.ts
5
5
  interface RootLayoutOptions {
6
- providerProps?: RootProviderProps;
6
+ providerProps?: Omit<RootProviderProps, "children">;
7
7
  }
8
8
  declare function createRootLayout<C extends ConfigContext = ConfigContext>(options?: RootLayoutOptions): Layouts<C>["root"];
9
9
  //#endregion
@@ -1,8 +1,9 @@
1
1
  import { DocsLayoutContextData } from "../layouts/docs.js";
2
2
  import { HomeLayoutContextData } from "../layouts/home.js";
3
+ import { NotebookLayoutContextData } from "../layouts/notebook.js";
3
4
  import { BuildMode, Config, ConfigContext, I18nConfig } from "../config.js";
4
5
  import { Adapter, Awaitable, ServerPlugin } from "./types.js";
5
- import { ReactNode } from "react";
6
+ import { ComponentType, ReactNode } from "react";
6
7
  import { RootProviderProps } from "fumadocs-ui/provider/waku";
7
8
  import { LoaderOutput, Page } from "fumadocs-core/source";
8
9
 
@@ -33,9 +34,13 @@ interface AppContext<C extends ConfigContext = ConfigContext> {
33
34
  }
34
35
  interface AppContextData {
35
36
  "core:page-meta"?: ((page: Page) => ReactNode)[];
37
+ "core:notebook-layout"?: NotebookLayoutContextData;
36
38
  "core:docs-layout"?: DocsLayoutContextData;
37
39
  "core:home-layout"?: HomeLayoutContextData;
38
40
  "core:provider"?: ((props: RootProviderProps) => Awaitable<RootProviderProps>)[];
39
41
  }
42
+ type TransformChildren<T> = Omit<T, "children"> & {
43
+ children?: ((nodes: ReactNode) => ReactNode)[];
44
+ };
40
45
  //#endregion
41
- export { AppContext, AppContextData };
46
+ export { AppContext, AppContextData, TransformChildren };
@@ -59,5 +59,12 @@ function baseOptions(ctx) {
59
59
  githubUrl: git ? `https://github.com/${git.user}/${git.repo}` : void 0
60
60
  };
61
61
  }
62
+ function TransformChildrenSlot({ Comp, props, children }) {
63
+ if (props.children) for (const transformer of props.children) children = transformer(children);
64
+ return /* @__PURE__ */ jsx(Comp, {
65
+ ...props,
66
+ children
67
+ });
68
+ }
62
69
  //#endregion
63
- export { baseOptions, getGitHubFileUrl, parseConfig, renderPageMeta, renderRootMeta };
70
+ export { TransformChildrenSlot, baseOptions, getGitHubFileUrl, parseConfig, renderPageMeta, renderRootMeta };
@@ -30,4 +30,4 @@ type RouteFns = Parameters<Parameters<typeof createPages>[0]>[0] & {
30
30
  }) => void;
31
31
  };
32
32
  //#endregion
33
- export { Adapter, Awaitable, ServerPlugin };
33
+ export { Adapter, Awaitable, RouteFns, ServerPlugin };
package/dist/vite.js CHANGED
@@ -12,6 +12,11 @@ function pressCore() {
12
12
  isBuild: command === "build",
13
13
  isFrameworkPkgByName(pkgName) {
14
14
  if (pkgName.startsWith("@fumapress/") || pkgName.startsWith("@fumadocs/") || pkgName.startsWith("fumadocs-") || pkgName.startsWith("fumapress-") || pkgName === "fumapress") return true;
15
+ switch (pkgName) {
16
+ case "vite":
17
+ case "waku":
18
+ case "shiki": return false;
19
+ }
15
20
  }
16
21
  });
17
22
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumapress",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "An opinionated docs framework powered by Fumadocs",
5
5
  "keywords": [
6
6
  "Docs",
@@ -22,6 +22,7 @@
22
22
  "./adapters/mdx": "./dist/adapters/mdx.js",
23
23
  "./layouts/docs": "./dist/layouts/docs.js",
24
24
  "./layouts/home": "./dist/layouts/home.js",
25
+ "./layouts/notebook": "./dist/layouts/notebook.js",
25
26
  "./layouts/root": "./dist/layouts/root.js",
26
27
  "./plugins/flexsearch": "./dist/plugins/flexsearch.js",
27
28
  "./plugins/llms.txt": "./dist/plugins/llms.txt.js",