2424sys .path .insert (0 , str (SCRIPTS_ROOT ))
2525
2626from helpers .qmd_utils import read_qmd_frontmatter , write_qmd_frontmatter # noqa: E402
27+ from helpers .doc_types import config_for , DEFAULT_FORMATS # noqa: E402
2728
2829
2930ALLOWLIST = {
3637 "version" ,
3738 "keywords" ,
3839 "original-filename" ,
40+ # Kept (not stripped) so fill_version / inject_changelog / strip_llms can
41+ # read it downstream.
42+ "type" ,
3943}
4044
4145EXCLUDED_DIRS = {"templates" , "theme" , "includes" , "_meta" , "_site" , ".quarto" }
@@ -46,17 +50,61 @@ def is_excluded(qmd_path: Path, source_root: Path) -> bool:
4650 return any (part in EXCLUDED_DIRS for part in rel_parts )
4751
4852
53+ def apply_doc_type (fm : dict ) -> None :
54+ """Apply the type config to `fm` in place.
55+
56+ Only OFF toggles do anything (ON == the default), so an untyped doc is
57+ untouched. The frontmatter toggles are done here; version/changelog/llms are
58+ handled later by fill_version / inject_changelog / strip_llms_sidecars, which
59+ read `type` themselves.
60+ """
61+ cfg = config_for (fm .get ("type" ))
62+ els = cfg ["elements" ]
63+
64+ # OFF actions only (ON == existing default == leave frontmatter untouched).
65+ if els ["toc" ] is False :
66+ fm ["toc" ] = False
67+ if els ["number-sections" ] is False :
68+ fm ["number-sections" ] = False
69+ if els ["code" ] is False :
70+ fm ["echo" ] = False # hides code source; Quarto tags the cell .hidden
71+ if els ["contact" ] is False :
72+ fm ["contact" ] = False # honoured by filters/inject_contact_info.lua
73+ if els ["keywords" ] is False :
74+ fm .pop ("keywords" , None ) # no project-level keywords default to leak now
75+ if els ["description" ] is False :
76+ fm .pop ("description" , None )
77+
78+ # style keys + code-fold off when code is off (project defaults it on, which
79+ # would leave fold triangles on hidden cells).
80+ html_opts = dict (cfg ["style" ])
81+ if els ["code" ] is False :
82+ html_opts ["code-fold" ] = False
83+
84+ # A doc `format:` block replaces the project's whole format list (Quarto's
85+ # one non-merging key), so only write it when we're restricting formats or
86+ # setting html options — never for the default.
87+ formats = cfg ["formats" ]
88+ if formats != DEFAULT_FORMATS or html_opts :
89+ fm ["format" ] = {
90+ f : (dict (html_opts ) if f == "html" and html_opts else "default" )
91+ for f in formats
92+ }
93+
94+
4995def strip_one (qmd_path : Path ) -> tuple [bool , list [str ]]:
5096 """Return (changed, dropped_field_names)."""
5197 yaml_data , lines = read_qmd_frontmatter (qmd_path )
5298 if not yaml_data or not lines :
5399 return False , []
54100
55101 dropped = sorted (k for k in yaml_data .keys () if k not in ALLOWLIST )
56- if not dropped :
102+ cleaned = {k : v for k , v in yaml_data .items () if k in ALLOWLIST }
103+ apply_doc_type (cleaned )
104+
105+ if cleaned == yaml_data : # nothing dropped and no type deviations -> no-op
57106 return False , []
58107
59- cleaned = {k : v for k , v in yaml_data .items () if k in ALLOWLIST }
60108 write_qmd_frontmatter (qmd_path , cleaned , lines )
61109 return True , dropped
62110
0 commit comments