@@ -16,6 +16,8 @@ const MARKDOWN_LINK_REGEX = /\[([^\]]+)\]\(([^)]+)\)/g;
1616const JSX_LINK_REGEX = / h r e f = [ " ' ] ( [ ^ " ' ] + ) [ " ' ] / g;
1717const ANCHOR_REGEX = / # [ ^ ) \s " ' ] * / ;
1818const CODE_BLOCK_REGEX = / ` ` ` [ \s \S ] * ?` ` ` / g;
19+ const FRONTMATTER_REGEX = / ^ - - - \s * \n ( [ \s \S ] * ?) \n - - - / ;
20+ const TITLE_REGEX = / ^ t i t l e : \s * [ " ' ] ? ( [ ^ " ' \n ] + ) [ " ' ] ? / m;
1921
2022function 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+
4454function 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 = [ ] ;
0 commit comments