LukeCarrier / mkdocs-drawio-exporter

Exports your Draw.io diagrams at build time for easier embedding into your documentation
https://pypi.org/project/mkdocs-drawio-exporter/
MIT License
81 stars 9 forks source link

Multi-page document support, quick start docs #4

Closed darth-veitcher closed 4 years ago

darth-veitcher commented 4 years ago

When running a mkdocs build or mkdocs serve command the following error occurs.

Traceback (most recent call last):
  File "/Users/darthveitcher/.local/share/virtualenvs/myproject-LFrY1FU6/lib/python3.7/site-packages/mkdocsdrawioexporter/mkdocsdrawioexporter.py", line 86, in on_post_build
    mkdocs.utils.copy_file(cache_filename, abs_dest_path)
  File "/Users/darthveitcher/.local/share/virtualenvs/myproject-LFrY1FU6/lib/python3.7/site-packages/mkdocs/utils/__init__.py", line 120, in copy_file
    shutil.copyfile(source_path, output_path)
  File "/Users/darthveitcher/.local/share/virtualenvs/myproject-LFrY1FU6/lib/python3.7/shutil.py", line 120, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/darthveitcher/wip/myproject/docs_src/drawio-exporter/b67cd0c521ac80ff54e5d104542206f8aab93e64'

It seems to be expecting a file here (I'm assuming some kind of generated output) as manually creating a directory here generates an [Errno 21] Is a directory.

Possibly a symptom of needing a more detailed Quick start set of instructions?

darth-veitcher commented 4 years ago

Looks to be an issue when you use files with multiple tabs. Using a single-tabbed file will generate an output.

LukeCarrier commented 4 years ago

Hey @darth-veitcher, thanks for the catch. I can see that there's a CLI option (-p, --page-index) for this.

When you're referencing a single page of a multi-page document, the expected behaviour would be that only a single page is exported, right? In this case, maybe we should have the user include the index of the page in the URL they embed? e.g.:

![Some alt text](my-diagram.drawio#3)

Agreed on the docs point too.

darth-veitcher commented 4 years ago

That would be perfect @LukeCarrier having the page reference as an anchor link.

LukeCarrier commented 4 years ago

Now all of the cleanup and testing is out of the way I've picked this up. I think the best approach is to:

Still gotta figure out how to get the list of pages we care about exporting to the export process in on_post_build()... I'll figure it out.

LukeCarrier commented 4 years ago

WIP branch: https://github.com/LukeCarrier/mkdocs-drawio-exporter/compare/multi-page

LukeCarrier commented 4 years ago

@darth-veitcher I think I have this working now -- if you have time to test it out that'd be great. You could either pull the source down and do pip install --editable from inside the virtualenv you have mkdocs installed to or just install from a Git source:

pip install git+https://github.com/LukeCarrier/mkdocs-drawio-exporter.git@multi-page

If it helps I've thrown a basic test case with a two-page document together below. No additional configuration should be required.

My /test/index.md:

# Testing multi-page diagrams

## Diagram 1

![Diagram 1](diagram.drawio#0)

## Diagram 2

![Diagram 2](diagram.drawio#1)

My /test/diagram.drawio:

<mxfile host="Electron" modified="2019-12-23T22:55:27.739Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/11.3.0 Chrome/76.0.3809.139 Electron/6.0.7 Safari/537.36" etag="3foxywefqy83qYuQ_QeQ" version="11.3.0" type="device" pages="2"><diagram id="ukS30fI4Lm5kd7NlG5mV" name="Page-1">jZJNT4QwEIZ/DUcTPhLsXsVVD2rUNTHxVulAmy0MKV0Bf71lmS6QzSZ76vR5Z/rxzgRJVvWPhjfyBQXoIA5FHyT3QRxHIUvdMpJhIiwkUBolKGkGO/UHvpLoQQloV4kWUVvVrGGOdQ25XTFuDHbrtAL1+taGl3AGdjnX5/RLCSuJRulmFp5AlZKuZvHtJFTcJ9NPWskFdguUbIMkM4h2iqo+Az2a532Z6h4uqKeHGajtVQXwkbJw/6qLZ4Gb90/bfbMbOuWX6wN9+G00JA5JaO3gnTB4qAWMh4VBctdJZWHX8HxUO9d7x6SttNtFLiyU1hlqNMfaRHBgRe54aw3uYaGkOYOfwin0EDAW+os/jE6+uYEDrMCawaVQgXd6WG+7Rd88k4uWpcQ4jUp5Onh20wVkqN/OjTtqi/FPtv8=</diagram><diagram id="rsHniokzqBsc5E8MZI1C" name="Page-2">rZPBToQwEIafhqMJtCviUXFXjdGY7MFzpbO0WhgsRWCf3rK0C+wejIkn2u+fmXb+DgFNi+5es0o8IwcVkJB3Ab0LCInCJLafgfQjSUIHci25C5rAVu7BZzraSA71ItAgKiOrJcywLCEzC8a0xnYZtkO1PLViOZyBbcbUOX2T3AhHo/h6Eh5A5sIdnZCrUSiYD3ad1IJxbGeIrgOaakQzroouBTWY533Z58Wj+DDrHuLyabV/2TQ3Xxdjsc1fUo4taCjN/5YmY+lvphrn1+vgJwmdUJveG6mxKTkMxcKA3rZCGthWLBvU1o6OZcIUyu4iu9xJpVJUqA+5lF9CwleW10bjJ8yUhLzTOLaKuwhoA93Jy/3SdnR8CzvEgAUY3ds8V8W/Xr/ctrNZ8EzMxiB2jLnxy4+FJ4vtwrnst9MwHLTZL0XXPw==</diagram></mxfile>
darth-veitcher commented 4 years ago

Thanks @LukeCarrier ill have a look this week!

LukeCarrier commented 4 years ago

Tested it under Windows 10 and Ubuntu 20.04 dev and we're looking good so far. I'll try to commandeer a Mac soon...

LukeCarrier commented 4 years ago

@darth-veitcher I've merged this and released v0.4.0 after testing -- please holler if something's not working. Merry Christmas! :gift: