Skip to content

Commit 1122f3f

Browse files
committed
Add Makefile options NODE and VOID_GUIDES
1 parent 80ea419 commit 1122f3f

3 files changed

Lines changed: 47 additions & 25 deletions

File tree

Makefile

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# *── Makefile ── Makefile for deimonn.dev ──*
22
#
3-
# │ Copyright (c) 2025 Deimonn
3+
# │ Copyright (c) 2025-2026 Deimonn
44
#
55
# │ This file is licensed under the MIT License.
66
#
@@ -15,6 +15,20 @@
1515
# Create build directories.
1616
$(shell mkdir -p dist/assets obj)
1717

18+
# *─────────*
19+
# │ Options
20+
# *
21+
22+
# Node command line to use to run scripts.
23+
NODE ?= node
24+
25+
# Path to the `void-guides` submodule.
26+
VOID_GUIDES ?= src/submodules/void-guides
27+
28+
# *─────────*
29+
# │ Targets
30+
# *
31+
1832
# List of all targets.
1933
targets =
2034

@@ -67,30 +81,30 @@ targets += dist/index.html
6781

6882
# Documentation for 'void-guides'.
6983
void_guides_sources = \
70-
src/submodules/void-guides/index.md \
71-
$(wildcard src/submodules/void-guides/*/*.md)
84+
$(VOID_GUIDES)/index.md \
85+
$(wildcard $(VOID_GUIDES)/*/*.md)
7286
void_guides_outputs = \
73-
$(patsubst src/submodules/void-guides/%.md,dist/void-guides/%.html,$(void_guides_sources))
87+
$(patsubst $(VOID_GUIDES)/%.md,dist/void-guides/%.html,$(void_guides_sources))
7488

7589
dist/void-guides/search-db.json obj/void-guides/nav-db.json: \
7690
compile-db.js $(void_guides_sources)
7791
mkdir -p dist/void-guides obj/void-guides
78-
node compile-db.js \
79-
void-guides void-guides/ \
92+
$(NODE) compile-db.js \
93+
'$(VOID_GUIDES)' void-guides void-guides/ \
8094
$(sort $(void_guides_sources))
8195

8296
dist/void-guides/%.html: \
8397
src/templates/docs.html src/main.html \
84-
src/submodules/void-guides/%.md src/submodules/void-guides/categories.json \
98+
$(VOID_GUIDES)/%.md $(VOID_GUIDES)/categories.json \
8599
compile-markdown.js obj/oro-theme.json obj/void-guides/nav-db.json
86100

87101
# Create directories.
88102
mkdir -p "$$(dirname $(subst dist/void-guides/,obj/void-guides/,$@))"
89103
mkdir -p "$$(dirname $@)"
90104

91105
# Compile markdown.
92-
node compile-markdown.js \
93-
void-guides void-guides/ \
106+
$(NODE) compile-markdown.js \
107+
'$(VOID_GUIDES)' void-guides void-guides/ \
94108
$(patsubst dist/void-guides/%.html,%,$@)
95109

96110
# Generate page from template.

compile-db.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*── compile-db.js ── Compilation of database ──*
22
3-
│ Copyright (c) 2025 Deimonn
3+
│ Copyright (c) 2025-2026 Deimonn
44
55
│ This file is licensed under the MIT License.
66
@@ -19,19 +19,23 @@ function readFile(path) {
1919
return fs.readFileSync(path, { encoding: "utf-8" });
2020
}
2121

22+
// Fetch arguments.
23+
const args = process.argv.slice(2);
24+
25+
const submodule = args[0];
26+
const repo = args[1];
27+
const prefix = args[2].substring(repo.length + 1);
28+
29+
const inputs = args.slice(3);
30+
2231
// Variables and constants.
2332
let search = [];
2433
let nav = [];
2534

26-
const repo = process.argv[2];
27-
const prefix = process.argv[3];
28-
2935
const searchOutput = `dist/${repo}/search-db.json`;
3036
const navOutput = `obj/${repo}/nav-db.json`;
3137

3238
// Parse inputs.
33-
const inputs = process.argv.slice(4);
34-
3539
for (const input of inputs) {
3640
// Initialize entry and push it to search database.
3741
const entry = {
@@ -41,7 +45,10 @@ for (const input of inputs) {
4145
search.push(entry);
4246

4347
// Generate link.
44-
const href = input.substring(15 + prefix.length, input.length - 3);
48+
const hrefStart = submodule.length + prefix.length + 1;
49+
const hrefEnd = input.length - 3;
50+
51+
const href = input.substring(hrefStart, hrefEnd);
4552
entry.href = `/${repo}/${href}`;
4653

4754
// Read file contents.

compile-markdown.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*── compile-markdown.js ── Compilation of markdown docs ──*
22
3-
│ Copyright (c) 2025 Deimonn
3+
│ Copyright (c) 2025-2026 Deimonn
44
55
│ This file is licensed under the MIT License.
66
@@ -25,11 +25,12 @@ function readFile(path) {
2525
// Fetch arguments.
2626
const args = process.argv.slice(2);
2727

28-
const repo = args[0];
29-
const prefix = args[1].substring(repo.length + 1);
30-
const target = args[2];
28+
const submodule = args[0];
29+
const repo = args[1];
30+
const prefix = args[2].substring(repo.length + 1);
31+
const target = args[3];
3132

32-
const input = `src/submodules/${repo}/${prefix}${target}.md`;
33+
const input = `${submodule}/${prefix}${target}.md`;
3334
const mainOutput = `obj/${repo}/${target}.html`;
3435
const navOutput = `obj/${repo}/${target}.nav.html`;
3536
const tocOutput = `obj/${repo}/${target}.toc.html`;
@@ -82,7 +83,7 @@ let mainHtml = await marked.parse(readFile(input), {
8283
token.href = token.href.replace(/(\.md$)|(\.md(?=#))/, "");
8384

8485
// Validate existence.
85-
let file = `src/submodules/${repo}/${prefix}`;
86+
let file = `${submodule}/${prefix}`;
8687

8788
file += path.dirname(target) + "/";
8889
file += token.href.replace(/#.*$/, "") + ".md";
@@ -196,17 +197,17 @@ if (headings.length == 0) {
196197
const categories = {};
197198
let dictionary = {};
198199

199-
if (fs.existsSync(`src/submodules/${repo}/${prefix}categories.json`)) {
200+
if (fs.existsSync(`${submodule}/${prefix}categories.json`)) {
200201
dictionary = JSON.parse(
201-
readFile(`src/submodules/${repo}/${prefix}categories.json`)
202+
readFile(`${submodule}/${prefix}categories.json`)
202203
);
203204
}
204205

205206
for (const entry of nav) {
206207
const path = entry.path;
207208

208209
// Remove common prefix.
209-
const file = path.substring(16 + repo.length + prefix.length);
210+
const file = path.substring(submodule.length + prefix.length + 1);
210211
if (!file.includes("/")) {
211212
continue;
212213
}

0 commit comments

Comments
 (0)