#!/usr/bin/env python3 """ Markdown to HTML converter for Puercito Fiction site. Converts markdown files from content/ directory to HTML files in site/ directory. """ import os from pathlib import Path import markdown # HTML template for generated pages HTML_TEMPLATE = """ {title} - Puercito Fiction
← Back to Home
{content}
""" # Page background colors (muted primary and secondary colors) PAGE_COLORS = { 'about': '#f5e3d9', # muted peach 'comics': '#e3d9f5', # muted lavender 'projects': '#f5f5d9', # muted yellow 'links': '#d9f5e3', # muted teal 'contact': '#f5d9d9', # muted coral 'now': '#d9e3f5', # muted blue 'uses': '#f5dfe3', # muted peach-pink } def convert_markdown_to_html(markdown_file: Path, output_dir: Path): """ Convert a single markdown file to HTML. Args: markdown_file: Path to the markdown file output_dir: Directory to save the HTML file """ # Read markdown content with open(markdown_file, 'r', encoding='utf-8') as f: md_content = f.read() # Convert markdown to HTML md = markdown.Markdown(extensions=['extra', 'codehilite', 'meta']) html_content = md.convert(md_content) # Extract title from filename or first heading title = markdown_file.stem.capitalize() # Get background color for this page (default to white if not specified) page_name = markdown_file.stem bg_color = PAGE_COLORS.get(page_name, '#ffffff') # Fill template full_html = HTML_TEMPLATE.format( title=title, content=html_content, bg_color=bg_color ) # Output file path output_file = output_dir / f"{markdown_file.stem}.html" # Write HTML file with open(output_file, 'w', encoding='utf-8') as f: f.write(full_html) print(f"✓ Converted {markdown_file.name} → {output_file.name}") def main(): """Main build script.""" # Define directories content_dir = Path('content') site_dir = Path('site') # Ensure directories exist if not content_dir.exists(): print(f"Error: {content_dir} directory not found") return if not site_dir.exists(): print(f"Creating {site_dir} directory...") site_dir.mkdir(parents=True) # Find all markdown files md_files = list(content_dir.glob('*.md')) if not md_files: print(f"No markdown files found in {content_dir}") return print(f"Found {len(md_files)} markdown file(s)") print("-" * 50) # Convert each markdown file for md_file in md_files: convert_markdown_to_html(md_file, site_dir) print("-" * 50) print(f"Build complete! HTML files saved to {site_dir}/") if __name__ == '__main__': main()