174 """Copy workspace assets (or bundled fallbacks) into ``site_root/_assets``.
176 Returns the resolved source directory used, or ``None`` when no
177 assets directory was found and nothing was copied.
180 workspace_assets = ws_root / _WORKSPACE_ASSETS_REL
181 target = site_root /
"_assets"
183 if workspace_assets.is_dir():
184 _dbg(
"OCT-DOCS", func, f
"copying workspace assets {workspace_assets} -> {target}", 3)
185 shutil.copytree(workspace_assets, target, dirs_exist_ok=
True)
186 return workspace_assets
188 if _BUNDLED_ASSETS_DIR.is_dir():
189 _dbg(
"OCT-DOCS", func, f
"copying bundled assets {_BUNDLED_ASSETS_DIR} -> {target}", 3)
190 shutil.copytree(_BUNDLED_ASSETS_DIR, target, dirs_exist_ok=
True)
191 return _BUNDLED_ASSETS_DIR
193 _dbg(
"OCT-DOCS", func,
"no asset source found; skipping copy", 3)
198 """Render the front page and write it to ``site_root/index.html``.
203 Workspace root path. Used to find the override template and
204 the workspace ``assets/`` directory.
206 Aggregation directory (``<ws_root>/_site/`` in normal use).
207 Created if it does not exist.
209 Loaded :class:`Workspace` providing the manifest data the
215 The absolute path to the written ``index.html``.
217 func =
"render_front_page"
218 _dbg(
"OCT-DOCS", func, f
"start ws_root={ws_root} site_root={site_root}", 2)
220 site_root.mkdir(parents=
True, exist_ok=
True)
227 from jinja2
import Environment, FileSystemLoader, select_autoescape
229 loader=FileSystemLoader(str(template_path.parent)),
230 autoescape=select_autoescape([
"html",
"j2"]),
231 keep_trailing_newline=
True,
233 template = env.get_template(template_path.name)
234 html = template.render(**context)
236 output = site_root /
"index.html"
237 output.write_text(html, encoding=
"utf-8")
238 _dbg(
"OCT-DOCS", func, f
"wrote {output} ({len(html)} chars)", 3)
242 _dbg(
"OCT-DOCS", func,
"end", 2)
Path|None copy_assets(Path ws_root, Path site_root)
Path resolve_template_path(Path ws_root)
Path render_front_page(Path ws_root, Path site_root, Workspace workspace)
dict[str, Any] build_render_context(Workspace workspace)