diff --git a/src/dialann/site_generator.py b/src/dialann/site_generator.py index b90c02c..5fe2435 100644 --- a/src/dialann/site_generator.py +++ b/src/dialann/site_generator.py @@ -37,11 +37,15 @@ def _read_file(path: Path) -> str: return f.read() +def _get_transformed_path(config: Config, path: Path, ext: str) -> str: + source_dir = path.parent.relative_to(config.source_dir) + filename = str(path.stem) + f".{ext}" + return config.build_dir / source_dir / filename + + def generate(config: Config): - static_dir = config.source_dir / "static" - build_static_dir = config.build_dir / "static" - _replace_content(static_dir, build_static_dir) + _replace_content(config.source_dir / "static", config.build_dir / "static") template_dir = config.source_dir / "templates" header = _read_if_exists(template_dir / "header.html") @@ -49,11 +53,8 @@ def generate(config: Config): parser = MarkdownIt() sources = config.source_dir.glob("**/*.md") - for source in sources: - source_dir = source.parent.relative_to(config.source_dir) - output_path = config.build_dir / source_dir / (str(source.stem) + ".html") - content = _read_file(source) output = parser.render(content) + output_path = _get_transformed_path(config, source, "html") _write_file(output_path, header + output + footer)