Skip to content

Commit

Permalink
build: make doc builds concurrent
Browse files Browse the repository at this point in the history
  • Loading branch information
TheManchineel committed Dec 12, 2024
1 parent a0f65bb commit d08c002
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions build_docs_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,52 @@


def build_docs_and_index():
jobs = []
with StringIO() as index_entries:
for path in pathlib.Path("/workspace").rglob("*/*.md"):
print(f"Processing {path}...")
for path in sorted(pathlib.Path("/workspace").rglob("*/*.md")):
print(f"Adding {path} to the build queue")
last_modified = datetime.datetime.fromtimestamp(path.stat().st_mtime).strftime("%Y-%m-%d %H:%M:%S")
output_filename = path.parent / f"{path.stem}.html"
index_entries.write(f'<li><a href="{output_filename}">{path.parent.name}</a></li>\n')
Popen(
[
"pandoc",
"--template",
"template.html",
"--toc",
"--katex=https://cdn.jsdelivr.net/npm/[email protected]/dist/",
"--metadata",
"toc-title=Indice",
"--metadata",
"lang=it",
"--metadata",
f"date={last_modified}",
"--metadata",
"maxwidth=100vw",
"--verbose",
"-o",
output_filename,
path,
]
).wait()

if output_filename.name == "index.html":
index_entries.write(
f'<li><a href="/{path.parent.name}/{output_filename.name}>{path.parent.name}</a></li>\n'
)
jobs.append(
Popen(
[
"pandoc",
"--template",
"template.html",
"--toc",
"--katex=https://cdn.jsdelivr.net/npm/[email protected]/dist/",
"--metadata",
"toc-title=Indice",
"--metadata",
"lang=it",
"--metadata",
f"date={last_modified}",
"--metadata",
"maxwidth=100vw",
# Output gets very messy with concurrent verbose output
# "--verbose",
"-o",
output_filename,
path,
]
)
)
original_html = ""
with open("/workspace/index.html", "r") as index_file:
original_html = index_file.read()

with open("/workspace/index.html", "w") as index_file:
index_file.write(original_html.replace("{{{PLACEHOLDER}}}", index_entries.getvalue()))

print("Waiting for jobs to complete...")
for job in jobs:
job.wait()
print("Done! :)")


if __name__ == "__main__":
build_docs_and_index()
Expand Down

0 comments on commit d08c002

Please sign in to comment.