Skip to content

Commit 0f1512d

Browse files
authored
Use new frontmatter docs title schema for new Prometheus/Alertmanager docs (#2686)
Signed-off-by: Julius Volz <[email protected]>
1 parent e39897e commit 0f1512d

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

scripts/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ export const compareFullVersion = (a: string, b: string) => {
1010
return compare(a.replace(/^v/, ""), b.replace(/^v/, ""));
1111
};
1212

13+
// Compares two "<major>.<minor>" version strings., e.g. "3.4" vs "3.5".
14+
export const compareMajorMinor = (a: string, b: string) => {
15+
const [aMajor, aMinor] = a.split(".").map(Number);
16+
const [bMajor, bMinor] = b.split(".").map(Number);
17+
if (aMajor === bMajor) {
18+
return aMinor === bMinor ? 0 : aMinor > bMinor ? 1 : -1;
19+
}
20+
return aMajor > bMajor ? 1 : -1;
21+
};
22+
1323
export function filterUnique(value: string, index: number, array: string[]) {
1424
return array.indexOf(value) === index;
1525
}

src/app/docs/[...slug]/page.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Divider, Title } from "@mantine/core";
88
import PrevNextEditButtons from "./PrevNextEditButtons";
99
import path from "path";
1010
import { DocMetadata } from "@/docs-collection-types";
11+
import { compareMajorMinor } from "../../../../scripts/utils";
1112

1213
// Next.js uses this function at build time to figure out which
1314
// docs pages it should statically generate.
@@ -82,6 +83,18 @@ export default async function DocsPage({
8283
(docMeta.version === docMeta.latestVersion &&
8384
!docMeta.slug.startsWith(docMeta.versionRoot));
8485

86+
// The Markdown format was changed in Prometheus >3.4 and Alertmanager >0.28
87+
// to not include the H1 title in the Markdown content itself, so we need to
88+
// externally render the title using the frontmatter `title` field instead..
89+
const useFrontmatterTitle =
90+
docMeta.type === "local-doc" ||
91+
(docMeta.type === "repo-doc" &&
92+
docMeta.owner === "prometheus" &&
93+
((docMeta.repo === "prometheus" &&
94+
compareMajorMinor(docMeta.version, "3.4") === 1) ||
95+
(docMeta.repo === "alertmanager" &&
96+
compareMajorMinor(docMeta.version, "0.28") === 1)));
97+
8598
return (
8699
<>
87100
<VersionWarning currentPage={docMeta} />
@@ -93,9 +106,7 @@ export default async function DocsPage({
93106
)}`,
94107
}}
95108
>
96-
{docMeta.type === "local-doc" && (
97-
<Title order={1}>{docMeta.title}</Title>
98-
)}
109+
{useFrontmatterTitle && <Title order={1}>{docMeta.title}</Title>}
99110
<PromMarkdown
100111
normalizeHref={(href: string | undefined) => {
101112
if (!href) {

0 commit comments

Comments
 (0)