diff --git a/blog_template.html b/blog_template.html new file mode 100644 index 0000000..f3ff177 --- /dev/null +++ b/blog_template.html @@ -0,0 +1 @@ +{{%META%}}{{%TITLE%}}
{{%CONTENT%}}
\ No newline at end of file diff --git a/build.py b/build.py index aa8b770..53f1465 100644 --- a/build.py +++ b/build.py @@ -24,6 +24,9 @@ os.makedirs("build") with open("template.html", "r") as template_file: template_text = template_file.read() +with open("blog_template.html", "r") as blog_template_file: + blog_template_text = blog_template_file.read() + with open("meta.json", "r") as meta_file: base_meta = json.load(meta_file) @@ -38,11 +41,11 @@ def parse_meta(meta_data): for key, value in meta_data.get("og", {}).items(): meta_tags.append(f'') - return "\n".join(meta_tags) + return "".join(meta_tags) -def generate_html_content(directory, filename): - """Generate HTML content from a markdown file and meta data.""" +def generate_html_content(directory, filename, is_blog=False): + """Generate HTML content from a markdown file and metadata.""" file_path = os.path.join(directory, filename) with open(file_path, "r") as file: @@ -56,8 +59,10 @@ def generate_html_content(directory, filename): meta_data = parse_meta(meta) + template_to_use = blog_template_text if is_blog else template_text + return ( - template_text.replace("{{%CONTENT%}}", markdown_renderer(md_text)) + template_to_use.replace("{{%CONTENT%}}", markdown_renderer(md_text)) .replace("{{%TITLE%}}", meta.get("title", "")) .replace("{{%META%}}", meta_data) ) @@ -86,9 +91,13 @@ def process_content_directory(source_dir, target_dir): process_content_directory(source_path, target_path) else: if filename.endswith(".md"): + is_blog = "blog" in os.path.relpath(source_path, start="content").split( + os.sep + ) + html_filename = os.path.splitext(filename)[0] + ".html" output_file = os.path.join(target_dir, html_filename) - content = generate_html_content(source_dir, filename) + content = generate_html_content(source_dir, filename, is_blog=is_blog) with open(output_file, "w") as file: file.write(content) diff --git a/template.html b/template.html index c6f07cf..065d47e 100644 --- a/template.html +++ b/template.html @@ -1,47 +1 @@ - - - - - - - - {{%META%}} - - - - - - - - - - - - - {{%TITLE%}} - - - - -
- {{%CONTENT%}} -
- - - - +{{%META%}}{{%TITLE%}}
{{%CONTENT%}}
\ No newline at end of file