Skip to content

Commit 6e70929

Browse files
committed
fix: Link handling
1 parent df20aca commit 6e70929

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

tools/builder/prepare-gh-pages.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,9 @@ function getSteps(tutorialDir) {
5151
mkdirSync(join(cwd, "dist"), { recursive: true });
5252

5353
console.log(`👉 Copying root README.md...`);
54-
function rewriteLinks(file, path, tutorialName) {
55-
let permalink;
56-
if (!path) {
57-
permalink = "index.html";
58-
} else if (!tutorialName) {
59-
permalink = `build/${path.replace(".md", ".html")}`;
60-
} else {
61-
permalink = `${tutorialName}/build/${path.replace(".md", ".html")}`;
62-
}
54+
function rewriteLinks(file) {
55+
let permalink = file.split("dist/")[1].replace(".md", ".html");
6356
let content = `---\npermalink: ${permalink}\n---\n\n${readFileSync(file, { encoding: "utf8"})}`;
64-
if (tutorialName) {
65-
content = content.replace(/steps\/(\d{2})/g, `${tutorialName}/build/$1`);
66-
content = content.replace(/\.\.\/(\d{2})/g, "../$1");
67-
} else {
68-
content = content.replace(/steps\/(\d{2})/g, "build/$1");
69-
content = content.replace(/\.\.\/(\d{2})/g, "../$1");
70-
}
7157
content = content.replace(/README\.md/g, "README.html");
7258
writeFileSync(file, content, { encoding: "utf8" });
7359
}
@@ -104,7 +90,7 @@ function getSteps(tutorialDir) {
10490
console.log(` 👉 Copying tutorial README.md...`);
10591
if (existsSync(join(tutorialDir, "README.md"))) {
10692
copyFileSync(join(tutorialDir, "README.md"), join(distTutorialDir, "index.md"));
107-
rewriteLinks(join(distTutorialDir, "index.md"), null, tutorial);
93+
rewriteLinks(join(distTutorialDir, "index.md"));
10894
}
10995

11096
console.log(` 👉 Zipping TypeScript sources...`);
@@ -132,7 +118,7 @@ function getSteps(tutorialDir) {
132118
const [, path, step] = readme.match("steps/((.*)/README.md)");
133119
mkdirSync(join(buildDir, step), { recursive: true });
134120
copyFileSync(join(tutorialDir, readme), join(buildDir, path));
135-
rewriteLinks(join(buildDir, path), path, tutorial);
121+
rewriteLinks(join(buildDir, path));
136122
});
137123

138124
console.log(` 🌅 Copying step assets...`);

0 commit comments

Comments
 (0)