@@ -29,6 +29,9 @@ const linkInlineMarkup = {
2929 strong : '**'
3030}
3131
32+ const currentVersionWithSpacesRegex = / \/ e n t e r p r i s e \/ { { c u r r e n t V e r s i o n } } / g
33+ const currentVersionWithoutSpaces = '/enterprise/{{currentVersion}}'
34+
3235// [start-readme]
3336//
3437// Run this script to find internal links in all content and data Markdown files, check if either the title or link
@@ -61,10 +64,14 @@ async function main () {
6164
6265 for ( const file of allFiles ) {
6366 const { data, content } = frontmatter ( fs . readFileSync ( file , 'utf8' ) )
64- const ast = astFromMarkdown ( content )
65-
6667 let newContent = content
6768
69+ // Do a blanket find-replace for /enterprise/{{ currentVersion }}/ to /enterprise/{{currentVersion}}/
70+ // so that the AST parser recognizes the link as a link node. The spaces prevent it from doing so.
71+ newContent = newContent . replace ( currentVersionWithSpacesRegex , currentVersionWithoutSpaces )
72+
73+ const ast = astFromMarkdown ( newContent )
74+
6875 // We can't do async functions within visit, so gather the nodes upfront
6976 const nodesPerFile = [ ]
7077
@@ -98,8 +105,9 @@ async function main () {
98105 const oldTitle = node . children [ 0 ] . value || node . children [ 0 ] . children [ 0 ] . value
99106 const oldMarkdownLink = `[${ inlineMarkup } ${ oldTitle } ${ inlineMarkup } ](${ oldLink } )`
100107
101- // As a blanket rule, only update titles in links that have quotes around them.
102- // Update: "[Foo](/foo)"
108+ // As a blanket rule, only update titles in links that begin with quotes. (Many links
109+ // have punctuation before the closing quotes, so we'll only check for opening quotes.)
110+ // Update: "[Foo](/foo)
103111 // Do not update: [Bar](/bar)
104112 const hasQuotesAroundLink = newContent . includes ( `"${ oldMarkdownLink } ` )
105113
@@ -136,7 +144,7 @@ async function main () {
136144 process . exit ( 1 )
137145 }
138146
139- // If the original link includes a fragment or the original title includes Liquid, do not change;
147+ // If the original link includes a fragment OR the original title includes Liquid, do not change;
140148 // otherwise, use the found page title. (We don't want to update the title if a fragment is found because
141149 // the title likely points to the fragment section header, not the page title.)
142150 const newTitle = fragmentMatch || oldTitle . includes ( '{%' ) || ! hasQuotesAroundLink ? oldTitle : foundPage . title
0 commit comments