refactor(output): relocate templates with examples
This commit is contained in:
@@ -16,4 +16,4 @@ services:
|
||||
- ../ForRelease/outbox:/data/outbox
|
||||
- ../ForRelease/processed:/data/processed
|
||||
- ../ForRelease/failed:/data/failed
|
||||
- ../../input/templates:/templates:ro
|
||||
- ../templates:/templates:ro
|
||||
|
||||
@@ -20,17 +20,39 @@ OUTBOX = Path("/data/outbox")
|
||||
PROCESSED = Path("/data/processed")
|
||||
FAILED = Path("/data/failed")
|
||||
TEMPLATES = Path("/templates")
|
||||
TEMPLATE_CACHE = Path("/tmp/templates")
|
||||
|
||||
DOCX_TEMPLATE = TEMPLATES / "resume-reference.docx"
|
||||
DOCX_TEMPLATE_EXAMPLE = TEMPLATES / "resume-reference.docx.example"
|
||||
TEX_TEMPLATE = TEMPLATES / "resume-template.tex"
|
||||
TEX_TEMPLATE_EXAMPLE = TEMPLATES / "resume-template.tex.example"
|
||||
|
||||
RESOLVED_DOCX_TEMPLATE: Path | None = None
|
||||
RESOLVED_TEX_TEMPLATE: Path | None = None
|
||||
|
||||
POLL_INTERVAL_SECONDS = 5
|
||||
|
||||
|
||||
def resolve_template(primary: Path, example: Path, cache_dir: Path) -> Path:
|
||||
"""Return the template path, copying .example into a writable cache if needed."""
|
||||
if primary.exists():
|
||||
return primary
|
||||
|
||||
if example.exists():
|
||||
cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
cached = cache_dir / primary.name
|
||||
shutil.copy(example, cached)
|
||||
return cached
|
||||
|
||||
raise FileNotFoundError(f"Template missing: {primary} (no example found)")
|
||||
|
||||
|
||||
def ensure_environment() -> None:
|
||||
"""Verify required files and directories exist before processing starts."""
|
||||
global RESOLVED_DOCX_TEMPLATE, RESOLVED_TEX_TEMPLATE
|
||||
|
||||
missing = []
|
||||
for path in (INBOX, OUTBOX, PROCESSED, FAILED, DOCX_TEMPLATE, TEX_TEMPLATE):
|
||||
for path in (INBOX, OUTBOX, PROCESSED, FAILED, TEMPLATES):
|
||||
if not path.exists():
|
||||
missing.append(str(path))
|
||||
|
||||
@@ -39,6 +61,9 @@ def ensure_environment() -> None:
|
||||
"Required paths are missing inside the container: " + ", ".join(missing)
|
||||
)
|
||||
|
||||
RESOLVED_DOCX_TEMPLATE = resolve_template(DOCX_TEMPLATE, DOCX_TEMPLATE_EXAMPLE, TEMPLATE_CACHE)
|
||||
RESOLVED_TEX_TEMPLATE = resolve_template(TEX_TEMPLATE, TEX_TEMPLATE_EXAMPLE, TEMPLATE_CACHE)
|
||||
|
||||
|
||||
def run_pandoc(input_md: Path, output_docx: Path, output_pdf: Path) -> None:
|
||||
"""Invoke pandoc twice to create DOCX and PDF artifacts."""
|
||||
@@ -51,7 +76,7 @@ def run_pandoc(input_md: Path, output_docx: Path, output_pdf: Path) -> None:
|
||||
"--to",
|
||||
"docx",
|
||||
"--reference-doc",
|
||||
str(DOCX_TEMPLATE),
|
||||
str(RESOLVED_DOCX_TEMPLATE),
|
||||
"--output",
|
||||
str(output_docx),
|
||||
],
|
||||
@@ -67,7 +92,7 @@ def run_pandoc(input_md: Path, output_docx: Path, output_pdf: Path) -> None:
|
||||
"--pdf-engine",
|
||||
"xelatex",
|
||||
"--template",
|
||||
str(TEX_TEMPLATE),
|
||||
str(RESOLVED_TEX_TEMPLATE),
|
||||
"--output",
|
||||
str(output_pdf),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user