fumadocs-core 14.1.0 → 14.1.1

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.
@@ -0,0 +1,33 @@
1
+ // src/utils/path.ts
2
+ function splitPath(path) {
3
+ return path.split("/").filter((p) => p.length > 0);
4
+ }
5
+ function resolvePath(from, join) {
6
+ const v1 = splitPath(from), v2 = splitPath(join);
7
+ while (v2.length > 0) {
8
+ switch (v2[0]) {
9
+ case "..":
10
+ v1.pop();
11
+ break;
12
+ case ".":
13
+ break;
14
+ default:
15
+ v1.push(v2[0]);
16
+ }
17
+ v2.shift();
18
+ }
19
+ return v1.join("/");
20
+ }
21
+ function slash(path) {
22
+ const isExtendedLengthPath = path.startsWith("\\\\?\\");
23
+ if (isExtendedLengthPath) {
24
+ return path;
25
+ }
26
+ return path.replaceAll("\\", "/");
27
+ }
28
+
29
+ export {
30
+ splitPath,
31
+ resolvePath,
32
+ slash
33
+ };
@@ -52,7 +52,7 @@ declare function transformerTab(): ShikiTransformer;
52
52
 
53
53
  interface RemarkImageOptions {
54
54
  /**
55
- * Directory to resolve absolute image paths
55
+ * Directory or base URL to resolve absolute image paths
56
56
  */
57
57
  publicDir?: string;
58
58
  /**
@@ -2,13 +2,14 @@ import {
2
2
  flattenNode,
3
3
  remarkHeading
4
4
  } from "../chunk-4MNUWZIW.js";
5
+ import {
6
+ resolvePath,
7
+ slash
8
+ } from "../chunk-SHGL6VBO.js";
5
9
  import {
6
10
  createStyleTransformer,
7
11
  defaultThemes
8
12
  } from "../chunk-7CSWJQ5H.js";
9
- import {
10
- slash
11
- } from "../chunk-UWEEHUJV.js";
12
13
  import "../chunk-MLKGABMK.js";
13
14
 
14
15
  // src/mdx-plugins/index.ts
@@ -550,57 +551,58 @@ function remarkImage({
550
551
  const promises = [];
551
552
  function getImportPath(src) {
552
553
  if (!src.startsWith("/")) return src;
553
- if (file.path) {
554
- const relative = path.relative(
555
- path.dirname(file.path),
556
- path.join(publicDir, src)
557
- );
554
+ const to = path.join(publicDir, src);
555
+ if (file.dirname) {
556
+ const relative = slash(path.relative(file.dirname, to));
558
557
  return relative.startsWith("./") ? relative : `./${relative}`;
559
558
  }
560
- return path.join(publicDir, src);
559
+ return slash(to);
561
560
  }
562
561
  visit(tree, "image", (node) => {
563
- const src = decodeURI(node.url);
564
- if (!src) return;
565
- const isExternal = EXTERNAL_URL_REGEX.test(src);
562
+ const url = decodeURI(node.url);
563
+ if (!url) return;
564
+ const isExternal = EXTERNAL_URL_REGEX.test(url);
566
565
  if (isExternal && external || !useImport) {
567
- promises.push(
568
- getImageSize(src, publicDir).then((size) => {
569
- if (!size.width || !size.height) return;
570
- Object.assign(node, {
571
- type: "mdxJsxFlowElement",
572
- name: "img",
573
- attributes: [
574
- {
575
- type: "mdxJsxAttribute",
576
- name: "alt",
577
- value: node.alt ?? "image"
578
- },
579
- {
580
- type: "mdxJsxAttribute",
581
- name: "src",
582
- value: src
583
- },
584
- {
585
- type: "mdxJsxAttribute",
586
- name: "width",
587
- value: size.width.toString()
588
- },
589
- {
590
- type: "mdxJsxAttribute",
591
- name: "height",
592
- value: size.height.toString()
593
- }
594
- ]
595
- });
596
- })
597
- );
566
+ const task = getImageSize(url, publicDir).then((size) => {
567
+ if (!size.width || !size.height) return;
568
+ Object.assign(node, {
569
+ type: "mdxJsxFlowElement",
570
+ name: "img",
571
+ attributes: [
572
+ {
573
+ type: "mdxJsxAttribute",
574
+ name: "alt",
575
+ value: node.alt ?? "image"
576
+ },
577
+ {
578
+ type: "mdxJsxAttribute",
579
+ name: "src",
580
+ value: url
581
+ },
582
+ {
583
+ type: "mdxJsxAttribute",
584
+ name: "width",
585
+ value: size.width.toString()
586
+ },
587
+ {
588
+ type: "mdxJsxAttribute",
589
+ name: "height",
590
+ value: size.height.toString()
591
+ }
592
+ ]
593
+ });
594
+ }).catch(() => {
595
+ console.error(
596
+ `[Remark Image] Failed obtain image size for ${url} with public directory ${publicDir}`
597
+ );
598
+ });
599
+ promises.push(task);
598
600
  } else if (!isExternal) {
599
601
  const variableName = `__img${importsToInject.length.toString()}`;
600
- const hasBlur = placeholder === "blur" && VALID_BLUR_EXT.some((ext) => src.endsWith(ext));
602
+ const hasBlur = placeholder === "blur" && VALID_BLUR_EXT.some((ext) => url.endsWith(ext));
601
603
  importsToInject.push({
602
604
  variableName,
603
- importPath: slash(getImportPath(src))
605
+ importPath: getImportPath(url)
604
606
  });
605
607
  Object.assign(node, {
606
608
  type: "mdxJsxFlowElement",
@@ -665,17 +667,20 @@ function remarkImage({
665
667
  }
666
668
  };
667
669
  }
668
- function resolveSrc(src, dir) {
669
- return src.startsWith("/") || !path.isAbsolute(src) ? path.join(dir, src) : src;
670
- }
671
670
  async function getImageSize(src, dir) {
671
+ const isRelative = src.startsWith("/") || !path.isAbsolute(src);
672
+ let url;
672
673
  if (EXTERNAL_URL_REGEX.test(src)) {
673
- const res = await fetch(src);
674
- return sizeOf(
675
- await res.arrayBuffer().then((buffer) => new Uint8Array(buffer))
676
- );
674
+ url = src;
675
+ } else if (EXTERNAL_URL_REGEX.test(dir) && isRelative) {
676
+ const base = new URL(dir);
677
+ base.pathname = resolvePath(base.pathname, src);
678
+ url = base.toString();
679
+ } else {
680
+ return sizeOf(isRelative ? path.join(dir, src) : src);
677
681
  }
678
- return sizeOf(resolveSrc(src, dir));
682
+ const buffer = await fetch(url).then((res) => res.arrayBuffer());
683
+ return sizeOf(new Uint8Array(buffer));
679
684
  }
680
685
 
681
686
  // src/mdx-plugins/remark-structure.ts
@@ -2,75 +2,14 @@ import {
2
2
  removeUndefined
3
3
  } from "../chunk-2V6SCS43.js";
4
4
  import {
5
- slash
6
- } from "../chunk-UWEEHUJV.js";
5
+ resolvePath,
6
+ slash,
7
+ splitPath
8
+ } from "../chunk-SHGL6VBO.js";
7
9
  import {
8
10
  __export
9
11
  } from "../chunk-MLKGABMK.js";
10
12
 
11
- // src/source/path.ts
12
- function parseFilePath(path) {
13
- const segments = splitPath(slash(path));
14
- const dirname = segments.slice(0, -1).join("/");
15
- const base = segments.at(-1) ?? "";
16
- const dotIdx = base.lastIndexOf(".");
17
- const nameWithLocale = dotIdx !== -1 ? base.slice(0, dotIdx) : base;
18
- const flattenedPath = [dirname, nameWithLocale].filter((p) => p.length > 0).join("/");
19
- const [name, locale] = getLocale(nameWithLocale);
20
- return {
21
- dirname,
22
- name,
23
- flattenedPath,
24
- locale,
25
- path: segments.join("/")
26
- };
27
- }
28
- function parseFolderPath(path) {
29
- const segments = splitPath(slash(path));
30
- const base = segments.at(-1) ?? "";
31
- const [name, locale] = getLocale(base);
32
- const flattenedPath = segments.join("/");
33
- return {
34
- dirname: segments.slice(0, -1).join("/"),
35
- name,
36
- flattenedPath,
37
- locale,
38
- path: flattenedPath
39
- };
40
- }
41
- function getLocale(name) {
42
- const sep = name.lastIndexOf(".");
43
- if (sep === -1) return [name];
44
- const locale = name.slice(sep + 1);
45
- if (/\d+/.exec(locale)) return [name];
46
- return [name.slice(0, sep), locale];
47
- }
48
- function normalizePath(path) {
49
- const segments = splitPath(slash(path));
50
- if (segments[0] === "." || segments[0] === "..")
51
- throw new Error("It must not start with './' or '../'");
52
- return segments.join("/");
53
- }
54
- function splitPath(path) {
55
- return path.split("/").filter((p) => p.length > 0);
56
- }
57
- function resolvePath(from, join) {
58
- const v1 = splitPath(from), v2 = splitPath(join);
59
- while (v2.length > 0) {
60
- switch (v2[0]) {
61
- case "..":
62
- v1.pop();
63
- break;
64
- case ".":
65
- break;
66
- default:
67
- v1.push(v2[0]);
68
- }
69
- v2.shift();
70
- }
71
- return v1.join("/");
72
- }
73
-
74
13
  // src/source/page-tree-builder.ts
75
14
  var group = /^\((?<name>.+)\)$/;
76
15
  var link = /^(?:\[(?<icon>[^\]]+)])?\[(?<name>[^\]]+)]\((?<url>[^)]+)\)$/;
@@ -249,6 +188,50 @@ function pathToName(name, resolveGroup = false) {
249
188
  return result.join("");
250
189
  }
251
190
 
191
+ // src/source/path.ts
192
+ function parseFilePath(path) {
193
+ const segments = splitPath(slash(path));
194
+ const dirname = segments.slice(0, -1).join("/");
195
+ const base = segments.at(-1) ?? "";
196
+ const dotIdx = base.lastIndexOf(".");
197
+ const nameWithLocale = dotIdx !== -1 ? base.slice(0, dotIdx) : base;
198
+ const flattenedPath = [dirname, nameWithLocale].filter((p) => p.length > 0).join("/");
199
+ const [name, locale] = getLocale(nameWithLocale);
200
+ return {
201
+ dirname,
202
+ name,
203
+ flattenedPath,
204
+ locale,
205
+ path: segments.join("/")
206
+ };
207
+ }
208
+ function parseFolderPath(path) {
209
+ const segments = splitPath(slash(path));
210
+ const base = segments.at(-1) ?? "";
211
+ const [name, locale] = getLocale(base);
212
+ const flattenedPath = segments.join("/");
213
+ return {
214
+ dirname: segments.slice(0, -1).join("/"),
215
+ name,
216
+ flattenedPath,
217
+ locale,
218
+ path: flattenedPath
219
+ };
220
+ }
221
+ function getLocale(name) {
222
+ const sep = name.lastIndexOf(".");
223
+ if (sep === -1) return [name];
224
+ const locale = name.slice(sep + 1);
225
+ if (/\d+/.exec(locale)) return [name];
226
+ return [name.slice(0, sep), locale];
227
+ }
228
+ function normalizePath(path) {
229
+ const segments = splitPath(slash(path));
230
+ if (segments[0] === "." || segments[0] === "..")
231
+ throw new Error("It must not start with './' or '../'");
232
+ return segments.join("/");
233
+ }
234
+
252
235
  // src/source/file-system.ts
253
236
  var file_system_exports = {};
254
237
  __export(file_system_exports, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "14.1.0",
3
+ "version": "14.1.1",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -102,8 +102,8 @@
102
102
  "remark-rehype": "^11.1.1",
103
103
  "shiki-transformers": "^1.0.0",
104
104
  "unified": "^11.0.5",
105
- "tsconfig": "0.0.0",
106
- "eslint-config-custom": "0.0.0"
105
+ "eslint-config-custom": "0.0.0",
106
+ "tsconfig": "0.0.0"
107
107
  },
108
108
  "peerDependencies": {
109
109
  "algoliasearch": "4.24.0",
@@ -1,12 +0,0 @@
1
- // src/utils/slash.ts
2
- function slash(path) {
3
- const isExtendedLengthPath = path.startsWith("\\\\?\\");
4
- if (isExtendedLengthPath) {
5
- return path;
6
- }
7
- return path.replaceAll("\\", "/");
8
- }
9
-
10
- export {
11
- slash
12
- };