|
13 | 13 | logger = logging.getLogger(__name__) |
14 | 14 |
|
15 | 15 |
|
16 | | -@filter('fetch_artwork') |
17 | | -def fetch_artwork_filter(env: BuildEnvironment): |
| 16 | +@filter('fetch_artwork', pass_build_env=True) |
| 17 | +def fetch_artwork_filter(env: BuildEnvironment, id_: str) -> str | None: |
18 | 18 | """ |
19 | 19 | Fetch artwork picture by ID and install theme to Sphinx's source directory, |
20 | 20 | return the relative URI of current doc root. |
21 | 21 | """ |
22 | | - |
23 | | - def _filter(id_: str) -> str | None: |
24 | | - imgdir = '_assets/aw' |
25 | | - imgdir = env.srcdir.joinpath(imgdir) |
26 | | - if Deployment.current() == Deployment.Local: |
27 | | - try: |
28 | | - result = subprocess.run(['/home/la/sync/latree/bin/artworks', 'fetch', id_, imgdir]) |
29 | | - except Exception as e: |
30 | | - errmsg = str(e) |
31 | | - else: |
32 | | - errmsg = f'error code: {result.returncode}' if result.returncode else None |
33 | | - if errmsg: |
34 | | - logger.warning(f'failed to fetch arwork by ID {id_}: {errmsg}') |
35 | | - |
36 | | - f = f'/{imgdir}/{id_}.webp' |
37 | | - return f if path.exists(f) else None |
38 | | - |
39 | | - return _filter |
| 22 | + imgdir = '_assets/aw' |
| 23 | + imgdir = env.srcdir.joinpath(imgdir) |
| 24 | + if Deployment.current() == Deployment.Local: |
| 25 | + try: |
| 26 | + result = subprocess.run(['/home/la/sync/latree/bin/artworks', 'fetch', id_, imgdir]) |
| 27 | + except Exception as e: |
| 28 | + errmsg = str(e) |
| 29 | + else: |
| 30 | + errmsg = f'error code: {result.returncode}' if result.returncode else None |
| 31 | + if errmsg: |
| 32 | + logger.warning(f'failed to fetch arwork by ID {id_}: {errmsg}') |
| 33 | + |
| 34 | + f = f'/{imgdir}/{id_}.webp' |
| 35 | + return f if path.exists(f) else None |
40 | 36 |
|
41 | 37 |
|
42 | 38 | def setup(app: Sphinx): ... |
0 commit comments