Wait for kroki to start

This commit is contained in:
Lu Baumann 2023-10-17 01:44:10 +00:00 committed by GitHub
parent 54895751dc
commit c8de805803
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 105 deletions

View File

@ -11,6 +11,8 @@ runs:
- name: Start containers
run: docker-compose -f "${{ github.action_path }}/docker-compose.yml" up -d --build
shell: bash
- run: ${{ github.action_path }}/wait_for_kroki.sh
shell: bash
- name: Creating SVG files
run: find "${{ github.workspace }}" -type f -name '*.excalidraw' -exec bash "${{ github.action_path }}/to_svg.sh" "{}" ${{ inputs.dark-mode == 'true' }} ";"
shell: bash

105
main.py
View File

@ -1,105 +0,0 @@
from pathlib import Path
from sys import argv, stderr
import re
excalidraw_re = re.compile(r"\[\[(.*\.excalidraw)\]\]")
def eprint(*args, **kwargs):
print(*args, file=stderr, **kwargs)
def iter_svgs(vault_path, draws):
for draw in draws:
svg = Path("assets/excalidraw_svg").joinpath(Path(draw).with_suffix(".svg").name)
if vault_path.joinpath(svg).is_file():
print("::debug::[found]", svg)
yield draw, svg
else:
eprint("::error::[missing]", svg)
yield draw, None
def iter_refs(vault_path):
pages = [path for path in vault_path.joinpath("pages").glob("*") if path.is_file()]
for page in pages:
with open(page) as f:
content = f.read()
for ref_match in excalidraw_re.finditer(content):
yield page, ref_match
def get_draws(vault_path):
draws = set()
pages = set()
for page, ref_match in iter_refs(vault_path):
draws.add(ref_match[1])
pages.add(page)
return pages, draws
def main() -> None:
"""
Replaces excalidraw file references with svg references
If <drawing_name>.svg exists in assets/excalidraw_svg it will be used,
otherwise it will be replaced with
:return:
"""
vault_path = Path(argv[1]).expanduser()
home_md_file = None
if len(argv) > 2:
home_md_file = Path(argv[2]).expanduser()
if not home_md_file:
home_md_file = None
pages, draws = get_draws(vault_path)
missing_svgs = []
replace_dict = {}
for draw, svg in iter_svgs(vault_path, draws):
if svg is None:
replace_dict[f"[[{draw}]]"] = "<h1 style='color: #ff0000'>MISSING IMAGE</h1>"
missing_svgs.append(draw)
else:
replace_dict[f"[[{draw}]]"] = f"![{draw}](../{svg})"
for page in pages:
with open(page) as f:
content = f.read()
for prev, new in replace_dict.items():
content = content.replace(prev, new)
with open(page, "w") as f:
f.write(content)
if missing_svgs:
if home_md_file is not None:
eprint(f"::notice::Writing error message to {home_md_file}")
file_error = "\n" + f"""
- <h1 style="color: red;">Some drawings were not loaded</h1>
\t- ## How to fix as a Contributor
\t\t- drawings are located in <vault path>/draws
\t\t- each ".excalidraw" drawing file should have an equivalent ".svg" file in <vault path>/assets/excalidraw_svg with the same basename
\t\t- ### Example
\t\t ```
\t\t <vault path>/draws/2023-10-08-21-23-31.excalidraw
\t\t <vault path>/assets/excalidraw_svg/2023-10-08-21-23-31.svg
\t\t ```
\t\t- to create a missing svg file, head to https://excalidraw.com/, paste the .excalidraw file, Click the Hamburger Menu > Export Image
\t\t\t- Enable "Background" and check if you need Dark or Light theme
\t\t\t- Click "SVG" and copy to <vault path>/assets/excalidraw_svgs
\t\t\t- Rename the file so the base names match
\t- ## The svgs for following drawing are missing"""
for draw in missing_svgs:
file_error += f"\n\t\t- `{draw}`"
with open(home_md_file, "a") as f:
f.write(file_error)
else:
eprint("::warning::home-md-file not set for logseq-publish-excalidraw-to-svg, won't write error message to "
"website")
if __name__ == "__main__":
main()

View File

@ -8,3 +8,4 @@ echo ::debug::'$ENCODED' "$ENCODED"
docker ps
curl "localhost:8080/excalidraw/svg/$ENCODED" > "$1.svg"
echo ::debug::"svg: $(cat $1.svg)"

3
wait_for_kroki.sh Normal file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
ENCODED="eNrVm1tT4koXhu_nV1h8twO7z4e58zioM3hARd01ZQUSIBoSTAKIU_Pfv05kk4OJBiVjjFVi0t3pTudhvWutbn9_2dio-fOxUfu2UTMeeppl6q42q30Nrk8N1zMdWxWh8NxzJm4vrDn0_bH37Z9_ohaNnjN6amVYxsiwfU_V-1edb2z8Dn_H-nGNnq_ZA8sIG4RFUVeQ0_TVlmOH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ORTnQZ-X5M8WSqwgEV0IsMUAw2NYPpXJXcXy59j-hIg0BAIGUY8lV8E1QnnLdD-9up_vwYtS51u3D6Tk9Obw-fIt6qr6EVPaYCYKCRLoorp7ZOypLDkpRoj56tUGi-meRTgTzN-7DIDtN0ApmJJuVyu98Fel8bQNKSdWjM_U1AoiVk77FsoiUIhhYclL6f4a8vHz4PindfTB6E78yupm7pkkJFojHg7DXgM_ey_nZ9uEi8veEUzwTTgSopIxIzD4-eavUEGJAMOFCffnF8yAzVya3WX_-eDZAe83NkXt61d--OWuO3iKTOHUUV8nsTeHlqiRaNcZMNRCfRSdRrtVAACDMCcTFdTIblsq72-zvJGOj7P-LMSajSpspJOQjt-u_Txi_b5ejiV8WI6tp43Hb13xjaWxqU9OYbWX9P1h4LO6uZtLUF08TOr5_vvz5PwWZbjk="
until [[ -n "$(curl --silent "localhost:8080/excalidraw/svg/$ENCODED")" ]]; do echo "waiting for kroki"; sleep 1; done