-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add scripts/update-readme-table.py * call update-readme-table.py from scripts/render-tikz.py * update readme * show file length to section title * pnpm add -D @sveltejs/vite-plugin-svelte
- Loading branch information
Showing
6 changed files
with
179 additions
and
117 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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Auto-update readme table listing all TikZ figures in assets/.""" | ||
|
||
import os | ||
import re | ||
from glob import glob | ||
from itertools import zip_longest | ||
|
||
MOD_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
ROOT = os.path.dirname(MOD_DIR) | ||
TEX_DIR = f"{ROOT}/assets" | ||
|
||
tex_paths = sorted(glob(f"{TEX_DIR}/**/*.tex")) | ||
|
||
md_table = f"| {' ' * 22} | {' ' * 22} |\n| :---: | :---: |\n" | ||
|
||
for path1, path2 in zip_longest(tex_paths[::2], tex_paths[1::2]): | ||
dir1, dir2 = map(os.path.dirname, (path1, path2 or "")) | ||
fig1, fig2 = map(os.path.basename, (dir1, dir2)) | ||
|
||
# file name row | ||
dir_link1 = f"[`{fig1}`](https://janosh.github.io/tikz/{fig1})" | ||
dir_link2 = f"[`{fig2}`](https://janosh.github.io/tikz/{fig2})" if path2 else "" | ||
md_table += f"| {dir_link1} | {dir_link2} |\n" | ||
|
||
# image row | ||
img_link1 = f"![`{fig1}.png`](assets/{fig1}/{fig1}.png)" | ||
img_link2 = f"![`{fig2}.png`](assets/{fig2}/{fig2}.png)" if path2 else "" | ||
md_table += f"| {img_link1} | {img_link2} |\n" | ||
|
||
|
||
with open(f"{ROOT}/README.md", "r") as file: | ||
readme = file.read() | ||
|
||
# insert table markdown between "## Images\n" and "## Scripts\n" headings | ||
readme = re.sub( | ||
r"(?<=## Images\n)(.*)(?=## Scripts\n)", | ||
f"\n{md_table}\n", | ||
readme, | ||
flags=re.DOTALL, | ||
) | ||
|
||
with open(f"{ROOT}/README.md", "w") as file: | ||
file.write(readme) | ||
|
||
# run pre-commit on readme to format white space in table | ||
os.system("pre-commit run --files readme.md") |
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
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
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