@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,24 @@
|
|
|
1
|
+
import { normalizePageMap } from "./normalize.js";
|
|
2
|
+
import { convertToPageMap } from "./to-page-map.js";
|
|
3
|
+
import { mergeMetaWithPageMap } from "./merge-meta-with-page-map.js";
|
|
4
|
+
import { getPageMap } from "./get.js";
|
|
5
|
+
import { createIndexPage, getIndexPageMap } from "./index-page.js";
|
|
6
|
+
function getMetadata(page) {
|
|
7
|
+
if ("generateMetadata" in page && // `@sentry/nextjs` makes `generateMetadata` getter function which can be `undefined`
|
|
8
|
+
page.generateMetadata) {
|
|
9
|
+
return page.generateMetadata({});
|
|
10
|
+
}
|
|
11
|
+
if ("metadata" in page) {
|
|
12
|
+
return page.metadata;
|
|
13
|
+
}
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
convertToPageMap,
|
|
18
|
+
createIndexPage,
|
|
19
|
+
getIndexPageMap,
|
|
20
|
+
getMetadata,
|
|
21
|
+
getPageMap,
|
|
22
|
+
mergeMetaWithPageMap,
|
|
23
|
+
normalizePageMap
|
|
24
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Folder, PageMapItem, TItem, DynamicMeta } 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
|
+
declare function mergeMetaWithPageMap<T extends Folder | PageMapItem[] | TItem>(pageMap: T, meta: DynamicMeta, shouldCheckIndividualMetaFilesUsage?: boolean): T;
|
|
16
|
+
|
|
17
|
+
export { mergeMetaWithPageMap };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { pageTitleFromFilename } from "../utils.js";
|
|
3
|
+
function isFolder(value) {
|
|
4
|
+
return !!value && typeof value === "object" && "items" in value && // @ts-expect-error -- fixme
|
|
5
|
+
value.type !== "menu";
|
|
6
|
+
}
|
|
7
|
+
function normalizeMetaRecord(obj, map) {
|
|
8
|
+
return Object.fromEntries(
|
|
9
|
+
Object.entries(obj).map(([key, value]) => {
|
|
10
|
+
let val;
|
|
11
|
+
if (isFolder(value)) {
|
|
12
|
+
const { items: _items, ...rest } = value;
|
|
13
|
+
val = rest;
|
|
14
|
+
} else {
|
|
15
|
+
val = value;
|
|
16
|
+
}
|
|
17
|
+
return [key, map[key] ? val : val || pageTitleFromFilename(key)];
|
|
18
|
+
})
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
function mergeMetaWithPageMap(pageMap, meta, shouldCheckIndividualMetaFilesUsage = false) {
|
|
22
|
+
if ("children" in pageMap) {
|
|
23
|
+
return {
|
|
24
|
+
...pageMap,
|
|
25
|
+
children: mergeMetaWithPageMap(
|
|
26
|
+
// @ts-expect-error -- fixme
|
|
27
|
+
pageMap.children,
|
|
28
|
+
meta,
|
|
29
|
+
shouldCheckIndividualMetaFilesUsage
|
|
30
|
+
)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const result = pageMap.map(({ __pagePath, ...restParent }) => {
|
|
34
|
+
if ("children" in restParent) {
|
|
35
|
+
restParent.children = mergeMetaWithPageMap(
|
|
36
|
+
restParent.children,
|
|
37
|
+
// @ts-expect-error -- fixme
|
|
38
|
+
meta[restParent.name]?.items || {}
|
|
39
|
+
);
|
|
40
|
+
return restParent;
|
|
41
|
+
}
|
|
42
|
+
return restParent;
|
|
43
|
+
});
|
|
44
|
+
const normalizedMetaRecord = normalizeMetaRecord(
|
|
45
|
+
meta,
|
|
46
|
+
// @ts-expect-error -- fixme
|
|
47
|
+
Object.fromEntries(result.map((key) => [key.name, key.frontMatter]))
|
|
48
|
+
);
|
|
49
|
+
const metaRecord = result[0] && "data" in result[0] && result[0].data;
|
|
50
|
+
if (metaRecord) {
|
|
51
|
+
if (shouldCheckIndividualMetaFilesUsage) {
|
|
52
|
+
const childRoute = result[1].route;
|
|
53
|
+
const { dir } = path.parse(childRoute);
|
|
54
|
+
const metaPath = `${dir.replace(/^\/$/, "")}/_meta`;
|
|
55
|
+
throw new Error(
|
|
56
|
+
[
|
|
57
|
+
"Merging an `_meta.global` file with a folder-specific `_meta` is unsupported.",
|
|
58
|
+
`Move content of \`${metaPath}\` file into the \`_meta.global\` file`
|
|
59
|
+
].join("\n")
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
;
|
|
63
|
+
result[0].data = {
|
|
64
|
+
...metaRecord,
|
|
65
|
+
...normalizedMetaRecord
|
|
66
|
+
};
|
|
67
|
+
} else {
|
|
68
|
+
result.unshift({ data: normalizedMetaRecord });
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
mergeMetaWithPageMap
|
|
74
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PageMapItem, Folder, TItem } 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
|
+
declare function normalizePageMap(pageMap: PageMapItem[] | Folder | TItem): any;
|
|
16
|
+
|
|
17
|
+
export { normalizePageMap };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { metaSchema } from "../schemas.js";
|
|
3
|
+
import { pageTitleFromFilename } from "../utils.js";
|
|
4
|
+
function normalizePageMap(pageMap) {
|
|
5
|
+
if (Array.isArray(pageMap)) {
|
|
6
|
+
return sortFolder(
|
|
7
|
+
pageMap.map((item) => "children" in item ? normalizePageMap(item) : item)
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
return sortFolder(pageMap);
|
|
11
|
+
}
|
|
12
|
+
function titlize(item, meta) {
|
|
13
|
+
const titleFromMeta = meta[item.name]?.title;
|
|
14
|
+
if (titleFromMeta) return titleFromMeta;
|
|
15
|
+
if ("frontMatter" in item && item.frontMatter) {
|
|
16
|
+
const titleFromFrontMatter = item.frontMatter.sidebarTitle || item.frontMatter.title;
|
|
17
|
+
if (titleFromFrontMatter) return titleFromFrontMatter;
|
|
18
|
+
}
|
|
19
|
+
return pageTitleFromFilename(item.name);
|
|
20
|
+
}
|
|
21
|
+
function sortFolder(pageMap) {
|
|
22
|
+
const newChildren = [];
|
|
23
|
+
const isFolder = !Array.isArray(pageMap);
|
|
24
|
+
const folder = isFolder ? { ...pageMap } : { children: pageMap };
|
|
25
|
+
const meta = {};
|
|
26
|
+
for (const item of folder.children) {
|
|
27
|
+
if (isFolder && "frontMatter" in item && item.frontMatter?.asIndexPage && item.route === folder.route) {
|
|
28
|
+
folder.frontMatter = item.frontMatter;
|
|
29
|
+
} else if ("children" in item) {
|
|
30
|
+
newChildren.push(normalizePageMap(item));
|
|
31
|
+
} else if ("data" in item) {
|
|
32
|
+
for (const [key, titleOrObject] of Object.entries(item.data)) {
|
|
33
|
+
const { data, error } = metaSchema.safeParse(titleOrObject);
|
|
34
|
+
if (error) {
|
|
35
|
+
throw z.prettifyError(error);
|
|
36
|
+
}
|
|
37
|
+
if (key === "*") {
|
|
38
|
+
delete data.title;
|
|
39
|
+
delete data.href;
|
|
40
|
+
}
|
|
41
|
+
meta[key] = data;
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
newChildren.push(item);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const metaKeys = Object.keys(meta);
|
|
48
|
+
const hasIndexKey = metaKeys.includes("index");
|
|
49
|
+
const items = newChildren.sort((a, b) => {
|
|
50
|
+
const indexA = metaKeys.indexOf(a.name);
|
|
51
|
+
const indexB = metaKeys.indexOf(b.name);
|
|
52
|
+
if (!hasIndexKey) {
|
|
53
|
+
if (b.name === "index") return 1;
|
|
54
|
+
if (a.name === "index") return -1;
|
|
55
|
+
}
|
|
56
|
+
if (indexA === -1 && indexB === -1) return a.name < b.name ? -1 : 1;
|
|
57
|
+
if (indexA === -1) return 1;
|
|
58
|
+
if (indexB === -1) return -1;
|
|
59
|
+
return indexA - indexB;
|
|
60
|
+
});
|
|
61
|
+
for (const [index, metaKey] of metaKeys.filter((key) => key !== "*").entries()) {
|
|
62
|
+
const metaItem = meta[metaKey];
|
|
63
|
+
const item = items.find((item2) => item2.name === metaKey);
|
|
64
|
+
if (metaItem.type === "menu" && item) {
|
|
65
|
+
item.items = metaItem.items;
|
|
66
|
+
const { children } = items.find(
|
|
67
|
+
(i) => i.name === metaKey
|
|
68
|
+
);
|
|
69
|
+
for (const [key, value] of Object.entries(
|
|
70
|
+
// @ts-expect-error fixme
|
|
71
|
+
item.items
|
|
72
|
+
)) {
|
|
73
|
+
if (!value.href && children.every((i) => i.name !== key)) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
`Validation of "_meta" file has failed.
|
|
76
|
+
The field key "${metaKey}.items.${key}" in \`_meta\` file refers to a page that cannot be found, remove this key from "_meta" file.`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (item) continue;
|
|
82
|
+
const isValid = metaItem.type === "separator" || metaItem.type === "menu" || metaItem.href;
|
|
83
|
+
if (!isValid) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
`Validation of "_meta" file has failed.
|
|
86
|
+
The field key "${metaKey}" in \`_meta\` file refers to a page that cannot be found, remove this key from "_meta" file.`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
const currentItem = items[index];
|
|
90
|
+
if (currentItem?.name === metaKey) continue;
|
|
91
|
+
items.splice(
|
|
92
|
+
index,
|
|
93
|
+
// index at which to start changing the array
|
|
94
|
+
0,
|
|
95
|
+
// remove zero items
|
|
96
|
+
// @ts-expect-error fixme
|
|
97
|
+
{ name: metaKey, ...meta[metaKey] }
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
if (metaKeys.length) {
|
|
101
|
+
items.unshift({ data: meta });
|
|
102
|
+
}
|
|
103
|
+
const itemsWithTitle = items.map((item) => {
|
|
104
|
+
const isSeparator = "type" in item && item.type === "separator";
|
|
105
|
+
if ("name" in item && !isSeparator) {
|
|
106
|
+
return {
|
|
107
|
+
...item,
|
|
108
|
+
title: titlize(item, meta)
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return item;
|
|
112
|
+
});
|
|
113
|
+
const result = isFolder ? {
|
|
114
|
+
...folder,
|
|
115
|
+
title: titlize(folder, {}),
|
|
116
|
+
children: itemsWithTitle
|
|
117
|
+
} : itemsWithTitle;
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
export {
|
|
121
|
+
normalizePageMap
|
|
122
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ArrayExpression } from 'estree';
|
|
2
|
+
import { TItem, Import } 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 convertPageMapToAst(pageMap: TItem[], imports: Import[]): ArrayExpression;
|
|
17
|
+
|
|
18
|
+
export { convertPageMapToAst };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { MARKDOWN_EXTENSION_RE } from "../constants.js";
|
|
3
|
+
import { createAstObject } from "../utils.js";
|
|
4
|
+
function cleanFilePath(filePath) {
|
|
5
|
+
const { dir, name } = path.parse(filePath);
|
|
6
|
+
const fileName = `${dir.replace(/^(src\/)?content\/?/, "")}_${name}`;
|
|
7
|
+
return (
|
|
8
|
+
// handle non-"\w" characters
|
|
9
|
+
encodeURI(fileName).replaceAll(/[\W_]+/g, "_").replace(/^_/, "").replace(/^\d/, (match) => `_${match}`)
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
function convertPageMapToAst(pageMap, imports) {
|
|
13
|
+
const elements = pageMap.map((item) => {
|
|
14
|
+
if ("children" in item) {
|
|
15
|
+
return createAstObject({
|
|
16
|
+
name: item.name,
|
|
17
|
+
route: item.route,
|
|
18
|
+
children: convertPageMapToAst(item.children, imports)
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if ("route" in item) {
|
|
22
|
+
const filePath2 = item.__pagePath;
|
|
23
|
+
const importName2 = cleanFilePath(filePath2);
|
|
24
|
+
imports.push({ importName: importName2, filePath: filePath2 });
|
|
25
|
+
return createAstObject({
|
|
26
|
+
name: item.name,
|
|
27
|
+
route: item.route,
|
|
28
|
+
frontMatter: MARKDOWN_EXTENSION_RE.test(filePath2) ? { type: "Identifier", name: importName2 } : {
|
|
29
|
+
type: "CallExpression",
|
|
30
|
+
callee: { type: "Identifier", name: "getMetadata" },
|
|
31
|
+
arguments: [{ type: "Identifier", name: importName2 }],
|
|
32
|
+
optional: false
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const filePath = item.__metaPath;
|
|
37
|
+
const importName = cleanFilePath(filePath);
|
|
38
|
+
imports.push({ importName, filePath });
|
|
39
|
+
return createAstObject({
|
|
40
|
+
data: { type: "Identifier", name: importName }
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
return { type: "ArrayExpression", elements };
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
convertPageMapToAst
|
|
47
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TItem } 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
|
+
declare function convertPageMapToJs({ pageMap, mdxPages, globalMetaPath }: {
|
|
16
|
+
pageMap: TItem[];
|
|
17
|
+
mdxPages: Record<string, string>;
|
|
18
|
+
globalMetaPath?: string;
|
|
19
|
+
}): string;
|
|
20
|
+
|
|
21
|
+
export { convertPageMapToJs };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { toJs } from "estree-util-to-js";
|
|
2
|
+
import { MARKDOWN_EXTENSION_RE, METADATA_ONLY_RQ } from "../constants.js";
|
|
3
|
+
import { convertPageMapToAst } from "./to-ast.js";
|
|
4
|
+
const META_RE = /_meta\.[jt]sx?$/;
|
|
5
|
+
function convertPageMapToJs({
|
|
6
|
+
pageMap,
|
|
7
|
+
mdxPages,
|
|
8
|
+
globalMetaPath
|
|
9
|
+
}) {
|
|
10
|
+
const imports = [];
|
|
11
|
+
const pageMapAst = convertPageMapToAst(pageMap, imports);
|
|
12
|
+
const importsAst = imports.map(
|
|
13
|
+
({ filePath, importName }) => {
|
|
14
|
+
const isMdx = MARKDOWN_EXTENSION_RE.test(filePath);
|
|
15
|
+
const isMeta = META_RE.test(filePath);
|
|
16
|
+
return {
|
|
17
|
+
type: "ImportDeclaration",
|
|
18
|
+
source: {
|
|
19
|
+
type: "Literal",
|
|
20
|
+
// Add resource query only for `.md`, `.mdx` files
|
|
21
|
+
value: `private-next-root-dir/${filePath}${isMdx ? METADATA_ONLY_RQ : ""}`
|
|
22
|
+
},
|
|
23
|
+
specifiers: [
|
|
24
|
+
isMeta || isMdx ? {
|
|
25
|
+
local: { type: "Identifier", name: importName },
|
|
26
|
+
...isMeta ? { type: "ImportDefaultSpecifier" } : {
|
|
27
|
+
type: "ImportSpecifier",
|
|
28
|
+
imported: { type: "Identifier", name: "metadata" }
|
|
29
|
+
}
|
|
30
|
+
} : {
|
|
31
|
+
type: "ImportNamespaceSpecifier",
|
|
32
|
+
local: { type: "Identifier", name: importName }
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
const importsResult = toJs({
|
|
39
|
+
type: "Program",
|
|
40
|
+
sourceType: "module",
|
|
41
|
+
body: importsAst
|
|
42
|
+
});
|
|
43
|
+
const pageMapResult = toJs({
|
|
44
|
+
type: "Program",
|
|
45
|
+
sourceType: "module",
|
|
46
|
+
body: [{ type: "ExpressionStatement", expression: pageMapAst }]
|
|
47
|
+
});
|
|
48
|
+
let pageMapRawJs = pageMapResult.value.slice(
|
|
49
|
+
0,
|
|
50
|
+
-2
|
|
51
|
+
/* replace semicolon */
|
|
52
|
+
);
|
|
53
|
+
if (globalMetaPath) {
|
|
54
|
+
pageMapRawJs = `mergeMetaWithPageMap(${pageMapRawJs}, globalMeta, true)`;
|
|
55
|
+
}
|
|
56
|
+
const rawJs = `import { ${[
|
|
57
|
+
"normalizePageMap",
|
|
58
|
+
globalMetaPath && "mergeMetaWithPageMap",
|
|
59
|
+
imports.some(
|
|
60
|
+
(o) => !MARKDOWN_EXTENSION_RE.test(o.filePath) && !META_RE.test(o.filePath)
|
|
61
|
+
) && "getMetadata"
|
|
62
|
+
].filter(Boolean).join(", ")} } from 'nextra/page-map'
|
|
63
|
+
${globalMetaPath ? `import globalMeta from 'private-next-root-dir/${globalMetaPath}'` : ""}
|
|
64
|
+
${importsResult.value}
|
|
65
|
+
export const pageMap = normalizePageMap(${pageMapRawJs})
|
|
66
|
+
|
|
67
|
+
export const RouteToFilepath = ${JSON.stringify(mdxPages, null, 2)}`;
|
|
68
|
+
return rawJs;
|
|
69
|
+
}
|
|
70
|
+
export {
|
|
71
|
+
convertPageMapToJs
|
|
72
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TItem } 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
|
+
declare function convertToPageMap({ filePaths, basePath, locale }: {
|
|
16
|
+
filePaths: string[];
|
|
17
|
+
basePath?: string;
|
|
18
|
+
locale?: string;
|
|
19
|
+
}): {
|
|
20
|
+
pageMap: TItem[];
|
|
21
|
+
mdxPages: {
|
|
22
|
+
[k: string]: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { convertToPageMap };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { normalizeAppPath } from "next/dist/shared/lib/router/utils/app-paths.js";
|
|
3
|
+
function createNested(map, path2) {
|
|
4
|
+
let current = map;
|
|
5
|
+
for (const part of path2.split("/")) {
|
|
6
|
+
current[part] ||= {};
|
|
7
|
+
current = current[part];
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const APP_DIR_SUFFIX_RE = /^(src\/)?app\//;
|
|
11
|
+
function convertToPageMap({
|
|
12
|
+
filePaths,
|
|
13
|
+
basePath,
|
|
14
|
+
locale
|
|
15
|
+
}) {
|
|
16
|
+
const pages = {};
|
|
17
|
+
const metaFiles = {};
|
|
18
|
+
const nestedMap = {};
|
|
19
|
+
for (const filePath of filePaths) {
|
|
20
|
+
let { name, dir } = path.parse(filePath);
|
|
21
|
+
const inAppDir = APP_DIR_SUFFIX_RE.test(filePath);
|
|
22
|
+
if (inAppDir) {
|
|
23
|
+
dir = dir.replace(/^(src\/)?app(\/|$)/, "");
|
|
24
|
+
} else {
|
|
25
|
+
let filePath2 = dir.replace(/^(src\/)?content(\/|$)/, "");
|
|
26
|
+
if (locale) filePath2 = filePath2.replace(new RegExp(`^${locale}/?`), "");
|
|
27
|
+
dir = [basePath, filePath2].filter(Boolean).join("/");
|
|
28
|
+
}
|
|
29
|
+
if (name === "_meta") {
|
|
30
|
+
const key = dir ? `${dir}/${name}` : name;
|
|
31
|
+
metaFiles[key] = filePath;
|
|
32
|
+
} else if (name !== "_meta.global") {
|
|
33
|
+
const key = inAppDir ? (
|
|
34
|
+
// In Next.js we can organize routes without affecting the URL
|
|
35
|
+
// https://nextjs.org/docs/app/building-your-application/routing/route-groups#organize-routes-without-affecting-the-url-path
|
|
36
|
+
//
|
|
37
|
+
// E.g. we have the following filepath:
|
|
38
|
+
// app/posts/(with-comments)/aaron-swartz-a-programmable-web/()/page.mdx
|
|
39
|
+
//
|
|
40
|
+
// will be normalized to:
|
|
41
|
+
// app/posts/aaron-swartz-a-programmable-web/page.mdx
|
|
42
|
+
//
|
|
43
|
+
// The `normalizeAppPath` function ensures a leading slash is present, so we slice it off.
|
|
44
|
+
normalizeAppPath(dir).slice(1)
|
|
45
|
+
) : [dir, name !== "index" && name].filter(Boolean).join("/");
|
|
46
|
+
pages[key] = filePath;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
for (const path2 of Object.keys(metaFiles)) {
|
|
50
|
+
createNested(nestedMap, path2);
|
|
51
|
+
}
|
|
52
|
+
for (const path2 of Object.keys(pages)) {
|
|
53
|
+
createNested(nestedMap, path2 && `${path2}/`);
|
|
54
|
+
}
|
|
55
|
+
function fillPageMap(obj, prefix) {
|
|
56
|
+
return Object.entries(obj).map(([key, value]) => {
|
|
57
|
+
const path2 = prefix && key ? `${prefix}/${key}` : prefix || key;
|
|
58
|
+
if (key === "_meta") {
|
|
59
|
+
const __metaPath = metaFiles[path2];
|
|
60
|
+
if (!__metaPath) {
|
|
61
|
+
const o = JSON.stringify({ path: path2, metaFiles }, null, 2);
|
|
62
|
+
throw new Error(`Can't find "_meta" file for:
|
|
63
|
+
${o}`);
|
|
64
|
+
}
|
|
65
|
+
return { __metaPath };
|
|
66
|
+
}
|
|
67
|
+
const item = {
|
|
68
|
+
name: key || "index",
|
|
69
|
+
route: `/${path2}`
|
|
70
|
+
};
|
|
71
|
+
const keys = Object.keys(value);
|
|
72
|
+
const isFolder = keys.length > 1 || keys.length === 1 && keys[0] !== "";
|
|
73
|
+
if (isFolder) {
|
|
74
|
+
return { ...item, children: fillPageMap(value, path2) };
|
|
75
|
+
}
|
|
76
|
+
const __pagePath = pages[path2];
|
|
77
|
+
if (!__pagePath) {
|
|
78
|
+
const o = JSON.stringify({ path: path2, mdxPages: pages }, null, 2);
|
|
79
|
+
throw new Error(`Can't find "page" file for:
|
|
80
|
+
${o}`);
|
|
81
|
+
}
|
|
82
|
+
return { ...item, __pagePath };
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const pageMap = fillPageMap(nestedMap);
|
|
86
|
+
const mdxPages = Object.fromEntries(
|
|
87
|
+
Object.entries(pages).flatMap(([key, value]) => {
|
|
88
|
+
if (basePath) key = key.replace(new RegExp(`^${basePath}/?`), "");
|
|
89
|
+
value = value.replace(/^(src\/)?content\//, "");
|
|
90
|
+
if (locale) value = value.replace(new RegExp(`^${locale}/`), "");
|
|
91
|
+
if (APP_DIR_SUFFIX_RE.test(value)) {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
return [[key, value]];
|
|
95
|
+
})
|
|
96
|
+
);
|
|
97
|
+
return { pageMap, mdxPages };
|
|
98
|
+
}
|
|
99
|
+
export {
|
|
100
|
+
convertToPageMap
|
|
101
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { DEFAULT_PROPERTY_PROPS } from "../constants.js";
|
|
2
|
+
var Mdx = /* @__PURE__ */ ((Mdx2) => {
|
|
3
|
+
Mdx2["Wrapper"] = "MDXContent";
|
|
4
|
+
Mdx2["Content"] = "_createMdxContent";
|
|
5
|
+
return Mdx2;
|
|
6
|
+
})(Mdx || {});
|
|
7
|
+
const recmaRewrite = ({ isPageImport, isRemoteContent }) => (ast) => {
|
|
8
|
+
const hasMdxLayout = ast.body.some(
|
|
9
|
+
(node) => node.type === "VariableDeclaration" && node.kind === "const" && node.declarations[0].id.type === "Identifier" && node.declarations[0].id.name === "MDXLayout"
|
|
10
|
+
);
|
|
11
|
+
if (isRemoteContent) {
|
|
12
|
+
if (hasMdxLayout) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
ast.body = ast.body.filter(
|
|
16
|
+
(node) => node.type !== "FunctionDeclaration" || node.id.name !== "MDXContent" /* Wrapper */
|
|
17
|
+
);
|
|
18
|
+
const returnStatement = ast.body.find(
|
|
19
|
+
(node) => node.type === "ReturnStatement"
|
|
20
|
+
);
|
|
21
|
+
const { properties } = returnStatement.argument;
|
|
22
|
+
for (const node of properties) {
|
|
23
|
+
if (node.type === "Property" && node.key.type === "Identifier" && node.key.name === "default" && node.value.type === "Identifier" && node.value.name === "MDXContent" /* Wrapper */) {
|
|
24
|
+
node.value.name = "_createMdxContent" /* Content */;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const defaultExport = ast.body.find(
|
|
31
|
+
(node) => node.type === "ExportDefaultDeclaration"
|
|
32
|
+
);
|
|
33
|
+
if (hasMdxLayout) {
|
|
34
|
+
Object.assign(defaultExport, defaultExport.declaration);
|
|
35
|
+
ast.body.unshift(HOC_IMPORT_AST);
|
|
36
|
+
ast.body.push({
|
|
37
|
+
type: "ExportDefaultDeclaration",
|
|
38
|
+
declaration: createHocCallAst("MDXContent" /* Wrapper */)
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (isPageImport) {
|
|
43
|
+
ast.body.unshift(HOC_IMPORT_AST);
|
|
44
|
+
defaultExport.declaration = createHocCallAst("_createMdxContent" /* Content */);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
defaultExport.declaration = {
|
|
48
|
+
type: "Identifier",
|
|
49
|
+
name: "_createMdxContent" /* Content */
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
const HOC_IMPORT_AST = {
|
|
53
|
+
type: "ImportDeclaration",
|
|
54
|
+
source: { type: "Literal", value: "nextra/setup-page" },
|
|
55
|
+
specifiers: [
|
|
56
|
+
{
|
|
57
|
+
type: "ImportSpecifier",
|
|
58
|
+
imported: { type: "Identifier", name: "HOC_MDXWrapper" },
|
|
59
|
+
local: { type: "Identifier", name: "HOC_MDXWrapper" }
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
};
|
|
63
|
+
function createHocCallAst(componentName) {
|
|
64
|
+
return {
|
|
65
|
+
type: "CallExpression",
|
|
66
|
+
callee: { type: "Identifier", name: "HOC_MDXWrapper" },
|
|
67
|
+
optional: false,
|
|
68
|
+
arguments: [
|
|
69
|
+
{ type: "Identifier", name: componentName },
|
|
70
|
+
{
|
|
71
|
+
type: "ObjectExpression",
|
|
72
|
+
properties: [
|
|
73
|
+
{
|
|
74
|
+
...DEFAULT_PROPERTY_PROPS,
|
|
75
|
+
shorthand: true,
|
|
76
|
+
key: { type: "Identifier", name: "metadata" },
|
|
77
|
+
value: { type: "Identifier", name: "metadata" }
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
...DEFAULT_PROPERTY_PROPS,
|
|
81
|
+
shorthand: true,
|
|
82
|
+
key: { type: "Identifier", name: "toc" },
|
|
83
|
+
value: { type: "Identifier", name: "toc" }
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
...DEFAULT_PROPERTY_PROPS,
|
|
87
|
+
shorthand: true,
|
|
88
|
+
key: { type: "Identifier", name: "sourceCode" },
|
|
89
|
+
value: { type: "Identifier", name: "sourceCode" }
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
export {
|
|
97
|
+
recmaRewrite
|
|
98
|
+
};
|