fumadocs-core 16.12.1 → 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 { 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,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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "16.12.1",
3
+ "version": "16.13.0",
4
4
  "description": "The React.js library for building a documentation website",
5
5
  "keywords": [
6
6
  "Docs",