-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhooks.py
More file actions
39 lines (26 loc) · 1020 Bytes
/
hooks.py
File metadata and controls
39 lines (26 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import logging
import subprocess
import time
import jinja2
from pathlib import Path
from typing import Any
from mkdocs.config.defaults import MkDocsConfig
logger = logging.getLogger("mkdocs.hooks")
def do_startswith(value: str, prefix: str) -> bool:
return value.startswith(prefix)
def on_env(env: jinja2.Environment, **kwargs: Any) -> None:
env.tests["startswith"] = do_startswith
def jupyterlite_build(output_dir: str) -> None:
logger.info(f"Building JupyterLite...")
output_dir = Path(output_dir) / "jupyterlite"
lite_dir = Path(__file__).parent / "jupyterlite"
start = time.monotonic()
result = subprocess.run(
("jupyter", "lite", "build", "--lite-dir", lite_dir, "--output-dir", output_dir),
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
result.check_returncode()
logger.info(f"JupyterLite built in {time.monotonic() - start:.2f} seconds")
def on_post_build(config: MkDocsConfig) -> None:
jupyterlite_build(config.site_dir)