refactor(website): compute Markdown preference once (#16438)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-03 18:47:20 +00:00
1 parent 6dda69dc1d
commit 356b0b2b47
1 file changed
+5 -8
+5 -8
View File
@@ -11,22 +11,19 @@ function prefersMarkdown(accept) {
const q = quality === undefined ? 1 : Number(quality.slice(2));
return {
type: type.trim(),
q: Number.isFinite(q) && q >= 0 && q <= 1 ? q : 0,
q: q >= 0 && q <= 1 ? q : 0,
};
});
const quality = (type) => {
for (const match of [type, "text/*", "*/*"]) {
const quality = (types) => {
for (const match of types) {
const matches = ranges.filter((range) => range.type === match);
if (matches.length) return Math.max(...matches.map((range) => range.q));
}
return 0;
};
// Wildcards alone never opt a browser into Markdown; HTML wins ties.
return (
ranges.some((range) => range.type === "text/markdown") &&
quality("text/markdown") > 0 &&
quality("text/markdown") > quality("text/html")
);
const markdown = quality(["text/markdown"]);
return markdown > 0 && markdown > quality(["text/html", "text/*", "*/*"]);
}
function advertiseMarkdown(response, path) {