diff --git a/lib/server/docs.js b/lib/server/docs.js index f5c7ceb6b389..896d3e1ec994 100644 --- a/lib/server/docs.js +++ b/lib/server/docs.js @@ -38,10 +38,18 @@ function getFile(metadata) { function mdToHtmlify(oldContent, mdToHtml, metadata) { let content = oldContent; + const mdLinks = []; + + // find any links to markdown files const regex = /(?:\]\()(?:\.\/)?([^'")\]\s>]+\.md)/g; let match = regex.exec(content); while (match !== null) { - const mdLink = match[1]; + mdLinks.push(match[1]); + match = regex.exec(content); + } + + // replace to their website html links + new Set(mdLinks).forEach(mdLink => { let htmlLink = mdToHtml[mdLink]; if (htmlLink) { htmlLink = getPath(htmlLink, siteConfig.cleanUrl); @@ -57,8 +65,7 @@ function mdToHtmlify(oldContent, mdToHtml, metadata) { `](${htmlLink}` ); } - match = regex.exec(content); - } + }); return content; }