|
| 1 | +"""Attach temporary assembly-video players to the matching tutorial pages.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from html import escape |
| 6 | + |
| 7 | +from docutils import nodes |
| 8 | +from sphinx.application import Sphinx |
| 9 | + |
| 10 | + |
| 11 | +VIDEOS = { |
| 12 | + "build/assembly-tutorials/modules/mod-fdr-aseembly": { |
| 13 | + "title": "Feeder module assembly", |
| 14 | + "embed_url": "https://drive.google.com/file/d/1U7WHxCBrBH_LmIhVE-iPwYedeMLx_lZj/preview", |
| 15 | + "watch_url": "https://drive.google.com/file/d/1U7WHxCBrBH_LmIhVE-iPwYedeMLx_lZj/view?usp=drivesdk", |
| 16 | + }, |
| 17 | + "build/assembly-tutorials/modules/mod-lgt": { |
| 18 | + "title": "Light ring module assembly", |
| 19 | + "embed_url": "https://drive.google.com/file/d/11ymhMf_vLa13IoAeG7u0pcYd7CdqgUvQ/preview", |
| 20 | + "watch_url": "https://drive.google.com/file/d/11ymhMf_vLa13IoAeG7u0pcYd7CdqgUvQ/view?usp=drivesdk", |
| 21 | + }, |
| 22 | + "build/assembly-tutorials/modules/mod-pbg-assembly": { |
| 23 | + "title": "Photobeam gate assembly", |
| 24 | + "embed_url": "https://drive.google.com/file/d/1YcfWktCNrZLU985ME6mK09RCsFTdyBYW/preview", |
| 25 | + "watch_url": "https://drive.google.com/file/d/1YcfWktCNrZLU985ME6mK09RCsFTdyBYW/view?usp=drivesdk", |
| 26 | + }, |
| 27 | + "build/assembly-tutorials/modules/mod-scr-assembly": { |
| 28 | + "title": "Screen module assembly", |
| 29 | + "embed_url": "https://drive.google.com/file/d/1W-CbucP4mVNRbWdahoSWfjjUbpiLWMX0/preview", |
| 30 | + "watch_url": "https://drive.google.com/file/d/1W-CbucP4mVNRbWdahoSWfjjUbpiLWMX0/view?usp=drivesdk", |
| 31 | + }, |
| 32 | +} |
| 33 | + |
| 34 | + |
| 35 | +def _append_video(app: Sphinx, doctree: nodes.document, docname: str) -> None: |
| 36 | + video = VIDEOS.get(docname) |
| 37 | + if video is None or app.builder.format != "html": |
| 38 | + return |
| 39 | + |
| 40 | + title = str(video["title"]) |
| 41 | + embed_url = str(video["embed_url"]) |
| 42 | + watch_url = str(video["watch_url"]) |
| 43 | + |
| 44 | + section = nodes.section(ids=["assembly-video-tutorial"]) |
| 45 | + section += nodes.title(text="Assembly video") |
| 46 | + section += nodes.paragraph( |
| 47 | + text=( |
| 48 | + "Use this short visual walkthrough alongside the written instructions. " |
| 49 | + "The parts list, cautions, and checkpoints in this page remain essential." |
| 50 | + ) |
| 51 | + ) |
| 52 | + section += nodes.raw( |
| 53 | + "", |
| 54 | + ( |
| 55 | + '<div class="assembly-video">' |
| 56 | + f'<iframe src="{escape(embed_url, quote=True)}" ' |
| 57 | + f'title="{escape(title, quote=True)}" ' |
| 58 | + 'loading="lazy" allow="autoplay; fullscreen" allowfullscreen ' |
| 59 | + 'referrerpolicy="strict-origin-when-cross-origin"></iframe>' |
| 60 | + "</div>" |
| 61 | + ), |
| 62 | + format="html", |
| 63 | + ) |
| 64 | + |
| 65 | + fallback = nodes.paragraph() |
| 66 | + fallback += nodes.Text("Player unavailable? ") |
| 67 | + fallback += nodes.reference( |
| 68 | + "", |
| 69 | + "Open the temporary video in Google Drive", |
| 70 | + refuri=watch_url, |
| 71 | + internal=False, |
| 72 | + ) |
| 73 | + fallback += nodes.Text(".") |
| 74 | + section += fallback |
| 75 | + |
| 76 | + note = nodes.note() |
| 77 | + note += nodes.paragraph( |
| 78 | + text=( |
| 79 | + "Temporary hosting: this Drive player will be replaced by the project's " |
| 80 | + "YouTube stream after publication; the released original will be archived " |
| 81 | + "on Zenodo. Google may request sign-in until public sharing is confirmed." |
| 82 | + ) |
| 83 | + ) |
| 84 | + section += note |
| 85 | + doctree += section |
| 86 | + |
| 87 | + |
| 88 | +def setup(app: Sphinx) -> dict[str, object]: |
| 89 | + app.connect("doctree-resolved", _append_video) |
| 90 | + return { |
| 91 | + "version": "1.0", |
| 92 | + "parallel_read_safe": True, |
| 93 | + "parallel_write_safe": True, |
| 94 | + } |
0 commit comments