Skip to content

Commit ffc8c81

Browse files
committed
fix: ignore draft docs in link checker
1 parent 1c3827e commit ffc8c81

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

scripts/check-links.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const MARKDOWN_LINK_REGEX = /\[([^\]]+)\]\(([^)]+)\)/g;
1616
const JSX_LINK_REGEX = /href=["']([^"']+)["']/g;
1717
const ANCHOR_REGEX = /#[^)\s"']*/;
1818
const CODE_BLOCK_REGEX = /```[\s\S]*?```/g;
19+
const FRONTMATTER_REGEX = /^---\s*\n([\s\S]*?)\n---/;
20+
const TITLE_REGEX = /^title:\s*["']?([^"'\n]+)["']?/m;
1921

2022
function removeCodeBlocks(content) {
2123
return content.replace(CODE_BLOCK_REGEX, (match) => {
@@ -41,6 +43,14 @@ function findMDXFiles(dir, fileList = []) {
4143
return fileList;
4244
}
4345

46+
function hasDraftTitle(content) {
47+
const frontmatter = content.match(FRONTMATTER_REGEX);
48+
if (!frontmatter) return false;
49+
50+
const title = frontmatter[1].match(TITLE_REGEX);
51+
return title ? title[1].toLowerCase().includes('draft') : false;
52+
}
53+
4454
function extractLinks(content, filePath) {
4555
const links = [];
4656

@@ -282,9 +292,13 @@ async function main() {
282292

283293
const mdxFiles = findMDXFiles('.');
284294
const excludedPaths = ['node_modules', '.git', 'CONTRIBUTING.md'];
285-
const filteredFiles = mdxFiles.filter(file =>
286-
!excludedPaths.some(excluded => file.includes(excluded))
287-
);
295+
const filteredFiles = mdxFiles.filter(file => {
296+
if (excludedPaths.some(excluded => file.includes(excluded))) {
297+
return false;
298+
}
299+
300+
return !hasDraftTitle(fs.readFileSync(file, 'utf8'));
301+
});
288302

289303
const brokenLinks = [];
290304
const externalLinks = [];

timezones-draft.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Working with timezones in Lightdash"
2+
title: "Draft: Working with timezones in Lightdash"
33
description: "Hidden draft: how to model warehouse data and use Lightdash so that timezones behave predictably."
44
hidden: true
55
---

0 commit comments

Comments
 (0)