Added homepage warning for errornous svgs
This commit is contained in:
parent
ec274c94d9
commit
c6234ec808
@ -1,5 +1,9 @@
|
||||
name: Logseq Excalidraw to SVG
|
||||
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:
|
||||
using: composite
|
||||
steps:
|
||||
@ -10,6 +14,6 @@ runs:
|
||||
python-version: '3.12'
|
||||
# Optional - x64 or x86 architecture, defaults to 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
|
||||
|
||||
|
27
main.py
27
main.py
@ -47,12 +47,20 @@ def main() -> None:
|
||||
: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_any_svgs = False
|
||||
|
||||
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_any_svgs = True
|
||||
else:
|
||||
replace_dict[f"[[{draw}]]"] = f"![{draw}](../{svg})"
|
||||
|
||||
@ -66,6 +74,25 @@ def main() -> None:
|
||||
with open(page, "w") as f:
|
||||
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__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user