fumadocs-core 16.12.0 → 16.13.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.
@@ -1,4 +1,4 @@
1
- import { n as normalizeUrl } from "./url-CWbf4MFh.js";
1
+ import { r as normalizeUrl } from "./url-BVHvi3_K.js";
2
2
  import { r as findPath } from "./utils-Dn9VIXRN.js";
3
3
  import { useMemo } from "react";
4
4
  //#region src/breadcrumb.tsx
@@ -28,7 +28,7 @@ const framework = {
28
28
  Link({ href, prefetch = true, ...props }) {
29
29
  return /* @__PURE__ */ jsx(Link, {
30
30
  to: href,
31
- unstable_prefetchOnEnter: prefetch,
31
+ unstable_prefetchOnEnter: prefetch ? { mode: "once" } : void 0,
32
32
  ...props,
33
33
  children: props.children
34
34
  });
@@ -1,4 +1,4 @@
1
- import { t as getNegotiator } from "../negotiation-D7x4zl2m.js";
1
+ import { t as getNegotiator } from "../negotiation-Bdf_-s58.js";
2
2
  import { NextResponse } from "next/server.js";
3
3
  //#region ../../node_modules/.pnpm/@formatjs+fast-memoize@3.1.7/node_modules/@formatjs/fast-memoize/index.js
4
4
  function memoize(fn, options) {
@@ -1,4 +1,4 @@
1
- import { n as normalizeUrl } from "./url-CWbf4MFh.js";
1
+ import { r as normalizeUrl } from "./url-BVHvi3_K.js";
2
2
  import { c as visit } from "./utils-Dn9VIXRN.js";
3
3
  import { a as normalize, i as joinPath, n as dirname, r as extname, t as basename } from "./path-B9zu5SjE.js";
4
4
  import { slugsPlugin } from "./source/plugins/slugs.js";
@@ -695,7 +695,11 @@ function loader(...args) {
695
695
  const [value, hash] = href.split("#", 2);
696
696
  let target;
697
697
  if (value.startsWith("./") || value.startsWith("../")) {
698
- const path = joinPath(dir, value);
698
+ let decoded = value;
699
+ try {
700
+ decoded = decodeURI(value);
701
+ } catch {}
702
+ const path = joinPath(dir, decoded);
699
703
  target = indexer.getPage(path, language);
700
704
  } else target = this.getPages(language).find((item) => item.url === value);
701
705
  if (target) return {
@@ -1,2 +1,2 @@
1
- import { n as isMarkdownPreferred, r as rewritePath, t as getNegotiator } from "../negotiation-D7x4zl2m.js";
1
+ import { n as isMarkdownPreferred, r as rewritePath, t as getNegotiator } from "../negotiation-Bdf_-s58.js";
2
2
  export { getNegotiator, isMarkdownPreferred, rewritePath };
@@ -1008,14 +1008,47 @@ function rewritePath(source, destination) {
1008
1008
  return compiler(result.params);
1009
1009
  } };
1010
1010
  }
1011
+ /**
1012
+ * Parse an `Accept` header into its media types and quality values.
1013
+ *
1014
+ * Media types the client didn't rank explicitly default to `q=1`.
1015
+ */
1016
+ function parseAccept(header) {
1017
+ const entries = [];
1018
+ for (const section of header.split(",")) {
1019
+ const [rawMediaType, ...params] = section.split(";");
1020
+ const mediaType = rawMediaType.trim().toLowerCase();
1021
+ if (mediaType.length === 0) continue;
1022
+ let quality = 1;
1023
+ for (const param of params) {
1024
+ const separator = param.indexOf("=");
1025
+ if (separator === -1 || param.slice(0, separator).trim().toLowerCase() !== "q") continue;
1026
+ const parsed = Number.parseFloat(param.slice(separator + 1));
1027
+ if (!Number.isNaN(parsed)) quality = parsed;
1028
+ }
1029
+ entries.push({
1030
+ mediaType,
1031
+ quality
1032
+ });
1033
+ }
1034
+ return entries;
1035
+ }
1011
1036
  function isMarkdownPreferred(request, options) {
1012
1037
  const { markdownMediaTypes = [
1013
1038
  "text/plain",
1014
1039
  "text/markdown",
1015
1040
  "text/x-markdown"
1016
1041
  ] } = options ?? {};
1017
- const mediaTypes = getNegotiator(request).mediaTypes();
1018
- return markdownMediaTypes.some((type) => mediaTypes.includes(type));
1042
+ const accept = request.headers.get("accept");
1043
+ if (!accept) return false;
1044
+ let markdown = 0;
1045
+ let html = 0;
1046
+ for (const { mediaType, quality } of parseAccept(accept)) {
1047
+ if (quality <= 0) continue;
1048
+ if (markdownMediaTypes.includes(mediaType)) markdown = Math.max(markdown, quality);
1049
+ else if (mediaType === "text/html" || mediaType === "text/*" || mediaType === "*/*") html = Math.max(html, quality);
1050
+ }
1051
+ return markdown > 0 && markdown >= html;
1019
1052
  }
1020
1053
  //#endregion
1021
1054
  export { isMarkdownPreferred as n, rewritePath as r, getNegotiator as t };
@@ -1,7 +1,7 @@
1
- import { t as BASE_PATH } from "../../url-CWbf4MFh.js";
1
+ import { n as join, t as BASE_PATH } from "../../url-BVHvi3_K.js";
2
2
  //#region src/search/client/fetch.ts
3
3
  const globalCache = /* @__PURE__ */ new Map();
4
- function fetchClient({ api = `${BASE_PATH}api/search`, locale, tag, cache = globalCache } = {}) {
4
+ function fetchClient({ api = join(BASE_PATH, "/api/search"), locale, tag, cache = globalCache } = {}) {
5
5
  return {
6
6
  deps: [
7
7
  api,
@@ -1,4 +1,4 @@
1
- import { t as BASE_PATH } from "../../url-CWbf4MFh.js";
1
+ import { n as join, t as BASE_PATH } from "../../url-BVHvi3_K.js";
2
2
  import { n as search, t as createDocument } from "../../utils-Bvy3V-fv.js";
3
3
  //#region src/search/client/flexsearch-static.ts
4
4
  function initDocument(data) {
@@ -8,7 +8,7 @@ function initDocument(data) {
8
8
  }
9
9
  const cacheMap = /* @__PURE__ */ new Map();
10
10
  function flexsearchStaticClient(options = {}) {
11
- const { from = `${BASE_PATH}api/search`, locale = "", tag } = options;
11
+ const { from = join(BASE_PATH, "/api/search"), locale = "", tag } = options;
12
12
  let dbs = cacheMap.get(from);
13
13
  if (!dbs && typeof window !== "undefined") {
14
14
  dbs = init(from);
@@ -1,4 +1,4 @@
1
- import { t as BASE_PATH } from "../../url-CWbf4MFh.js";
1
+ import { n as join, t as BASE_PATH } from "../../url-BVHvi3_K.js";
2
2
  import { n as searchSimple, t as searchAdvanced } from "../../advanced-BnqbPavQ.js";
3
3
  import { create, load } from "@orama/orama";
4
4
  //#region src/search/client/orama-static.ts
@@ -29,7 +29,7 @@ async function loadDB(from, initOrama = (locale) => create({
29
29
  }
30
30
  return dbs;
31
31
  }
32
- function getDBCached({ from = `${BASE_PATH}api/search`, initOrama }) {
32
+ function getDBCached({ from = join(BASE_PATH, "/api/search"), initOrama }) {
33
33
  const cacheKey = from;
34
34
  const cached = cache.get(cacheKey);
35
35
  if (cached) return cached;
@@ -1,4 +1,4 @@
1
- import { i as isStaticSource, n as loader, r as isDynamicSource } from "../loader-CoSFINvo.js";
1
+ import { i as isStaticSource, n as loader, r as isDynamicSource } from "../loader-BxANMvuQ.js";
2
2
  import { cache } from "react";
3
3
  //#region src/source/dynamic.ts
4
4
  function dynamicLoader(input, options) {
@@ -1,5 +1,5 @@
1
1
  import { o as path_exports } from "../path-B9zu5SjE.js";
2
- import { a as multiple, c as FileSystem, n as loader, o as source, s as update, t as createGetUrl } from "../loader-CoSFINvo.js";
2
+ import { a as multiple, c as FileSystem, n as loader, o as source, s as update, t as createGetUrl } from "../loader-BxANMvuQ.js";
3
3
  import { getSlugs } from "./plugins/slugs.js";
4
4
  import { llms } from "./llms.js";
5
5
  export { FileSystem, path_exports as PathUtils, createGetUrl, getSlugs, llms, loader, multiple, source, update };
@@ -0,0 +1,29 @@
1
+ //#region src/utils/url.tsx
2
+ /**
3
+ * The base path (Vite)
4
+ */
5
+ const BASE_PATH = typeof import.meta.env !== "undefined" && typeof import.meta.env.BASE_URL === "string" ? import.meta.env.BASE_URL : "/";
6
+ function join(...paths) {
7
+ let out = "";
8
+ for (let p of paths) {
9
+ if (out.length > 0) {
10
+ if (p.startsWith("/")) p = p.slice(1);
11
+ if (!out.endsWith("/")) out += "/";
12
+ }
13
+ out += p;
14
+ }
15
+ return out;
16
+ }
17
+ /**
18
+ * normalize URL into the Fumadocs standard form (`/slug-1/slug-2`).
19
+ *
20
+ * This includes URLs with trailing slashes.
21
+ */
22
+ function normalizeUrl(url) {
23
+ if (url.startsWith("http://") || url.startsWith("https://")) return url;
24
+ if (!url.startsWith("/")) url = "/" + url;
25
+ if (url.length > 1 && url.endsWith("/")) url = url.slice(0, -1);
26
+ return url;
27
+ }
28
+ //#endregion
29
+ export { join as n, normalizeUrl as r, BASE_PATH as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "16.12.0",
3
+ "version": "16.13.0",
4
4
  "description": "The React.js library for building a documentation website",
5
5
  "keywords": [
6
6
  "Docs",
@@ -1,19 +0,0 @@
1
- //#region src/utils/url.tsx
2
- /**
3
- * The base path (Vite), always ends with `/`.
4
- */
5
- let BASE_PATH = typeof import.meta.env !== "undefined" && typeof import.meta.env.BASE_URL === "string" ? import.meta.env.BASE_URL : "/";
6
- if (!BASE_PATH.endsWith("/")) BASE_PATH += "/";
7
- /**
8
- * normalize URL into the Fumadocs standard form (`/slug-1/slug-2`).
9
- *
10
- * This includes URLs with trailing slashes.
11
- */
12
- function normalizeUrl(url) {
13
- if (url.startsWith("http://") || url.startsWith("https://")) return url;
14
- if (!url.startsWith("/")) url = "/" + url;
15
- if (url.length > 1 && url.endsWith("/")) url = url.slice(0, -1);
16
- return url;
17
- }
18
- //#endregion
19
- export { normalizeUrl as n, BASE_PATH as t };