@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.
Files changed (293) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +56 -0
  3. package/changes.json +110 -0
  4. package/dist/client/components/banner/close-banner-button.d.ts +8 -0
  5. package/dist/client/components/banner/close-banner-button.js +45 -0
  6. package/dist/client/components/banner/index.client.d.ts +5 -0
  7. package/dist/client/components/banner/index.client.js +46 -0
  8. package/dist/client/components/banner/index.d.ts +51 -0
  9. package/dist/client/components/banner/index.js +93 -0
  10. package/dist/client/components/bleed.d.ts +63 -0
  11. package/dist/client/components/bleed.js +54 -0
  12. package/dist/client/components/button.d.ts +9 -0
  13. package/dist/client/components/button.js +55 -0
  14. package/dist/client/components/callout.d.ts +136 -0
  15. package/dist/client/components/callout.js +99 -0
  16. package/dist/client/components/cards.d.ts +104 -0
  17. package/dist/client/components/cards.js +132 -0
  18. package/dist/client/components/collapse.d.ts +12 -0
  19. package/dist/client/components/collapse.js +143 -0
  20. package/dist/client/components/file-tree/file.d.ts +9 -0
  21. package/dist/client/components/file-tree/file.js +43 -0
  22. package/dist/client/components/file-tree/folder.d.ts +12 -0
  23. package/dist/client/components/file-tree/folder.js +94 -0
  24. package/dist/client/components/file-tree/index.d.ts +57 -0
  25. package/dist/client/components/file-tree/index.js +12 -0
  26. package/dist/client/components/file-tree/tree.d.ts +5 -0
  27. package/dist/client/components/file-tree/tree.js +41 -0
  28. package/dist/client/components/head.d.ts +139 -0
  29. package/dist/client/components/head.js +202 -0
  30. package/dist/client/components/image-zoom.d.ts +6 -0
  31. package/dist/client/components/image-zoom.js +79 -0
  32. package/dist/client/components/index.d.ts +56 -0
  33. package/dist/client/components/index.js +42 -0
  34. package/dist/client/components/playground.d.ts +90 -0
  35. package/dist/client/components/playground.js +103 -0
  36. package/dist/client/components/popup/index.client.d.ts +7 -0
  37. package/dist/client/components/popup/index.client.js +83 -0
  38. package/dist/client/components/popup/index.d.ts +12 -0
  39. package/dist/client/components/popup/index.js +11 -0
  40. package/dist/client/components/search.d.ts +88 -0
  41. package/dist/client/components/search.js +426 -0
  42. package/dist/client/components/select.d.ts +19 -0
  43. package/dist/client/components/select.js +109 -0
  44. package/dist/client/components/skip-nav/index.client.d.ts +5 -0
  45. package/dist/client/components/skip-nav/index.client.js +45 -0
  46. package/dist/client/components/skip-nav/index.d.ts +6 -0
  47. package/dist/client/components/skip-nav/index.js +24 -0
  48. package/dist/client/components/steps.d.ts +64 -0
  49. package/dist/client/components/steps.js +74 -0
  50. package/dist/client/components/tabs/index.client.d.ts +21 -0
  51. package/dist/client/components/tabs/index.client.js +243 -0
  52. package/dist/client/components/tabs/index.d.ts +53 -0
  53. package/dist/client/components/tabs/index.js +9 -0
  54. package/dist/client/evaluate.d.ts +30 -0
  55. package/dist/client/evaluate.js +17 -0
  56. package/dist/client/hocs/index.d.ts +4 -0
  57. package/dist/client/hocs/index.js +6 -0
  58. package/dist/client/hocs/with-github-alert.d.ts +11 -0
  59. package/dist/client/hocs/with-github-alert.js +30 -0
  60. package/dist/client/hocs/with-icons.d.ts +6 -0
  61. package/dist/client/hocs/with-icons.js +76 -0
  62. package/dist/client/hooks/index.d.ts +4 -0
  63. package/dist/client/hooks/index.js +10 -0
  64. package/dist/client/hooks/use-copy.d.ts +9 -0
  65. package/dist/client/hooks/use-copy.js +77 -0
  66. package/dist/client/hooks/use-fs-route.d.ts +3 -0
  67. package/dist/client/hooks/use-fs-route.js +20 -0
  68. package/dist/client/hooks/use-hash.d.ts +3 -0
  69. package/dist/client/hooks/use-hash.js +20 -0
  70. package/dist/client/hooks/use-mounted.d.ts +3 -0
  71. package/dist/client/hooks/use-mounted.js +13 -0
  72. package/dist/client/icons/arrow-right.d.ts +5 -0
  73. package/dist/client/icons/arrow-right.js +24 -0
  74. package/dist/client/icons/chatgpt.d.ts +2 -0
  75. package/dist/client/icons/chatgpt.js +24 -0
  76. package/dist/client/icons/check.d.ts +2 -0
  77. package/dist/client/icons/check.js +24 -0
  78. package/dist/client/icons/claude.d.ts +2 -0
  79. package/dist/client/icons/claude.js +81 -0
  80. package/dist/client/icons/copy.d.ts +2 -0
  81. package/dist/client/icons/copy.js +31 -0
  82. package/dist/client/icons/cpp.d.ts +2 -0
  83. package/dist/client/icons/cpp.js +24 -0
  84. package/dist/client/icons/cross-circled.d.ts +2 -0
  85. package/dist/client/icons/cross-circled.js +24 -0
  86. package/dist/client/icons/csharp.d.ts +2 -0
  87. package/dist/client/icons/csharp.js +24 -0
  88. package/dist/client/icons/css.d.ts +2 -0
  89. package/dist/client/icons/css.js +24 -0
  90. package/dist/client/icons/discord.d.ts +2 -0
  91. package/dist/client/icons/discord.js +24 -0
  92. package/dist/client/icons/expand.d.ts +2 -0
  93. package/dist/client/icons/expand.js +31 -0
  94. package/dist/client/icons/file.d.ts +2 -0
  95. package/dist/client/icons/file.js +24 -0
  96. package/dist/client/icons/folder-open.d.ts +2 -0
  97. package/dist/client/icons/folder-open.js +24 -0
  98. package/dist/client/icons/folder.d.ts +2 -0
  99. package/dist/client/icons/folder.js +24 -0
  100. package/dist/client/icons/github-caution.d.ts +2 -0
  101. package/dist/client/icons/github-caution.js +24 -0
  102. package/dist/client/icons/github-important.d.ts +2 -0
  103. package/dist/client/icons/github-important.js +24 -0
  104. package/dist/client/icons/github-note.d.ts +2 -0
  105. package/dist/client/icons/github-note.js +24 -0
  106. package/dist/client/icons/github-tip.d.ts +2 -0
  107. package/dist/client/icons/github-tip.js +24 -0
  108. package/dist/client/icons/github-warning.d.ts +2 -0
  109. package/dist/client/icons/github-warning.js +24 -0
  110. package/dist/client/icons/github.d.ts +2 -0
  111. package/dist/client/icons/github.js +24 -0
  112. package/dist/client/icons/globe.d.ts +2 -0
  113. package/dist/client/icons/globe.js +24 -0
  114. package/dist/client/icons/go.d.ts +2 -0
  115. package/dist/client/icons/go.js +46 -0
  116. package/dist/client/icons/graphql.d.ts +2 -0
  117. package/dist/client/icons/graphql.js +56 -0
  118. package/dist/client/icons/index.d.ts +2 -0
  119. package/dist/client/icons/index.js +92 -0
  120. package/dist/client/icons/javascript.d.ts +2 -0
  121. package/dist/client/icons/javascript.js +24 -0
  122. package/dist/client/icons/json.d.ts +2 -0
  123. package/dist/client/icons/json.js +41 -0
  124. package/dist/client/icons/link-arrow.d.ts +2 -0
  125. package/dist/client/icons/link-arrow.js +31 -0
  126. package/dist/client/icons/link.d.ts +2 -0
  127. package/dist/client/icons/link.js +24 -0
  128. package/dist/client/icons/markdown.d.ts +2 -0
  129. package/dist/client/icons/markdown.js +24 -0
  130. package/dist/client/icons/mdx.d.ts +2 -0
  131. package/dist/client/icons/mdx.js +24 -0
  132. package/dist/client/icons/menu.d.ts +2 -0
  133. package/dist/client/icons/menu.js +36 -0
  134. package/dist/client/icons/moon.d.ts +2 -0
  135. package/dist/client/icons/moon.js +24 -0
  136. package/dist/client/icons/move.d.ts +2 -0
  137. package/dist/client/icons/move.js +24 -0
  138. package/dist/client/icons/python.d.ts +2 -0
  139. package/dist/client/icons/python.js +31 -0
  140. package/dist/client/icons/react.d.ts +2 -0
  141. package/dist/client/icons/react.js +38 -0
  142. package/dist/client/icons/rust.d.ts +2 -0
  143. package/dist/client/icons/rust.js +31 -0
  144. package/dist/client/icons/spinner.d.ts +2 -0
  145. package/dist/client/icons/spinner.js +31 -0
  146. package/dist/client/icons/sun.d.ts +2 -0
  147. package/dist/client/icons/sun.js +24 -0
  148. package/dist/client/icons/svelte.d.ts +2 -0
  149. package/dist/client/icons/svelte.js +31 -0
  150. package/dist/client/icons/terminal.d.ts +2 -0
  151. package/dist/client/icons/terminal.js +24 -0
  152. package/dist/client/icons/terraform.d.ts +2 -0
  153. package/dist/client/icons/terraform.js +24 -0
  154. package/dist/client/icons/typescript.d.ts +2 -0
  155. package/dist/client/icons/typescript.js +24 -0
  156. package/dist/client/icons/word-wrap.d.ts +2 -0
  157. package/dist/client/icons/word-wrap.js +24 -0
  158. package/dist/client/icons/x.d.ts +2 -0
  159. package/dist/client/icons/x.js +24 -0
  160. package/dist/client/mdx-components/anchor.d.ts +10 -0
  161. package/dist/client/mdx-components/anchor.js +109 -0
  162. package/dist/client/mdx-components/code.d.ts +7 -0
  163. package/dist/client/mdx-components/code.js +52 -0
  164. package/dist/client/mdx-components/details.d.ts +5 -0
  165. package/dist/client/mdx-components/details.js +166 -0
  166. package/dist/client/mdx-components/image.d.ts +28 -0
  167. package/dist/client/mdx-components/image.js +39 -0
  168. package/dist/client/mdx-components/index.d.ts +11 -0
  169. package/dist/client/mdx-components/index.js +16 -0
  170. package/dist/client/mdx-components/pre/copy-to-clipboard.d.ts +5 -0
  171. package/dist/client/mdx-components/pre/copy-to-clipboard.js +49 -0
  172. package/dist/client/mdx-components/pre/index.d.ts +16 -0
  173. package/dist/client/mdx-components/pre/index.js +156 -0
  174. package/dist/client/mdx-components/pre/toggle-word-wrap-button.d.ts +7 -0
  175. package/dist/client/mdx-components/pre/toggle-word-wrap-button.js +31 -0
  176. package/dist/client/mdx-components/summary.d.ts +5 -0
  177. package/dist/client/mdx-components/summary.js +80 -0
  178. package/dist/client/mdx-components/table.d.ts +57 -0
  179. package/dist/client/mdx-components/table.js +95 -0
  180. package/dist/client/mdx-components.d.ts +89 -0
  181. package/dist/client/mdx-components.js +15 -0
  182. package/dist/client/mdx-remote.d.ts +62 -0
  183. package/dist/client/mdx-remote.js +36 -0
  184. package/dist/client/normalize-pages.d.ts +84 -0
  185. package/dist/client/normalize-pages.js +232 -0
  186. package/dist/client/package.json +1 -0
  187. package/dist/client/pages.d.ts +131 -0
  188. package/dist/client/pages.js +39 -0
  189. package/dist/client/remove-links.d.ts +6 -0
  190. package/dist/client/remove-links.js +35 -0
  191. package/dist/client/setup-page.d.ts +18 -0
  192. package/dist/client/setup-page.js +14 -0
  193. package/dist/server/compile-metadata.d.ts +12 -0
  194. package/dist/server/compile-metadata.js +39 -0
  195. package/dist/server/compile.d.ts +39 -0
  196. package/dist/server/compile.js +158 -0
  197. package/dist/server/constants.d.ts +15 -0
  198. package/dist/server/constants.js +22 -0
  199. package/dist/server/fetch-filepaths-from-github.d.ts +10 -0
  200. package/dist/server/fetch-filepaths-from-github.js +36 -0
  201. package/dist/server/index.d.ts +39 -0
  202. package/dist/server/index.js +203 -0
  203. package/dist/server/loader.d.ts +18 -0
  204. package/dist/server/loader.js +155 -0
  205. package/dist/server/locales.d.ts +22 -0
  206. package/dist/server/locales.js +38 -0
  207. package/dist/server/page-map/find-meta-and-page-file-paths.d.ts +8 -0
  208. package/dist/server/page-map/find-meta-and-page-file-paths.js +32 -0
  209. package/dist/server/page-map/get.d.ts +50 -0
  210. package/dist/server/page-map/get.js +28 -0
  211. package/dist/server/page-map/index-page.d.ts +21 -0
  212. package/dist/server/page-map/index-page.js +57 -0
  213. package/dist/server/page-map/index.d.ts +26 -0
  214. package/dist/server/page-map/index.js +24 -0
  215. package/dist/server/page-map/merge-meta-with-page-map.d.ts +17 -0
  216. package/dist/server/page-map/merge-meta-with-page-map.js +74 -0
  217. package/dist/server/page-map/normalize.d.ts +17 -0
  218. package/dist/server/page-map/normalize.js +122 -0
  219. package/dist/server/page-map/placeholder.d.ts +2 -0
  220. package/dist/server/page-map/placeholder.js +0 -0
  221. package/dist/server/page-map/to-ast.d.ts +18 -0
  222. package/dist/server/page-map/to-ast.js +47 -0
  223. package/dist/server/page-map/to-js.d.ts +21 -0
  224. package/dist/server/page-map/to-js.js +72 -0
  225. package/dist/server/page-map/to-page-map.d.ts +26 -0
  226. package/dist/server/page-map/to-page-map.js +101 -0
  227. package/dist/server/recma-plugins/index.d.ts +3 -0
  228. package/dist/server/recma-plugins/index.js +4 -0
  229. package/dist/server/recma-plugins/recma-rewrite.d.ts +11 -0
  230. package/dist/server/recma-plugins/recma-rewrite.js +98 -0
  231. package/dist/server/rehype-plugins/index.d.ts +18 -0
  232. package/dist/server/rehype-plugins/index.js +16 -0
  233. package/dist/server/rehype-plugins/rehype-better-react-mathjax.d.ts +24 -0
  234. package/dist/server/rehype-plugins/rehype-better-react-mathjax.js +96 -0
  235. package/dist/server/rehype-plugins/rehype-extract-toc-content.d.ts +6 -0
  236. package/dist/server/rehype-plugins/rehype-extract-toc-content.js +119 -0
  237. package/dist/server/rehype-plugins/rehype-twoslash-popup.d.ts +6 -0
  238. package/dist/server/rehype-plugins/rehype-twoslash-popup.js +50 -0
  239. package/dist/server/rehype-plugins/rehype.d.ts +21 -0
  240. package/dist/server/rehype-plugins/rehype.js +84 -0
  241. package/dist/server/remark-plugins/index.d.ts +15 -0
  242. package/dist/server/remark-plugins/index.js +26 -0
  243. package/dist/server/remark-plugins/remark-assign-frontmatter.d.ts +10 -0
  244. package/dist/server/remark-plugins/remark-assign-frontmatter.js +24 -0
  245. package/dist/server/remark-plugins/remark-custom-heading-id.d.ts +9 -0
  246. package/dist/server/remark-plugins/remark-custom-heading-id.js +18 -0
  247. package/dist/server/remark-plugins/remark-export-only-metadata.d.ts +6 -0
  248. package/dist/server/remark-plugins/remark-export-only-metadata.js +18 -0
  249. package/dist/server/remark-plugins/remark-export-source-code.d.ts +6 -0
  250. package/dist/server/remark-plugins/remark-export-source-code.js +35 -0
  251. package/dist/server/remark-plugins/remark-headings.d.ts +12 -0
  252. package/dist/server/remark-plugins/remark-headings.js +133 -0
  253. package/dist/server/remark-plugins/remark-link-rewrite.d.ts +11 -0
  254. package/dist/server/remark-plugins/remark-link-rewrite.js +12 -0
  255. package/dist/server/remark-plugins/remark-mdx-disable-explicit-jsx.d.ts +10 -0
  256. package/dist/server/remark-plugins/remark-mdx-disable-explicit-jsx.js +10 -0
  257. package/dist/server/remark-plugins/remark-mdx-frontmatter.d.ts +6 -0
  258. package/dist/server/remark-plugins/remark-mdx-frontmatter.js +37 -0
  259. package/dist/server/remark-plugins/remark-mdx-title.d.ts +10 -0
  260. package/dist/server/remark-plugins/remark-mdx-title.js +53 -0
  261. package/dist/server/remark-plugins/remark-remove-imports.d.ts +6 -0
  262. package/dist/server/remark-plugins/remark-remove-imports.js +12 -0
  263. package/dist/server/remark-plugins/remark-static-image.d.ts +6 -0
  264. package/dist/server/remark-plugins/remark-static-image.js +107 -0
  265. package/dist/server/schemas.d.ts +352 -0
  266. package/dist/server/schemas.js +240 -0
  267. package/dist/server/tsdoc/base.d.ts +38 -0
  268. package/dist/server/tsdoc/base.js +284 -0
  269. package/dist/server/tsdoc/index.d.ts +6 -0
  270. package/dist/server/tsdoc/index.js +10 -0
  271. package/dist/server/tsdoc/tsdoc.d.ts +102 -0
  272. package/dist/server/tsdoc/tsdoc.js +262 -0
  273. package/dist/server/tsdoc/types.d.ts +64 -0
  274. package/dist/server/tsdoc/types.js +0 -0
  275. package/dist/server/tsdoc/zod-to-ts.d.ts +5 -0
  276. package/dist/server/tsdoc/zod-to-ts.js +107 -0
  277. package/dist/server/twoslash.d.ts +6 -0
  278. package/dist/server/twoslash.js +60 -0
  279. package/dist/server/utils.d.ts +12 -0
  280. package/dist/server/utils.js +45 -0
  281. package/dist/types.d.ts +128 -0
  282. package/dist/types.generated.d.ts +203 -0
  283. package/dist/types.generated.js +0 -0
  284. package/dist/types.js +0 -0
  285. package/loader.cjs +24 -0
  286. package/package.json +265 -0
  287. package/styles/cards.css +24 -0
  288. package/styles/code-block.css +266 -0
  289. package/styles/default.css +55 -0
  290. package/styles/react-medium-image-zoom.css +101 -0
  291. package/styles/scrollbar.css +14 -0
  292. package/styles/steps.css +22 -0
  293. 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,8 @@
1
+ declare function findMetaAndPageFilePaths({ dir, cwd, locale, contentDir }: {
2
+ dir: string;
3
+ cwd: string;
4
+ locale?: string;
5
+ contentDir?: string;
6
+ }): Promise<string[]>;
7
+
8
+ export { findMetaAndPageFilePaths };
@@ -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 };