Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update to absolute paths when converting README files #3325

Merged
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion sites/fast-component-explorer/build/convert-readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
janechu marked this conversation as resolved.
Show resolved Hide resolved
janechu marked this conversation as resolved.
Show resolved Hide resolved
const webComponentWorkspacePath =
"https://github.com/microsoft/fast-dna/tree/master/packages/web-components/";

/**
* Start and end file strings
Expand All @@ -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);
}
janechu marked this conversation as resolved.
Show resolved Hide resolved

/**
* Function to create string exports of a given path
*/
Expand All @@ -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;
}
Expand Down