Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Remove missing frontmatter workaround
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
  • Loading branch information
ArthurSens committed Sep 9, 2026
commit 39b4ee9e34cecda3d65a6c2549166993929db4fe
3 changes: 1 addition & 2 deletions docs-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ export default {
slugPrefix: "exporters/official-exporters/postgres",
navTitle: "Postgres",
versioning: "git-ref",
ref: "3d2ee4adba4ec98106b6ec45e59b12f5b49ef3a4",
allowMissingFrontmatter: true,
ref: "a488faeecc902f7a4ef74a23518639004e4048b2",
},
],

Expand Down
55 changes: 6 additions & 49 deletions scripts/fetch-repo-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,6 @@ const normalizeMarkdownFilePath = (filePath: string) =>
const markdownSlugPath = (filePath: string) =>
normalizeMarkdownFilePath(filePath).replace(/(^|\/)index\.md$/, "").replace(/\.md$/, "");

const preferredPreviewOrder = [
"index",
"getting-started",
"connecting",
"database-permissions",
"configuration",
"secrets",
"docker",
"aws-rds",
];

const inferTitle = (markdown: string, filePath: string) => {
const heading = markdown
.split(/\r?\n/)
.find((line) => line.startsWith("# "))
?.replace(/^#\s+/, "")
.trim();

if (heading) {
return heading;
}

return path
.basename(filePath, ".md")
.replace(/[-_]/g, " ")
.replace(/\b\w/g, (char) => char.toUpperCase());
};

const inferSortRank = (filePath: string, index: number) => {
const slugPath = markdownSlugPath(filePath) || "index";
const sortRank = preferredPreviewOrder.indexOf(slugPath);
return sortRank === -1 ? 1000 + index : sortRank + 1;
};

// Find all files (.md and others) recursively in a directory.
const findFiles = (dir: string): string[] => {
let results: string[] = [];
Expand Down Expand Up @@ -138,7 +104,6 @@ type IntegrateRepoDocsOptions = {
docsDir: string;
repoDocsDir: string;
assetsRoot: string;
allowMissingFrontmatter?: boolean;
includeFile: (filePath: string) => boolean;
addMarkdownDoc: (args: {
file: string;
Expand All @@ -157,7 +122,6 @@ const integrateRepoDocs = ({
docsDir,
repoDocsDir,
assetsRoot,
allowMissingFrontmatter,
includeFile,
addMarkdownDoc,
}: IntegrateRepoDocsOptions) => {
Expand All @@ -167,7 +131,7 @@ const integrateRepoDocs = ({
return markdownSlugPath(aPath).localeCompare(markdownSlugPath(bPath));
});

for (const [index, file] of files.entries()) {
for (const file of files) {
const filePath = path.relative(docsDir, file);
const normalizedFilePath = normalizeMarkdownFilePath(filePath);

Expand All @@ -178,41 +142,36 @@ const integrateRepoDocs = ({
if (file.endsWith(".md")) {
console.log("Found Markdown file:", filePath);

const markdown = fs.readFileSync(file, "utf-8");
const {
content,
data: {
title,
nav_title: navTitle,
sort_rank: sortRank,
hide_in_nav: hideInNav,
},
} = matter(markdown);
} = matter(fs.readFileSync(file, "utf-8"));

if (!title && !allowMissingFrontmatter) {
if (!title) {
throw new Error(`Missing title in ${file}`);
}
if (sortRank == null && !allowMissingFrontmatter) {
if (sortRank == null) {
// Docs in https://github.com/prometheus/prometheus/tree/main/docs/command-line
// are currently missing sort_rank 😤
if (!filePath.includes("command-line")) {
throw new Error(`Missing sort_rank in ${file}`);
}
}

const finalTitle = title ?? inferTitle(content, filePath);
const finalSortRank = sortRank ?? inferSortRank(filePath, index);

addMarkdownDoc({
file,
filePath: path.posix.join(
repoDocsDir,
filePath.split(path.sep).join(path.posix.sep)
),
slugPath: markdownSlugPath(filePath),
title: finalTitle,
title,
navTitle,
sortRank: finalSortRank,
sortRank: sortRank ?? 0,
hideInNav,
});
} else {
Expand Down Expand Up @@ -484,7 +443,6 @@ const fetchGitRefRepoDocs = async ({
repoDocsDir,
slugPrefix,
ref,
allowMissingFrontmatter,
navTitle: rootNavTitle,
}: Extract<GithubMarkdownSource, { versioning: "git-ref" }>) => {
console.log(`Fetching docs for ${owner}/${repo}@${ref}...`);
Expand Down Expand Up @@ -513,7 +471,6 @@ const fetchGitRefRepoDocs = async ({
docsDir,
repoDocsDir,
assetsRoot,
allowMissingFrontmatter,
includeFile: () => true,
addMarkdownDoc: ({
file,
Expand Down
1 change: 0 additions & 1 deletion src/docs-config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export type GithubMarkdownSource = {
| {
versioning: "git-ref";
ref: string;
allowMissingFrontmatter?: boolean;
}
);

Expand Down