@depup/nextra 4.6.1-depup.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/LICENSE +21 -0
- package/README.md +56 -0
- package/changes.json +110 -0
- package/dist/client/components/banner/close-banner-button.d.ts +8 -0
- package/dist/client/components/banner/close-banner-button.js +45 -0
- package/dist/client/components/banner/index.client.d.ts +5 -0
- package/dist/client/components/banner/index.client.js +46 -0
- package/dist/client/components/banner/index.d.ts +51 -0
- package/dist/client/components/banner/index.js +93 -0
- package/dist/client/components/bleed.d.ts +63 -0
- package/dist/client/components/bleed.js +54 -0
- package/dist/client/components/button.d.ts +9 -0
- package/dist/client/components/button.js +55 -0
- package/dist/client/components/callout.d.ts +136 -0
- package/dist/client/components/callout.js +99 -0
- package/dist/client/components/cards.d.ts +104 -0
- package/dist/client/components/cards.js +132 -0
- package/dist/client/components/collapse.d.ts +12 -0
- package/dist/client/components/collapse.js +143 -0
- package/dist/client/components/file-tree/file.d.ts +9 -0
- package/dist/client/components/file-tree/file.js +43 -0
- package/dist/client/components/file-tree/folder.d.ts +12 -0
- package/dist/client/components/file-tree/folder.js +94 -0
- package/dist/client/components/file-tree/index.d.ts +57 -0
- package/dist/client/components/file-tree/index.js +12 -0
- package/dist/client/components/file-tree/tree.d.ts +5 -0
- package/dist/client/components/file-tree/tree.js +41 -0
- package/dist/client/components/head.d.ts +139 -0
- package/dist/client/components/head.js +202 -0
- package/dist/client/components/image-zoom.d.ts +6 -0
- package/dist/client/components/image-zoom.js +79 -0
- package/dist/client/components/index.d.ts +56 -0
- package/dist/client/components/index.js +42 -0
- package/dist/client/components/playground.d.ts +90 -0
- package/dist/client/components/playground.js +103 -0
- package/dist/client/components/popup/index.client.d.ts +7 -0
- package/dist/client/components/popup/index.client.js +83 -0
- package/dist/client/components/popup/index.d.ts +12 -0
- package/dist/client/components/popup/index.js +11 -0
- package/dist/client/components/search.d.ts +88 -0
- package/dist/client/components/search.js +426 -0
- package/dist/client/components/select.d.ts +19 -0
- package/dist/client/components/select.js +109 -0
- package/dist/client/components/skip-nav/index.client.d.ts +5 -0
- package/dist/client/components/skip-nav/index.client.js +45 -0
- package/dist/client/components/skip-nav/index.d.ts +6 -0
- package/dist/client/components/skip-nav/index.js +24 -0
- package/dist/client/components/steps.d.ts +64 -0
- package/dist/client/components/steps.js +74 -0
- package/dist/client/components/tabs/index.client.d.ts +21 -0
- package/dist/client/components/tabs/index.client.js +243 -0
- package/dist/client/components/tabs/index.d.ts +53 -0
- package/dist/client/components/tabs/index.js +9 -0
- package/dist/client/evaluate.d.ts +30 -0
- package/dist/client/evaluate.js +17 -0
- package/dist/client/hocs/index.d.ts +4 -0
- package/dist/client/hocs/index.js +6 -0
- package/dist/client/hocs/with-github-alert.d.ts +11 -0
- package/dist/client/hocs/with-github-alert.js +30 -0
- package/dist/client/hocs/with-icons.d.ts +6 -0
- package/dist/client/hocs/with-icons.js +76 -0
- package/dist/client/hooks/index.d.ts +4 -0
- package/dist/client/hooks/index.js +10 -0
- package/dist/client/hooks/use-copy.d.ts +9 -0
- package/dist/client/hooks/use-copy.js +77 -0
- package/dist/client/hooks/use-fs-route.d.ts +3 -0
- package/dist/client/hooks/use-fs-route.js +20 -0
- package/dist/client/hooks/use-hash.d.ts +3 -0
- package/dist/client/hooks/use-hash.js +20 -0
- package/dist/client/hooks/use-mounted.d.ts +3 -0
- package/dist/client/hooks/use-mounted.js +13 -0
- package/dist/client/icons/arrow-right.d.ts +5 -0
- package/dist/client/icons/arrow-right.js +24 -0
- package/dist/client/icons/chatgpt.d.ts +2 -0
- package/dist/client/icons/chatgpt.js +24 -0
- package/dist/client/icons/check.d.ts +2 -0
- package/dist/client/icons/check.js +24 -0
- package/dist/client/icons/claude.d.ts +2 -0
- package/dist/client/icons/claude.js +81 -0
- package/dist/client/icons/copy.d.ts +2 -0
- package/dist/client/icons/copy.js +31 -0
- package/dist/client/icons/cpp.d.ts +2 -0
- package/dist/client/icons/cpp.js +24 -0
- package/dist/client/icons/cross-circled.d.ts +2 -0
- package/dist/client/icons/cross-circled.js +24 -0
- package/dist/client/icons/csharp.d.ts +2 -0
- package/dist/client/icons/csharp.js +24 -0
- package/dist/client/icons/css.d.ts +2 -0
- package/dist/client/icons/css.js +24 -0
- package/dist/client/icons/discord.d.ts +2 -0
- package/dist/client/icons/discord.js +24 -0
- package/dist/client/icons/expand.d.ts +2 -0
- package/dist/client/icons/expand.js +31 -0
- package/dist/client/icons/file.d.ts +2 -0
- package/dist/client/icons/file.js +24 -0
- package/dist/client/icons/folder-open.d.ts +2 -0
- package/dist/client/icons/folder-open.js +24 -0
- package/dist/client/icons/folder.d.ts +2 -0
- package/dist/client/icons/folder.js +24 -0
- package/dist/client/icons/github-caution.d.ts +2 -0
- package/dist/client/icons/github-caution.js +24 -0
- package/dist/client/icons/github-important.d.ts +2 -0
- package/dist/client/icons/github-important.js +24 -0
- package/dist/client/icons/github-note.d.ts +2 -0
- package/dist/client/icons/github-note.js +24 -0
- package/dist/client/icons/github-tip.d.ts +2 -0
- package/dist/client/icons/github-tip.js +24 -0
- package/dist/client/icons/github-warning.d.ts +2 -0
- package/dist/client/icons/github-warning.js +24 -0
- package/dist/client/icons/github.d.ts +2 -0
- package/dist/client/icons/github.js +24 -0
- package/dist/client/icons/globe.d.ts +2 -0
- package/dist/client/icons/globe.js +24 -0
- package/dist/client/icons/go.d.ts +2 -0
- package/dist/client/icons/go.js +46 -0
- package/dist/client/icons/graphql.d.ts +2 -0
- package/dist/client/icons/graphql.js +56 -0
- package/dist/client/icons/index.d.ts +2 -0
- package/dist/client/icons/index.js +92 -0
- package/dist/client/icons/javascript.d.ts +2 -0
- package/dist/client/icons/javascript.js +24 -0
- package/dist/client/icons/json.d.ts +2 -0
- package/dist/client/icons/json.js +41 -0
- package/dist/client/icons/link-arrow.d.ts +2 -0
- package/dist/client/icons/link-arrow.js +31 -0
- package/dist/client/icons/link.d.ts +2 -0
- package/dist/client/icons/link.js +24 -0
- package/dist/client/icons/markdown.d.ts +2 -0
- package/dist/client/icons/markdown.js +24 -0
- package/dist/client/icons/mdx.d.ts +2 -0
- package/dist/client/icons/mdx.js +24 -0
- package/dist/client/icons/menu.d.ts +2 -0
- package/dist/client/icons/menu.js +36 -0
- package/dist/client/icons/moon.d.ts +2 -0
- package/dist/client/icons/moon.js +24 -0
- package/dist/client/icons/move.d.ts +2 -0
- package/dist/client/icons/move.js +24 -0
- package/dist/client/icons/python.d.ts +2 -0
- package/dist/client/icons/python.js +31 -0
- package/dist/client/icons/react.d.ts +2 -0
- package/dist/client/icons/react.js +38 -0
- package/dist/client/icons/rust.d.ts +2 -0
- package/dist/client/icons/rust.js +31 -0
- package/dist/client/icons/spinner.d.ts +2 -0
- package/dist/client/icons/spinner.js +31 -0
- package/dist/client/icons/sun.d.ts +2 -0
- package/dist/client/icons/sun.js +24 -0
- package/dist/client/icons/svelte.d.ts +2 -0
- package/dist/client/icons/svelte.js +31 -0
- package/dist/client/icons/terminal.d.ts +2 -0
- package/dist/client/icons/terminal.js +24 -0
- package/dist/client/icons/terraform.d.ts +2 -0
- package/dist/client/icons/terraform.js +24 -0
- package/dist/client/icons/typescript.d.ts +2 -0
- package/dist/client/icons/typescript.js +24 -0
- package/dist/client/icons/word-wrap.d.ts +2 -0
- package/dist/client/icons/word-wrap.js +24 -0
- package/dist/client/icons/x.d.ts +2 -0
- package/dist/client/icons/x.js +24 -0
- package/dist/client/mdx-components/anchor.d.ts +10 -0
- package/dist/client/mdx-components/anchor.js +109 -0
- package/dist/client/mdx-components/code.d.ts +7 -0
- package/dist/client/mdx-components/code.js +52 -0
- package/dist/client/mdx-components/details.d.ts +5 -0
- package/dist/client/mdx-components/details.js +166 -0
- package/dist/client/mdx-components/image.d.ts +28 -0
- package/dist/client/mdx-components/image.js +39 -0
- package/dist/client/mdx-components/index.d.ts +11 -0
- package/dist/client/mdx-components/index.js +16 -0
- package/dist/client/mdx-components/pre/copy-to-clipboard.d.ts +5 -0
- package/dist/client/mdx-components/pre/copy-to-clipboard.js +49 -0
- package/dist/client/mdx-components/pre/index.d.ts +16 -0
- package/dist/client/mdx-components/pre/index.js +156 -0
- package/dist/client/mdx-components/pre/toggle-word-wrap-button.d.ts +7 -0
- package/dist/client/mdx-components/pre/toggle-word-wrap-button.js +31 -0
- package/dist/client/mdx-components/summary.d.ts +5 -0
- package/dist/client/mdx-components/summary.js +80 -0
- package/dist/client/mdx-components/table.d.ts +57 -0
- package/dist/client/mdx-components/table.js +95 -0
- package/dist/client/mdx-components.d.ts +89 -0
- package/dist/client/mdx-components.js +15 -0
- package/dist/client/mdx-remote.d.ts +62 -0
- package/dist/client/mdx-remote.js +36 -0
- package/dist/client/normalize-pages.d.ts +84 -0
- package/dist/client/normalize-pages.js +232 -0
- package/dist/client/package.json +1 -0
- package/dist/client/pages.d.ts +131 -0
- package/dist/client/pages.js +39 -0
- package/dist/client/remove-links.d.ts +6 -0
- package/dist/client/remove-links.js +35 -0
- package/dist/client/setup-page.d.ts +18 -0
- package/dist/client/setup-page.js +14 -0
- package/dist/server/compile-metadata.d.ts +12 -0
- package/dist/server/compile-metadata.js +39 -0
- package/dist/server/compile.d.ts +39 -0
- package/dist/server/compile.js +158 -0
- package/dist/server/constants.d.ts +15 -0
- package/dist/server/constants.js +22 -0
- package/dist/server/fetch-filepaths-from-github.d.ts +10 -0
- package/dist/server/fetch-filepaths-from-github.js +36 -0
- package/dist/server/index.d.ts +39 -0
- package/dist/server/index.js +203 -0
- package/dist/server/loader.d.ts +18 -0
- package/dist/server/loader.js +155 -0
- package/dist/server/locales.d.ts +22 -0
- package/dist/server/locales.js +38 -0
- package/dist/server/page-map/find-meta-and-page-file-paths.d.ts +8 -0
- package/dist/server/page-map/find-meta-and-page-file-paths.js +32 -0
- package/dist/server/page-map/get.d.ts +50 -0
- package/dist/server/page-map/get.js +28 -0
- package/dist/server/page-map/index-page.d.ts +21 -0
- package/dist/server/page-map/index-page.js +57 -0
- package/dist/server/page-map/index.d.ts +26 -0
- package/dist/server/page-map/index.js +24 -0
- package/dist/server/page-map/merge-meta-with-page-map.d.ts +17 -0
- package/dist/server/page-map/merge-meta-with-page-map.js +74 -0
- package/dist/server/page-map/normalize.d.ts +17 -0
- package/dist/server/page-map/normalize.js +122 -0
- package/dist/server/page-map/placeholder.d.ts +2 -0
- package/dist/server/page-map/placeholder.js +0 -0
- package/dist/server/page-map/to-ast.d.ts +18 -0
- package/dist/server/page-map/to-ast.js +47 -0
- package/dist/server/page-map/to-js.d.ts +21 -0
- package/dist/server/page-map/to-js.js +72 -0
- package/dist/server/page-map/to-page-map.d.ts +26 -0
- package/dist/server/page-map/to-page-map.js +101 -0
- package/dist/server/recma-plugins/index.d.ts +3 -0
- package/dist/server/recma-plugins/index.js +4 -0
- package/dist/server/recma-plugins/recma-rewrite.d.ts +11 -0
- package/dist/server/recma-plugins/recma-rewrite.js +98 -0
- package/dist/server/rehype-plugins/index.d.ts +18 -0
- package/dist/server/rehype-plugins/index.js +16 -0
- package/dist/server/rehype-plugins/rehype-better-react-mathjax.d.ts +24 -0
- package/dist/server/rehype-plugins/rehype-better-react-mathjax.js +96 -0
- package/dist/server/rehype-plugins/rehype-extract-toc-content.d.ts +6 -0
- package/dist/server/rehype-plugins/rehype-extract-toc-content.js +119 -0
- package/dist/server/rehype-plugins/rehype-twoslash-popup.d.ts +6 -0
- package/dist/server/rehype-plugins/rehype-twoslash-popup.js +50 -0
- package/dist/server/rehype-plugins/rehype.d.ts +21 -0
- package/dist/server/rehype-plugins/rehype.js +84 -0
- package/dist/server/remark-plugins/index.d.ts +15 -0
- package/dist/server/remark-plugins/index.js +26 -0
- package/dist/server/remark-plugins/remark-assign-frontmatter.d.ts +10 -0
- package/dist/server/remark-plugins/remark-assign-frontmatter.js +24 -0
- package/dist/server/remark-plugins/remark-custom-heading-id.d.ts +9 -0
- package/dist/server/remark-plugins/remark-custom-heading-id.js +18 -0
- package/dist/server/remark-plugins/remark-export-only-metadata.d.ts +6 -0
- package/dist/server/remark-plugins/remark-export-only-metadata.js +18 -0
- package/dist/server/remark-plugins/remark-export-source-code.d.ts +6 -0
- package/dist/server/remark-plugins/remark-export-source-code.js +35 -0
- package/dist/server/remark-plugins/remark-headings.d.ts +12 -0
- package/dist/server/remark-plugins/remark-headings.js +133 -0
- package/dist/server/remark-plugins/remark-link-rewrite.d.ts +11 -0
- package/dist/server/remark-plugins/remark-link-rewrite.js +12 -0
- package/dist/server/remark-plugins/remark-mdx-disable-explicit-jsx.d.ts +10 -0
- package/dist/server/remark-plugins/remark-mdx-disable-explicit-jsx.js +10 -0
- package/dist/server/remark-plugins/remark-mdx-frontmatter.d.ts +6 -0
- package/dist/server/remark-plugins/remark-mdx-frontmatter.js +37 -0
- package/dist/server/remark-plugins/remark-mdx-title.d.ts +10 -0
- package/dist/server/remark-plugins/remark-mdx-title.js +53 -0
- package/dist/server/remark-plugins/remark-remove-imports.d.ts +6 -0
- package/dist/server/remark-plugins/remark-remove-imports.js +12 -0
- package/dist/server/remark-plugins/remark-static-image.d.ts +6 -0
- package/dist/server/remark-plugins/remark-static-image.js +107 -0
- package/dist/server/schemas.d.ts +352 -0
- package/dist/server/schemas.js +240 -0
- package/dist/server/tsdoc/base.d.ts +38 -0
- package/dist/server/tsdoc/base.js +284 -0
- package/dist/server/tsdoc/index.d.ts +6 -0
- package/dist/server/tsdoc/index.js +10 -0
- package/dist/server/tsdoc/tsdoc.d.ts +102 -0
- package/dist/server/tsdoc/tsdoc.js +262 -0
- package/dist/server/tsdoc/types.d.ts +64 -0
- package/dist/server/tsdoc/types.js +0 -0
- package/dist/server/tsdoc/zod-to-ts.d.ts +5 -0
- package/dist/server/tsdoc/zod-to-ts.js +107 -0
- package/dist/server/twoslash.d.ts +6 -0
- package/dist/server/twoslash.js +60 -0
- package/dist/server/utils.d.ts +12 -0
- package/dist/server/utils.js +45 -0
- package/dist/types.d.ts +128 -0
- package/dist/types.generated.d.ts +203 -0
- package/dist/types.generated.js +0 -0
- package/dist/types.js +0 -0
- package/loader.cjs +24 -0
- package/package.json +265 -0
- package/styles/cards.css +24 -0
- package/styles/code-block.css +266 -0
- package/styles/default.css +55 -0
- package/styles/react-medium-image-zoom.css +101 -0
- package/styles/scrollbar.css +14 -0
- package/styles/steps.css +22 -0
- package/styles/subheading-anchor.css +25 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { createRequire } from "module";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import fg from "fast-glob";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { CWD, MARKDOWN_EXTENSION_RE } from "./constants.js";
|
|
7
|
+
import { NextraConfigSchema } from "./schemas.js";
|
|
8
|
+
import { logger } from "./utils.js";
|
|
9
|
+
const require2 = createRequire(import.meta.url);
|
|
10
|
+
const MARKDOWN_EXTENSIONS = ["md", "mdx"];
|
|
11
|
+
const DEFAULT_EXTENSIONS = ["js", "jsx", "ts", "tsx"];
|
|
12
|
+
const FILENAME = fileURLToPath(import.meta.url);
|
|
13
|
+
const LOADER_PATH = path.join(FILENAME, "..", "..", "..", "loader.cjs");
|
|
14
|
+
const SEP = path.sep === "/" ? "/" : "\\\\";
|
|
15
|
+
const GET_PAGE_MAP_PATH = "/nextra/dist/server/page-map/get.js";
|
|
16
|
+
const PAGE_MAP_PLACEHOLDER_PATH = "/nextra/dist/server/page-map/placeholder.js";
|
|
17
|
+
const GET_PAGE_MAP_RE = new RegExp(
|
|
18
|
+
GET_PAGE_MAP_PATH.replaceAll("/", SEP).replaceAll(".", String.raw`\.`)
|
|
19
|
+
);
|
|
20
|
+
const PAGE_MAP_PLACEHOLDER_RE = new RegExp(
|
|
21
|
+
PAGE_MAP_PLACEHOLDER_PATH.replaceAll("/", SEP).replaceAll(".", String.raw`\.`)
|
|
22
|
+
);
|
|
23
|
+
const CONTENT_DIR = getContentDirectory();
|
|
24
|
+
function getContentDirectory() {
|
|
25
|
+
const [contentDir = "content"] = fg.sync(["{src/,}content"], {
|
|
26
|
+
onlyDirectories: true
|
|
27
|
+
});
|
|
28
|
+
return contentDir;
|
|
29
|
+
}
|
|
30
|
+
const [nextMajorVersion, nextMinorVersion] = require2("next/package.json").version.split(".", 2).map(Number);
|
|
31
|
+
const shouldUseConfigTurbopack = nextMajorVersion > 15 || nextMajorVersion === 15 && nextMinorVersion > 2;
|
|
32
|
+
const nextra = (nextraConfig) => {
|
|
33
|
+
const { error, data: loaderOptions } = NextraConfigSchema.safeParse(nextraConfig);
|
|
34
|
+
if (error) {
|
|
35
|
+
logger.error("Error validating nextraConfig");
|
|
36
|
+
throw z.prettifyError(error);
|
|
37
|
+
}
|
|
38
|
+
const loader = {
|
|
39
|
+
loader: LOADER_PATH,
|
|
40
|
+
options: loaderOptions
|
|
41
|
+
};
|
|
42
|
+
const pageImportLoader = {
|
|
43
|
+
loader: LOADER_PATH,
|
|
44
|
+
options: { ...loaderOptions, isPageImport: true }
|
|
45
|
+
};
|
|
46
|
+
const pageMapPlaceholderLoader = {
|
|
47
|
+
loader: LOADER_PATH,
|
|
48
|
+
options: {
|
|
49
|
+
// Remove forward slash
|
|
50
|
+
contentDirBasePath: loaderOptions.contentDirBasePath.slice(1),
|
|
51
|
+
contentDir: CONTENT_DIR,
|
|
52
|
+
shouldAddLocaleToLinks: loaderOptions.unstable_shouldAddLocaleToLinks
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
return function withNextra(nextConfig = {}) {
|
|
56
|
+
const { locales, defaultLocale } = nextConfig.i18n || {};
|
|
57
|
+
if (locales) {
|
|
58
|
+
logger.info(
|
|
59
|
+
"You have Next.js i18n enabled, read here https://nextjs.org/docs/app/building-your-application/routing/internationalization for the docs."
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
const pageMapLoader = {
|
|
63
|
+
loader: LOADER_PATH,
|
|
64
|
+
options: {
|
|
65
|
+
// ts complains about readonly array
|
|
66
|
+
locales: locales ? [...locales] : [""]
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const turbopackConfig = (shouldUseConfigTurbopack ? nextConfig.turbopack : (
|
|
70
|
+
// @ts-expect-error -- Backwards compatibility
|
|
71
|
+
nextConfig.experimental?.turbo
|
|
72
|
+
)) ?? {};
|
|
73
|
+
const turbopack = {
|
|
74
|
+
...turbopackConfig,
|
|
75
|
+
rules: {
|
|
76
|
+
...turbopackConfig.rules,
|
|
77
|
+
[`./{src/,}app/**/page.{${MARKDOWN_EXTENSIONS}}`]: {
|
|
78
|
+
as: "*.tsx",
|
|
79
|
+
loaders: [pageImportLoader]
|
|
80
|
+
},
|
|
81
|
+
// Order matter here, pages match first -> after partial files
|
|
82
|
+
[`*.{${MARKDOWN_EXTENSIONS}}`]: {
|
|
83
|
+
as: "*.tsx",
|
|
84
|
+
loaders: [loader]
|
|
85
|
+
},
|
|
86
|
+
[`**${PAGE_MAP_PLACEHOLDER_PATH}`]: {
|
|
87
|
+
loaders: [pageMapPlaceholderLoader]
|
|
88
|
+
},
|
|
89
|
+
[`**${GET_PAGE_MAP_PATH}`]: {
|
|
90
|
+
loaders: [pageMapLoader]
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
resolveAlias: {
|
|
94
|
+
"next-mdx-import-source-file": "@vercel/turbopack-next/mdx-import-source",
|
|
95
|
+
// Fixes when Turbopack is enabled: Module not found: Can't resolve '@theguild/remark-mermaid/mermaid'
|
|
96
|
+
"@theguild/remark-mermaid/mermaid": path.relative(
|
|
97
|
+
CWD,
|
|
98
|
+
path.join(
|
|
99
|
+
require2.resolve("@theguild/remark-mermaid/package.json"),
|
|
100
|
+
"..",
|
|
101
|
+
"dist",
|
|
102
|
+
"mermaid.js"
|
|
103
|
+
)
|
|
104
|
+
),
|
|
105
|
+
...turbopackConfig.resolveAlias,
|
|
106
|
+
"private-next-root-dir/*": "./*",
|
|
107
|
+
"private-next-content-dir/*": `./${CONTENT_DIR}/*`
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
return {
|
|
111
|
+
...nextConfig,
|
|
112
|
+
...shouldUseConfigTurbopack && { turbopack },
|
|
113
|
+
transpilePackages: [
|
|
114
|
+
// To import ESM-only packages with `next dev --turbopack`. Source: https://github.com/vercel/next.js/issues/63318#issuecomment-2079677098
|
|
115
|
+
...// Next.js 15
|
|
116
|
+
process.env.TURBOPACK === "1" || // Next.js 16
|
|
117
|
+
process.env.TURBOPACK === "auto" ? ["shiki", "ts-morph"] : [],
|
|
118
|
+
...nextConfig.transpilePackages || []
|
|
119
|
+
],
|
|
120
|
+
pageExtensions: [
|
|
121
|
+
...nextConfig.pageExtensions || DEFAULT_EXTENSIONS,
|
|
122
|
+
...MARKDOWN_EXTENSIONS
|
|
123
|
+
],
|
|
124
|
+
// We always unset `nextConfig.i18n` property
|
|
125
|
+
i18n: void 0,
|
|
126
|
+
env: {
|
|
127
|
+
...nextConfig.env,
|
|
128
|
+
NEXTRA_LOCALES: JSON.stringify(pageMapLoader.options.locales),
|
|
129
|
+
NEXTRA_DEFAULT_LOCALE: defaultLocale,
|
|
130
|
+
NEXTRA_SHOULD_ADD_LOCALE_TO_LINKS: String(
|
|
131
|
+
loaderOptions.unstable_shouldAddLocaleToLinks
|
|
132
|
+
)
|
|
133
|
+
},
|
|
134
|
+
experimental: {
|
|
135
|
+
...nextConfig.experimental,
|
|
136
|
+
optimizePackageImports: [
|
|
137
|
+
"nextra/components",
|
|
138
|
+
"nextra-theme-docs",
|
|
139
|
+
"nextra-theme-blog",
|
|
140
|
+
...nextConfig.experimental?.optimizePackageImports || []
|
|
141
|
+
],
|
|
142
|
+
...!shouldUseConfigTurbopack && { turbo: turbopack }
|
|
143
|
+
},
|
|
144
|
+
webpack(config, options) {
|
|
145
|
+
if (config.watchOptions.ignored instanceof RegExp) {
|
|
146
|
+
const ignored = config.watchOptions.ignored.source;
|
|
147
|
+
config.watchOptions = {
|
|
148
|
+
...config.watchOptions,
|
|
149
|
+
ignored: new RegExp(
|
|
150
|
+
ignored.replace(
|
|
151
|
+
String.raw`(\.(git|next)|node_modules)`,
|
|
152
|
+
String.raw`\.(git|next)`
|
|
153
|
+
)
|
|
154
|
+
)
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
config.resolve.alias["private-next-content-dir"] = [
|
|
158
|
+
"private-next-root-dir/content",
|
|
159
|
+
"private-next-root-dir/src/content"
|
|
160
|
+
];
|
|
161
|
+
config.resolve.alias["next-mdx-import-source-file"] = [
|
|
162
|
+
"private-next-root-dir/mdx-components",
|
|
163
|
+
"private-next-root-dir/src/mdx-components"
|
|
164
|
+
];
|
|
165
|
+
const rules = config.module.rules;
|
|
166
|
+
rules.push(
|
|
167
|
+
{
|
|
168
|
+
test: PAGE_MAP_PLACEHOLDER_RE,
|
|
169
|
+
use: [options.defaultLoaders.babel, pageMapPlaceholderLoader]
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
test: GET_PAGE_MAP_RE,
|
|
173
|
+
use: [options.defaultLoaders.babel, pageMapLoader]
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
test: MARKDOWN_EXTENSION_RE,
|
|
177
|
+
oneOf: [
|
|
178
|
+
{
|
|
179
|
+
// Match pages (imports without an issuer request).
|
|
180
|
+
issuer: (request) => request === "",
|
|
181
|
+
use: [options.defaultLoaders.babel, pageImportLoader]
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
// Match Markdown imports from non-pages. These imports have an
|
|
185
|
+
// issuer, which can be anything as long as it's not empty string.
|
|
186
|
+
// When the issuer is `null`, it means that it can be imported via a
|
|
187
|
+
// runtime import call such as `import('...')`.
|
|
188
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- types are wrong, value can be null
|
|
189
|
+
issuer: (request) => request === null || !!request,
|
|
190
|
+
use: [options.defaultLoaders.babel, loader]
|
|
191
|
+
}
|
|
192
|
+
]
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
return nextConfig.webpack?.(config, options) || config;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
var server_default = nextra;
|
|
201
|
+
export {
|
|
202
|
+
server_default as default
|
|
203
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LoaderContext } from 'webpack';
|
|
2
|
+
import { LoaderOptions } from '../types.js';
|
|
3
|
+
import 'mdast';
|
|
4
|
+
import 'next';
|
|
5
|
+
import 'react';
|
|
6
|
+
import 'zod';
|
|
7
|
+
import './schemas.js';
|
|
8
|
+
import './lib/index.js';
|
|
9
|
+
import 'rehype-katex/lib/index.js';
|
|
10
|
+
import 'better-react-mathjax';
|
|
11
|
+
import 'rehype-pretty-code';
|
|
12
|
+
import '../types.generated.js';
|
|
13
|
+
import '@mdx-js/mdx';
|
|
14
|
+
import 'rehype-katex';
|
|
15
|
+
|
|
16
|
+
declare function loader(this: LoaderContext<LoaderOptions>, source: string): Promise<string>;
|
|
17
|
+
|
|
18
|
+
export { loader };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { transformerTwoslash } from "@shikijs/twoslash";
|
|
3
|
+
import { findPagesDir } from "next/dist/lib/find-pages-dir.js";
|
|
4
|
+
import { compileMetadata } from "./compile-metadata.js";
|
|
5
|
+
import { compileMdx } from "./compile.js";
|
|
6
|
+
import { CWD, IS_PRODUCTION, METADATA_ONLY_RQ } from "./constants.js";
|
|
7
|
+
import { findMetaAndPageFilePaths } from "./page-map/find-meta-and-page-file-paths.js";
|
|
8
|
+
import { convertPageMapToJs } from "./page-map/to-js.js";
|
|
9
|
+
import { convertToPageMap } from "./page-map/to-page-map.js";
|
|
10
|
+
import { twoslashRenderer } from "./twoslash.js";
|
|
11
|
+
import { logger } from "./utils.js";
|
|
12
|
+
const NOW = Date.now();
|
|
13
|
+
const APP_DIR = findPagesDir(CWD).appDir;
|
|
14
|
+
if (!APP_DIR) {
|
|
15
|
+
throw new Error("Unable to find `app` directory");
|
|
16
|
+
}
|
|
17
|
+
const repository = await (async () => {
|
|
18
|
+
if (process.versions.webcontainer) return;
|
|
19
|
+
const { Repository } = await import("@napi-rs/simple-git");
|
|
20
|
+
try {
|
|
21
|
+
const repository2 = Repository.discover(CWD);
|
|
22
|
+
if (repository2.isShallow()) {
|
|
23
|
+
if (process.env.VERCEL) {
|
|
24
|
+
logger.warn(
|
|
25
|
+
"The repository is shallow cloned, so the latest modified time will not be presented. Set the VERCEL_DEEP_CLONE=true environment variable to enable deep cloning."
|
|
26
|
+
);
|
|
27
|
+
} else if (process.env.GITHUB_ACTION) {
|
|
28
|
+
logger.warn(
|
|
29
|
+
"The repository is shallow cloned, so the latest modified time will not be presented. See https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches to fetch all the history."
|
|
30
|
+
);
|
|
31
|
+
} else {
|
|
32
|
+
logger.warn(
|
|
33
|
+
"The repository is shallow cloned, so the latest modified time will not be presented."
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return repository2;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
logger.warn(`Init git repository failed ${error.message}`);
|
|
40
|
+
}
|
|
41
|
+
})();
|
|
42
|
+
const GIT_ROOT = repository ? path.join(repository.path(), "..") : "";
|
|
43
|
+
const DEFAULT_TRANSFORMERS = transformerTwoslash({
|
|
44
|
+
renderer: twoslashRenderer(),
|
|
45
|
+
explicitTrigger: true
|
|
46
|
+
});
|
|
47
|
+
async function loader(source) {
|
|
48
|
+
const {
|
|
49
|
+
isPageImport,
|
|
50
|
+
defaultShowCopyCode,
|
|
51
|
+
search,
|
|
52
|
+
staticImage,
|
|
53
|
+
readingTime: _readingTime,
|
|
54
|
+
latex,
|
|
55
|
+
codeHighlight,
|
|
56
|
+
mdxOptions,
|
|
57
|
+
contentDirBasePath,
|
|
58
|
+
contentDir,
|
|
59
|
+
locales,
|
|
60
|
+
whiteListTagsStyling,
|
|
61
|
+
shouldAddLocaleToLinks
|
|
62
|
+
} = this.getOptions();
|
|
63
|
+
const { resourcePath, resourceQuery } = this;
|
|
64
|
+
if (contentDir) {
|
|
65
|
+
const locale = resourceQuery.replace("?lang=", "");
|
|
66
|
+
this.addContextDependency(APP_DIR);
|
|
67
|
+
this.addContextDependency(path.join(CWD, contentDir, locale));
|
|
68
|
+
const filePaths = await findMetaAndPageFilePaths({
|
|
69
|
+
dir: APP_DIR,
|
|
70
|
+
cwd: CWD,
|
|
71
|
+
locale,
|
|
72
|
+
contentDir
|
|
73
|
+
});
|
|
74
|
+
let { pageMap, mdxPages } = convertToPageMap({
|
|
75
|
+
filePaths,
|
|
76
|
+
basePath: shouldAddLocaleToLinks ? [locale, contentDirBasePath].filter(Boolean).join("/") : contentDirBasePath,
|
|
77
|
+
locale
|
|
78
|
+
});
|
|
79
|
+
if (shouldAddLocaleToLinks && "children" in pageMap[0]) {
|
|
80
|
+
pageMap = pageMap[0].children;
|
|
81
|
+
}
|
|
82
|
+
const globalMetaPath = filePaths.find(
|
|
83
|
+
(filePath) => filePath.includes("/_meta.global.")
|
|
84
|
+
);
|
|
85
|
+
return convertPageMapToJs({ pageMap, mdxPages, globalMetaPath });
|
|
86
|
+
}
|
|
87
|
+
if (locales) {
|
|
88
|
+
return replaceDynamicResourceQuery(
|
|
89
|
+
source,
|
|
90
|
+
"import(`./placeholder.js?lang=${lang}`)",
|
|
91
|
+
locales
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
const lastCommitTime = IS_PRODUCTION ? await getLastCommitTime(resourcePath) : NOW;
|
|
95
|
+
if (!IS_PRODUCTION && resourceQuery === METADATA_ONLY_RQ) {
|
|
96
|
+
return compileMetadata(source, {
|
|
97
|
+
filePath: resourcePath,
|
|
98
|
+
lastCommitTime
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return compileMdx(source, {
|
|
102
|
+
mdxOptions: {
|
|
103
|
+
...mdxOptions,
|
|
104
|
+
jsx: true,
|
|
105
|
+
outputFormat: "program",
|
|
106
|
+
rehypePrettyCodeOptions: {
|
|
107
|
+
...mdxOptions.rehypePrettyCodeOptions,
|
|
108
|
+
transformers: [
|
|
109
|
+
DEFAULT_TRANSFORMERS,
|
|
110
|
+
...mdxOptions.rehypePrettyCodeOptions.transformers || []
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
readingTime: _readingTime,
|
|
115
|
+
defaultShowCopyCode,
|
|
116
|
+
staticImage,
|
|
117
|
+
search,
|
|
118
|
+
latex,
|
|
119
|
+
codeHighlight,
|
|
120
|
+
filePath: resourcePath,
|
|
121
|
+
useCachedCompiler: true,
|
|
122
|
+
isPageImport,
|
|
123
|
+
whiteListTagsStyling,
|
|
124
|
+
lastCommitTime
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function replaceDynamicResourceQuery(rawJs, rawImport, locales) {
|
|
128
|
+
const { importPath } = rawJs.match(/import\(`(?<importPath>.+?)\?lang=\${lang}`\)/)?.groups || {};
|
|
129
|
+
if (!importPath) {
|
|
130
|
+
throw new Error(
|
|
131
|
+
`Can't find \`${rawImport}\` statement. This is a Nextra bug`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
const replaced = `{
|
|
135
|
+
${locales.map((lang) => `"${lang}": () => import("${importPath}?lang=${lang}")`).join(",\n")}
|
|
136
|
+
}[lang]()`;
|
|
137
|
+
return rawJs.replace(rawImport, replaced);
|
|
138
|
+
}
|
|
139
|
+
async function getLastCommitTime(filePath) {
|
|
140
|
+
if (!repository) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const relativePath = path.relative(GIT_ROOT, filePath);
|
|
144
|
+
try {
|
|
145
|
+
return await repository.getFileLatestModifiedDateAsync(relativePath);
|
|
146
|
+
} catch {
|
|
147
|
+
logger.warn(
|
|
148
|
+
"Failed to get the last modified timestamp from Git for the file",
|
|
149
|
+
relativePath
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
export {
|
|
154
|
+
loader
|
|
155
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* // Basic usage
|
|
8
|
+
* export { proxy } from 'nextra/locales'
|
|
9
|
+
*
|
|
10
|
+
* export const config = {
|
|
11
|
+
* // Matcher ignoring `/_next/` and `/api/`
|
|
12
|
+
* matcher: [
|
|
13
|
+
* '/((?!api|_next/static|_next/image|favicon.ico|icon.svg|apple-icon.png|manifest|_pagefind).*)'
|
|
14
|
+
* ]
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare function proxy(request: NextRequest): NextResponse<unknown> | undefined;
|
|
19
|
+
/** @deprecated Use `export { proxy } from 'nextra/locales'` instead. */
|
|
20
|
+
declare const middleware: typeof proxy;
|
|
21
|
+
|
|
22
|
+
export { middleware, proxy };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { match as matchLocale } from "@formatjs/intl-localematcher";
|
|
2
|
+
import Negotiator from "negotiator";
|
|
3
|
+
import { addBasePath } from "next/dist/client/add-base-path";
|
|
4
|
+
import { NextResponse } from "next/server";
|
|
5
|
+
const locales = JSON.parse(process.env.NEXTRA_LOCALES);
|
|
6
|
+
const defaultLocale = process.env.NEXTRA_DEFAULT_LOCALE;
|
|
7
|
+
const HAS_LOCALE_RE = new RegExp(String.raw`^\/(${locales.join("|")})(\/|$)`);
|
|
8
|
+
const COOKIE_NAME = "NEXT_LOCALE";
|
|
9
|
+
function getHeadersLocale(request) {
|
|
10
|
+
const headers = Object.fromEntries(
|
|
11
|
+
// @ts-expect-error -- this works
|
|
12
|
+
request.headers.entries()
|
|
13
|
+
);
|
|
14
|
+
const languages = new Negotiator({ headers }).languages(locales);
|
|
15
|
+
const locale = matchLocale(languages, locales, defaultLocale);
|
|
16
|
+
return locale;
|
|
17
|
+
}
|
|
18
|
+
function proxy(request) {
|
|
19
|
+
const { pathname } = request.nextUrl;
|
|
20
|
+
const pathnameHasLocale = HAS_LOCALE_RE.test(pathname);
|
|
21
|
+
const cookieLocale = request.cookies.get(COOKIE_NAME)?.value;
|
|
22
|
+
if (!pathnameHasLocale) {
|
|
23
|
+
const locale = cookieLocale || getHeadersLocale(request);
|
|
24
|
+
const url = addBasePath(`/${locale}${pathname}`);
|
|
25
|
+
return NextResponse.redirect(new URL(url, request.url));
|
|
26
|
+
}
|
|
27
|
+
const [, requestLocale] = pathname.split("/", 2);
|
|
28
|
+
if (requestLocale !== cookieLocale) {
|
|
29
|
+
const response = NextResponse.next();
|
|
30
|
+
response.cookies.set(COOKIE_NAME, requestLocale);
|
|
31
|
+
return response;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const middleware = proxy;
|
|
35
|
+
export {
|
|
36
|
+
middleware,
|
|
37
|
+
proxy
|
|
38
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fg from "fast-glob";
|
|
3
|
+
import slash from "slash";
|
|
4
|
+
async function findMetaAndPageFilePaths({
|
|
5
|
+
dir,
|
|
6
|
+
cwd,
|
|
7
|
+
locale = "",
|
|
8
|
+
// Can be `src/content` also
|
|
9
|
+
contentDir = "content"
|
|
10
|
+
}) {
|
|
11
|
+
const appDir = slash(path.relative(cwd, dir));
|
|
12
|
+
if (locale) contentDir += `/${locale}`;
|
|
13
|
+
const pattern = appDir ? [
|
|
14
|
+
`${contentDir}/**/_meta.{js,jsx,ts,tsx}`,
|
|
15
|
+
// Include `_meta` files from `content` directory
|
|
16
|
+
`${contentDir}/**/*.{md,mdx}`,
|
|
17
|
+
// Include all Markdown/MDX files from `content` directory
|
|
18
|
+
`${appDir}/**/page.{js,jsx,jsx,tsx,md,mdx}`,
|
|
19
|
+
`${appDir}/**/_meta.{js,jsx,ts,tsx}`,
|
|
20
|
+
// Include `_meta` files from `app` directory
|
|
21
|
+
`${appDir}/_meta.global.{js,jsx,ts,tsx}`,
|
|
22
|
+
// Include global `_meta` file from `app` directory
|
|
23
|
+
`!${appDir}/**/{_,[}*/*`
|
|
24
|
+
// Ignore subdirectories starting with `_` and dynamic routes
|
|
25
|
+
] : ["**/_meta.{js,jsx,ts,tsx}", "**/*.{md,mdx}"];
|
|
26
|
+
const result = await fg(pattern, { cwd });
|
|
27
|
+
const relativePaths = result.sort((a, b) => a.localeCompare(b));
|
|
28
|
+
return relativePaths;
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
findMetaAndPageFilePaths
|
|
32
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { PageMapItem } from '../../types.js';
|
|
2
|
+
import 'mdast';
|
|
3
|
+
import 'next';
|
|
4
|
+
import 'react';
|
|
5
|
+
import 'zod';
|
|
6
|
+
import '../schemas.js';
|
|
7
|
+
import './lib/index.js';
|
|
8
|
+
import 'rehype-katex/lib/index.js';
|
|
9
|
+
import 'better-react-mathjax';
|
|
10
|
+
import 'rehype-pretty-code';
|
|
11
|
+
import '../../types.generated.js';
|
|
12
|
+
import '@mdx-js/mdx';
|
|
13
|
+
import 'rehype-katex';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves the page map structure for a given route handling nested routes.
|
|
17
|
+
*
|
|
18
|
+
* The page map structure represents the hierarchical organization of your documentation or content,
|
|
19
|
+
* where each item can be either a page or a folder containing more pages.
|
|
20
|
+
*
|
|
21
|
+
* @returns A Promise that resolves to an array of `PageMapItem` objects representing the page structure
|
|
22
|
+
* such as `MdxFile`, `Folder` and `MetaJsonFile`.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { getPageMap } from 'nextra/page-map'
|
|
27
|
+
*
|
|
28
|
+
* // Get the root page map
|
|
29
|
+
* const rootPageMap = await getPageMap()
|
|
30
|
+
*
|
|
31
|
+
* // Get the page map for a specific route
|
|
32
|
+
* const blogPageMap = await getPageMap('/blog')
|
|
33
|
+
*
|
|
34
|
+
* // Get the page map for a specific language when using i18n
|
|
35
|
+
* const enPageMap = await getPageMap('/en')
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @throws {Error} when the specified route segment cannot be found in the page map.
|
|
39
|
+
*
|
|
40
|
+
* @see [Page Map Structure Documentation](https://nextra.site/docs/file-conventions/meta-file#pagemap-structure).
|
|
41
|
+
*/
|
|
42
|
+
declare function getPageMap(
|
|
43
|
+
/**
|
|
44
|
+
* The route path to retrieve the page map for.
|
|
45
|
+
* @default "/"
|
|
46
|
+
*/
|
|
47
|
+
route?: string): Promise<PageMapItem[]>;
|
|
48
|
+
declare function getRouteToFilepath(lang?: string): Promise<Record<string, string>>;
|
|
49
|
+
|
|
50
|
+
export { getPageMap, getRouteToFilepath };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
function importPageMap(lang = "") {
|
|
2
|
+
return import(`./placeholder.js?lang=${lang}`);
|
|
3
|
+
}
|
|
4
|
+
const defaultLocale = process.env.NEXTRA_DEFAULT_LOCALE;
|
|
5
|
+
async function getPageMap(route = "/") {
|
|
6
|
+
const segments = route.split("/");
|
|
7
|
+
const lang = segments.splice(0, defaultLocale ? 2 : 1).at(-1);
|
|
8
|
+
let { pageMap } = await importPageMap(lang);
|
|
9
|
+
let segment;
|
|
10
|
+
while (segment = segments.shift()) {
|
|
11
|
+
const folder = pageMap.find(
|
|
12
|
+
(item) => "name" in item && item.name === segment
|
|
13
|
+
);
|
|
14
|
+
if (!folder) {
|
|
15
|
+
throw new Error(`Can't find pageMap for "${segment}" in route "${route}"`);
|
|
16
|
+
}
|
|
17
|
+
pageMap = folder.children;
|
|
18
|
+
}
|
|
19
|
+
return pageMap;
|
|
20
|
+
}
|
|
21
|
+
async function getRouteToFilepath(lang) {
|
|
22
|
+
const { RouteToFilepath } = await importPageMap(lang);
|
|
23
|
+
return RouteToFilepath;
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
getPageMap,
|
|
27
|
+
getRouteToFilepath
|
|
28
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { PageMapItem, MdxFile } from '../../types.js';
|
|
3
|
+
import 'mdast';
|
|
4
|
+
import 'next';
|
|
5
|
+
import 'zod';
|
|
6
|
+
import '../schemas.js';
|
|
7
|
+
import './lib/index.js';
|
|
8
|
+
import 'rehype-katex/lib/index.js';
|
|
9
|
+
import 'better-react-mathjax';
|
|
10
|
+
import 'rehype-pretty-code';
|
|
11
|
+
import '../../types.generated.js';
|
|
12
|
+
import '@mdx-js/mdx';
|
|
13
|
+
import 'rehype-katex';
|
|
14
|
+
|
|
15
|
+
declare function createIndexPage(pageMap: PageMapItem[]): Promise<string>;
|
|
16
|
+
declare function getIndexPageMap(pageMap: PageMapItem[]): ({
|
|
17
|
+
type: "separator";
|
|
18
|
+
title?: string | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | undefined;
|
|
19
|
+
} | MdxFile[])[];
|
|
20
|
+
|
|
21
|
+
export { createIndexPage, getIndexPageMap };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { compileMdx } from "../compile.js";
|
|
2
|
+
function renderCard(item) {
|
|
3
|
+
const icon = item.frontMatter?.icon;
|
|
4
|
+
const Icon = icon ? `<${icon}/>` : "null";
|
|
5
|
+
return `<Cards.Card title="${item.title}" href="${item.route}" icon={${Icon}} />`;
|
|
6
|
+
}
|
|
7
|
+
async function createIndexPage(pageMap) {
|
|
8
|
+
const result = [];
|
|
9
|
+
let hasCards = false;
|
|
10
|
+
for (const item of pageMap) {
|
|
11
|
+
if ("data" in item) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (item.type === "separator") {
|
|
15
|
+
if (hasCards) {
|
|
16
|
+
result.push("</Cards>");
|
|
17
|
+
hasCards = false;
|
|
18
|
+
}
|
|
19
|
+
result.push(`## ${item.title}`);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (!hasCards) {
|
|
23
|
+
hasCards = true;
|
|
24
|
+
result.push("<Cards>");
|
|
25
|
+
}
|
|
26
|
+
result.push(renderCard(item));
|
|
27
|
+
}
|
|
28
|
+
if (hasCards) {
|
|
29
|
+
result.push("</Cards>");
|
|
30
|
+
}
|
|
31
|
+
const rawMdx = result.join("\n");
|
|
32
|
+
const rawJs = await compileMdx(rawMdx);
|
|
33
|
+
return rawJs;
|
|
34
|
+
}
|
|
35
|
+
function getIndexPageMap(pageMap) {
|
|
36
|
+
const result = [];
|
|
37
|
+
for (const item of pageMap) {
|
|
38
|
+
if ("data" in item) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (item.type === "separator") {
|
|
42
|
+
result.push(item);
|
|
43
|
+
} else {
|
|
44
|
+
const lastResult = result.at(-1);
|
|
45
|
+
if (Array.isArray(lastResult)) {
|
|
46
|
+
lastResult.push(item);
|
|
47
|
+
} else {
|
|
48
|
+
result.push([item]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
createIndexPage,
|
|
56
|
+
getIndexPageMap
|
|
57
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Metadata } from 'next';
|
|
2
|
+
export { normalizePageMap } from './normalize.js';
|
|
3
|
+
export { convertToPageMap } from './to-page-map.js';
|
|
4
|
+
export { mergeMetaWithPageMap } from './merge-meta-with-page-map.js';
|
|
5
|
+
export { getPageMap } from './get.js';
|
|
6
|
+
export { createIndexPage, getIndexPageMap } from './index-page.js';
|
|
7
|
+
import '../../types.js';
|
|
8
|
+
import 'mdast';
|
|
9
|
+
import 'react';
|
|
10
|
+
import 'zod';
|
|
11
|
+
import '../schemas.js';
|
|
12
|
+
import './lib/index.js';
|
|
13
|
+
import 'rehype-katex/lib/index.js';
|
|
14
|
+
import 'better-react-mathjax';
|
|
15
|
+
import 'rehype-pretty-code';
|
|
16
|
+
import '../../types.generated.js';
|
|
17
|
+
import '@mdx-js/mdx';
|
|
18
|
+
import 'rehype-katex';
|
|
19
|
+
|
|
20
|
+
declare function getMetadata(page: {
|
|
21
|
+
metadata: Metadata;
|
|
22
|
+
} | {
|
|
23
|
+
generateMetadata?: (props: object) => Promise<Metadata>;
|
|
24
|
+
}): Promise<Metadata> | Metadata;
|
|
25
|
+
|
|
26
|
+
export { getMetadata };
|