-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0f65bb
commit d08c002
Showing
1 changed file
with
36 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
|