fumadocs-core 11.1.0 → 11.1.2

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.
@@ -4,7 +4,7 @@ import { RehypeShikiOptions } from '@shikijs/rehype';
4
4
  import { Processor, Transformer } from 'unified';
5
5
  import { ShikiTransformer } from 'shiki';
6
6
  import { Root as Root$1, Heading } from 'mdast';
7
- export { S as StructuredData, r as remarkStructure, s as structure } from '../remark-structure-RwYPDA6M.js';
7
+ export { a as StructureOptions, S as StructuredData, r as remarkStructure, s as structure } from '../remark-structure-Os9Vuaua.js';
8
8
 
9
9
  interface CodeBlockIcon {
10
10
  viewBox: string;
@@ -12,11 +12,11 @@ interface Content {
12
12
  interface StructuredData {
13
13
  headings: Heading[];
14
14
  /**
15
- * Refer to paragraphs, a heading may contains multiple contents as well
15
+ * Refer to paragraphs, a heading may contain multiple contents as well
16
16
  */
17
17
  contents: Content[];
18
18
  }
19
- interface Options {
19
+ interface StructureOptions {
20
20
  /**
21
21
  * Types to be scanned, default: `["heading", "blockquote", "paragraph"]`
22
22
  */
@@ -25,10 +25,10 @@ interface Options {
25
25
  /**
26
26
  * Attach structured data to VFile, you can access via `vfile.data.structuredData`.
27
27
  */
28
- declare function remarkStructure({ types, }?: Options): Transformer<Root, Root>;
28
+ declare function remarkStructure({ types, }?: StructureOptions): Transformer<Root, Root>;
29
29
  /**
30
30
  * Extract data from markdown/mdx content
31
31
  */
32
- declare function structure(content: string, remarkPlugins?: PluggableList, options?: Options): StructuredData;
32
+ declare function structure(content: string, remarkPlugins?: PluggableList, options?: StructureOptions): StructuredData;
33
33
 
34
- export { type StructuredData as S, remarkStructure as r, structure as s };
34
+ export { type StructuredData as S, type StructureOptions as a, remarkStructure as r, structure as s };
@@ -1,5 +1,5 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
- import { S as StructuredData } from '../remark-structure-RwYPDA6M.js';
2
+ import { S as StructuredData } from '../remark-structure-Os9Vuaua.js';
3
3
  import { SortedResult } from './shared.js';
4
4
  import 'mdast';
5
5
  import 'unified';
@@ -4,7 +4,7 @@ import { SWRResponse } from 'swr';
4
4
  import { SortedResult } from '../search/shared.js';
5
5
  import { BaseIndex } from './server.js';
6
6
  import 'algoliasearch';
7
- import '../remark-structure-RwYPDA6M.js';
7
+ import '../remark-structure-Os9Vuaua.js';
8
8
  import 'mdast';
9
9
  import 'unified';
10
10
 
@@ -1,5 +1,5 @@
1
1
  import { SearchClient, SearchIndex } from 'algoliasearch';
2
- import { S as StructuredData } from '../remark-structure-RwYPDA6M.js';
2
+ import { S as StructuredData } from '../remark-structure-Os9Vuaua.js';
3
3
  import 'mdast';
4
4
  import 'unified';
5
5
 
@@ -64,7 +64,7 @@ interface BuildPageTreeOptionsWithI18n {
64
64
  interface PageTreeBuilder {
65
65
  build: () => Root;
66
66
  /**
67
- * Build page tree and fallback to the default language if the page doesn't exist
67
+ * Build page tree and fallback to the default language if the localized page doesn't exist
68
68
  */
69
69
  buildI18n: (options?: Partial<BuildPageTreeOptionsWithI18n>) => Record<string, Root>;
70
70
  }
@@ -10,7 +10,7 @@ import { parse } from "path";
10
10
  function parseFilePath(path) {
11
11
  const normalized = normalizePath(path);
12
12
  const parsed = parse(normalized);
13
- const flattenedPath = joinPaths([parsed.dir, parsed.name]);
13
+ const flattenedPath = [parsed.dir, parsed.name].filter((p) => p.length > 0).join("/");
14
14
  const [name, locale] = parsed.name.split(".");
15
15
  return {
16
16
  dirname: parsed.dir,
@@ -36,13 +36,26 @@ function normalizePath(path) {
36
36
  const segments = splitPath(slash(path));
37
37
  if (segments[0] === "." || segments[0] === "..")
38
38
  throw new Error("It must not start with './' or '../'");
39
- return joinPaths(segments);
39
+ return segments.join("/");
40
40
  }
41
41
  function splitPath(path) {
42
42
  return path.split("/").filter((p) => p.length > 0);
43
43
  }
44
- function joinPaths(paths, slashMode = "none") {
45
- const joined = paths.flatMap((path) => splitPath(path)).join("/");
44
+ function resolvePath(from, join, slashMode = "none") {
45
+ const v1 = splitPath(from), v2 = splitPath(join);
46
+ while (v2.length > 0) {
47
+ switch (v2[0]) {
48
+ case "..":
49
+ v1.pop();
50
+ break;
51
+ case ".":
52
+ break;
53
+ default:
54
+ v1.push(v2[0]);
55
+ }
56
+ v2.shift();
57
+ }
58
+ const joined = v1.join("/");
46
59
  switch (slashMode) {
47
60
  case "leading":
48
61
  return `/${joined}`;
@@ -54,10 +67,10 @@ function joinPaths(paths, slashMode = "none") {
54
67
  }
55
68
 
56
69
  // src/source/page-tree-builder.ts
57
- var external = new RegExp("\\[(?<text>.+)\\]\\((?<url>.+)\\)");
58
- var separator = new RegExp("---(?<name>.*?)---");
70
+ var link = new RegExp("^\\[(?<text>.+)]\\((?<url>.+)\\)$");
71
+ var separator = new RegExp("^---(?<name>.*?)---$");
59
72
  var rest = "...";
60
- var extractor = new RegExp("\\.\\.\\.(?<name>.+)");
73
+ var extractor = new RegExp("^\\.\\.\\.(?<name>.+)$");
61
74
  function buildAll(nodes, ctx, skipIndex) {
62
75
  const output = [];
63
76
  for (const node of [...nodes].sort(
@@ -91,22 +104,24 @@ function resolveFolderItem(folder, item, ctx, addedNodePaths) {
91
104
  }
92
105
  ];
93
106
  }
94
- const externalResult = external.exec(item);
95
- if (externalResult == null ? void 0 : externalResult.groups) {
107
+ const linkResult = link.exec(item);
108
+ if (linkResult == null ? void 0 : linkResult.groups) {
109
+ const { url, text } = linkResult.groups;
110
+ const isRelative = url.startsWith("/") || url.startsWith("#") || url.startsWith(".");
96
111
  return [
97
112
  {
98
113
  type: "page",
99
- name: externalResult.groups.text,
100
- url: externalResult.groups.url,
101
- external: true
114
+ name: text,
115
+ url,
116
+ external: !isRelative
102
117
  }
103
118
  ];
104
119
  }
105
120
  const extractResult = extractor.exec(item);
106
- const path = joinPaths([
121
+ const path = resolvePath(
107
122
  folder.file.path,
108
123
  (_b = (_a = extractResult == null ? void 0 : extractResult.groups) == null ? void 0 : _a.name) != null ? _b : item
109
- ]);
124
+ );
110
125
  const itemNode = (_c = ctx.storage.readDir(path)) != null ? _c : ctx.storage.read(path, "page");
111
126
  if (!itemNode)
112
127
  return [];
@@ -119,11 +134,11 @@ function resolveFolderItem(folder, item, ctx, addedNodePaths) {
119
134
  }
120
135
  function buildFolderNode(folder, defaultIsRoot, ctx) {
121
136
  var _a, _b, _c, _d, _e;
122
- const metaPath = joinPaths([folder.file.path, "meta"]);
137
+ const metaPath = resolvePath(folder.file.path, "meta");
123
138
  let meta = ctx.storage.read(metaPath, "meta");
124
139
  meta = (_a = findLocalizedFile(metaPath, "meta", ctx)) != null ? _a : meta;
125
140
  const indexFile = ctx.storage.read(
126
- joinPaths([folder.file.flattenedPath, "index"]),
141
+ resolvePath(folder.file.flattenedPath, "index"),
127
142
  "page"
128
143
  );
129
144
  const metadata = meta == null ? void 0 : meta.data.data;
@@ -344,10 +359,8 @@ function buildPageMap(storage, languages) {
344
359
  }
345
360
  function createGetUrl(baseUrl) {
346
361
  return (slugs, locale) => {
347
- let paths = [baseUrl, ...slugs];
348
- if (locale)
349
- paths = [baseUrl, locale, ...slugs];
350
- return joinPaths(paths, "leading");
362
+ const paths = locale ? [...splitPath(baseUrl), locale, ...slugs] : [...splitPath(baseUrl), ...slugs];
363
+ return `/${paths.join("/")}`;
351
364
  };
352
365
  }
353
366
  function getSlugs(info) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "11.1.0",
3
+ "version": "11.1.2",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -113,19 +113,19 @@
113
113
  ],
114
114
  "dependencies": {
115
115
  "@formatjs/intl-localematcher": "^0.5.4",
116
- "@shikijs/rehype": "^1.3.0",
117
- "@shikijs/transformers": "^1.3.0",
116
+ "@shikijs/rehype": "^1.6.0",
117
+ "@shikijs/transformers": "^1.6.0",
118
118
  "flexsearch": "0.7.21",
119
119
  "github-slugger": "^2.0.0",
120
120
  "hast-util-to-estree": "^3.1.0",
121
121
  "negotiator": "^0.6.3",
122
122
  "npm-to-yarn": "^2.2.1",
123
- "react-remove-scroll": "^2.5.9",
123
+ "react-remove-scroll": "^2.5.10",
124
124
  "remark": "^15.0.0",
125
125
  "remark-gfm": "^4.0.0",
126
126
  "remark-mdx": "^3.0.1",
127
127
  "scroll-into-view-if-needed": "^3.1.0",
128
- "shiki": "^1.3.0",
128
+ "shiki": "^1.6.0",
129
129
  "swr": "^2.2.5",
130
130
  "unist-util-visit": "^5.0.0"
131
131
  },
@@ -138,7 +138,7 @@
138
138
  "@types/mdast": "^4.0.3",
139
139
  "@types/negotiator": "^0.6.3",
140
140
  "@types/node": "18.17.5",
141
- "@types/react": "^18.3.1",
141
+ "@types/react": "^18.3.2",
142
142
  "@types/react-dom": "^18.3.0",
143
143
  "algoliasearch": "^4.23.3",
144
144
  "next": "^14.2.3",