Skip to content

Commit 46c88fe

Browse files
committed
Allow docs to exist in places other than the repository root
1 parent dbc0882 commit 46c88fe

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ $(void_guides_outputs): \
8282

8383
# Compile markdown.
8484
node compile-markdown.js \
85-
void-guides \
85+
void-guides void-guides/ \
8686
$(patsubst dist/void-guides/%.html,%,$@)
8787

8888
# Generate page from template.

compile-markdown.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ function readFile(path) {
2626
const args = process.argv.slice(2);
2727

2828
const repo = args[0];
29-
const target = args[1];
29+
const prefix = args[1].substring(repo.length + 1);
30+
const target = args[2];
3031

31-
const input = `src/submodules/${repo}/${target}.md`;
32+
const input = `src/submodules/${repo}/${prefix}${target}.md`;
3233
const mainOutput = `obj/${repo}/${target}.html`;
3334
const navOutput = `obj/${repo}/${target}.nav.html`;
3435
const tocOutput = `obj/${repo}/${target}.toc.html`;
@@ -82,7 +83,7 @@ let mainHtml = await marked.parse(readFile(input), {
8283
}
8384

8485
// Other relative link; point to raw user content.
85-
let dirname = path.dirname(target);
86+
let dirname = path.dirname(prefix + target);
8687
let href =
8788
`https://raw.githubusercontent.com/deimonn/` +
8889
`${repo}/refs/heads/master/${dirname}/${token.href}`
@@ -181,13 +182,15 @@ if (headings.length == 0) {
181182
const categories = {};
182183
let dictionary = {};
183184

184-
if (fs.existsSync(`src/submodules/${repo}/categories.json`)) {
185-
dictionary = JSON.parse(readFile(`src/submodules/${repo}/categories.json`));
185+
if (fs.existsSync(`src/submodules/${repo}/${prefix}categories.json`)) {
186+
dictionary = JSON.parse(
187+
readFile(`src/submodules/${repo}/${prefix}categories.json`)
188+
);
186189
}
187190

188191
for (const path of listing) {
189192
// Remove common prefix.
190-
const file = path.substring(16 + repo.length);
193+
const file = path.substring(16 + repo.length + prefix.length);
191194
if (!file.includes("/")) {
192195
continue;
193196
}
@@ -227,7 +230,7 @@ for (const [_, category] of Object.entries(categories)) {
227230

228231
for (const file of category.files) {
229232
// Current file, highlighted in bold.
230-
if (input == `src/submodules/${repo}/${file.path}`) {
233+
if (input == `src/submodules/${repo}/${prefix}${file.path}`) {
231234
navHtml += /* HTML */ `
232235
<li>
233236
<b>${file.name}</b>

0 commit comments

Comments
 (0)