sphinx-contrib / video

A sphinx plugin that enables embedding of HTML5 videos
https://sphinxcontrib-video.readthedocs.io
Apache License 2.0
43 stars 29 forks source link

Fix referencing video files from any path #36

Closed QuLogic closed 3 months ago

QuLogic commented 4 months ago

This makes it no longer necessary to place video files in _static, but instead in any location.

I spent a while going through Shinx's implementation for images, and this copies what it does:

  1. File paths are normalized with Environment.relfn2path, and also a dependency is added for the document in the Environment. This allows paths relative to any document.
  2. A post transform adds the files from the Environment to a tracker on the Builder. This causes the HTML5 builder to copy the file to the _images directory (and a unique name is guaranteed by the tracker on the Environment).
  3. The URI is re-written to be relative to the builder image path (only when using HTML output.)

Fixes #33 Because Sphinx then tries to copy the file, it raises a warning if not found, so I think this also fixes (partially) #14. However, if you expected the file to be in the _static directory, it might not warn. I did not check that.

severin-lemaignan commented 4 months ago

I've tested the patch and it works brilliantly for me (also with 2 video sources). Thanks!

12rambau commented 3 months ago

I'll merge it with master once the tests are happy and create a release candidate to let people play with it. As it's changing how images are referenced it's important to give people a heads up.

@QuLogic can you have a look to the mypy issues ?

QuLogic commented 3 months ago

The mypy issue seems unrelated; I can reproduce it on master. I see previous workflows passed, so maybe something in Sphinx changed recently?

QuLogic commented 3 months ago

See #37.

Calinou commented 3 months ago

I see the version was bumped to 0.2.1rc0 in https://github.com/sphinx-contrib/video/commit/098b467ec9b376df9c764e0a37c543926e7452ee. Could this be published on PyPI (perhaps as 0.2.1) so that it can be referenced in Sphinx repositories? This would unblock me for integrating videos on godot-docs. Thanks in advance :slightly_smiling_face:

QuLogic commented 3 months ago

It is on PyPI: https://pypi.org/project/sphinxcontrib-video/0.2.1rc0/ (you'd need to pass --pre to pip install to see it, or explicitly ask for that version.)