@@ -2037,6 +2037,27 @@ fn load_template_config(template_dir: &Path) -> TemplateConfig {
20372037 } )
20382038}
20392039
2040+ /// `canvas_dir`'s repo HEAD, short form (e.g. `"a1b2c3d"`) — `None` when
2041+ /// `canvas_dir` isn't inside a git working tree, or `git` itself isn't
2042+ /// installed. A canvas exported outside any repo (or by a build machine
2043+ /// without `git`) still gets a static site; it just has no `canvas_commit`
2044+ /// for the template to show.
2045+ fn canvas_git_commit ( canvas_dir : & Path ) -> Option < String > {
2046+ let output = std:: process:: Command :: new ( "git" )
2047+ . args ( [ "-C" , & canvas_dir. to_string_lossy ( ) , "rev-parse" , "--short" , "HEAD" ] )
2048+ . output ( )
2049+ . ok ( ) ?;
2050+ if !output. status . success ( ) {
2051+ return None ;
2052+ }
2053+ let commit = String :: from_utf8 ( output. stdout ) . ok ( ) ?. trim ( ) . to_string ( ) ;
2054+ if commit. is_empty ( ) {
2055+ None
2056+ } else {
2057+ Some ( commit)
2058+ }
2059+ }
2060+
20402061/// Every `node` subcommand's last step before handing a patch back to be
20412062/// written: make sure it still parses — the same validate-before-commit
20422063/// shape every mutating `/api/nodes*` server handler uses.
@@ -2080,6 +2101,13 @@ fn static_cmd(canvas_path: &Path, template_dir: &Path, out_dir: &Path, force: bo
20802101 let mut context = tera:: Context :: new ( ) ;
20812102 context. insert ( "site" , & site) ;
20822103 context. insert ( "icons" , & config. icons ) ;
2104+ // `meshfox_version` is always set (same string `--version` prints —
2105+ // whichever binary is running this export); `canvas_commit` is the
2106+ // canvas's own repo HEAD, short form, and `None` when `canvas_dir` isn't
2107+ // inside a git working tree — a template decides for itself whether to
2108+ // show either at all.
2109+ context. insert ( "meshfox_version" , VERSION ) ;
2110+ context. insert ( "canvas_commit" , & canvas_git_commit ( canvas_dir) ) ;
20832111
20842112 // A proper glob-registered `Tera` instance, not a one-off render per
20852113 // file: a template needs cross-file `{% import %}` to define the
0 commit comments