Added homepage warning for errornous svgs

This commit is contained in:
Surferlul 2023-10-13 19:03:04 +02:00
parent ec274c94d9
commit c6234ec808
2 changed files with 32 additions and 1 deletions

View File

@ -1,5 +1,9 @@
name: Logseq Excalidraw to SVG name: Logseq Excalidraw to SVG
description: Converts excalidraw to svg references description: Converts excalidraw to svg references
inputs:
home-md-file:
description: Markdown file of the page you see when accessing the published site
required: false
runs: runs:
using: composite using: composite
steps: steps:
@ -10,6 +14,6 @@ runs:
python-version: '3.12' python-version: '3.12'
# Optional - x64 or x86 architecture, defaults to x64 # Optional - x64 or x86 architecture, defaults to x64
architecture: 'x64' architecture: 'x64'
- run: python ${{ github.action_path }}/main.py ${{ github.workspace }} - run: python ${{ github.action_path }}/main.py ${{ github.workspace }} ${{ inputs.home-md-file}}
shell: bash shell: bash

27
main.py
View File

@ -47,12 +47,20 @@ def main() -> None:
:return: :return:
""" """
vault_path = Path(argv[1]).expanduser() 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) pages, draws = get_draws(vault_path)
missing_any_svgs = False
replace_dict = {} replace_dict = {}
for draw, svg in iter_svgs(vault_path, draws): for draw, svg in iter_svgs(vault_path, draws):
if svg is None: if svg is None:
replace_dict[f"[[{draw}]]"] = "<h1 style='color: #ff0000'>MISSING IMAGE</h1>" replace_dict[f"[[{draw}]]"] = "<h1 style='color: #ff0000'>MISSING IMAGE</h1>"
missing_any_svgs = True
else: else:
replace_dict[f"[[{draw}]]"] = f"![{draw}](../{svg})" replace_dict[f"[[{draw}]]"] = f"![{draw}](../{svg})"
@ -66,6 +74,25 @@ def main() -> None:
with open(page, "w") as f: with open(page, "w") as f:
f.write(content) f.write(content)
if missing_any_svgs and home_md_file is not None:
with open(home_md_file, "a") as f:
f.write("\n" + """
- <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
"""
)
if __name__ == "__main__": if __name__ == "__main__":
main() main()