From 3d592b1574d7b687e12d71ff82b8a6be2cf6fc5d Mon Sep 17 00:00:00 2001 From: Jane Chu <7559015+janechu@users.noreply.github.com> Date: Tue, 16 Jun 2020 15:24:04 -0700 Subject: [PATCH] chore: replace relative paths with absolute paths when README files are converted --- .../build/convert-readme.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/sites/fast-component-explorer/build/convert-readme.js b/sites/fast-component-explorer/build/convert-readme.js index 92c2e533699..b041421d320 100644 --- a/sites/fast-component-explorer/build/convert-readme.js +++ b/sites/fast-component-explorer/build/convert-readme.js @@ -8,6 +8,9 @@ const fs = require("fs"); const MarkdownIt = require("markdown-it"); const srcDir = "../../packages/web-components/fast-components/src/**/README.md"; +// TODO: update this when the repository is renamed +const webComponentWorkspacePath = + "https://github.com/microsoft/fast-dna/tree/master/packages/web-components/"; /** * Start and end file strings @@ -33,6 +36,18 @@ const md = new MarkdownIt({ xhtmlOut: true, }); +/** + * Function to determine the correct href path if + * it uses a relative path + */ +function normalizeLink() { + return `href="${webComponentWorkspacePath}`; +} + +function normalizeMarkdown(markdown) { + return markdown.replace(/href="\.\.\/\.\.\/\.\.\//gm, normalizeLink); +} + /** * Function to create string exports of a given path */ @@ -48,7 +63,7 @@ const md = new MarkdownIt({ const componentFolderName = pathSegments[pathSegments.length - 2]; if (markdown.length !== 0) { - guidance += md.render(markdown); + guidance += normalizeMarkdown(md.render(markdown)); } else { guidance += emptyFile; }