Further small cleaning of generate script
This commit is contained in:
parent
e3772d63a3
commit
e0a2d2b83c
1 changed files with 8 additions and 7 deletions
|
@ -37,11 +37,15 @@ def _read_file(path: Path) -> str:
|
||||||
return f.read()
|
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):
|
def generate(config: Config):
|
||||||
|
|
||||||
static_dir = config.source_dir / "static"
|
_replace_content(config.source_dir / "static", config.build_dir / "static")
|
||||||
build_static_dir = config.build_dir / "static"
|
|
||||||
_replace_content(static_dir, build_static_dir)
|
|
||||||
|
|
||||||
template_dir = config.source_dir / "templates"
|
template_dir = config.source_dir / "templates"
|
||||||
header = _read_if_exists(template_dir / "header.html")
|
header = _read_if_exists(template_dir / "header.html")
|
||||||
|
@ -49,11 +53,8 @@ def generate(config: Config):
|
||||||
|
|
||||||
parser = MarkdownIt()
|
parser = MarkdownIt()
|
||||||
sources = config.source_dir.glob("**/*.md")
|
sources = config.source_dir.glob("**/*.md")
|
||||||
|
|
||||||
for source in sources:
|
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)
|
content = _read_file(source)
|
||||||
output = parser.render(content)
|
output = parser.render(content)
|
||||||
|
output_path = _get_transformed_path(config, source, "html")
|
||||||
_write_file(output_path, header + output + footer)
|
_write_file(output_path, header + output + footer)
|
||||||
|
|
Loading…
Reference in a new issue