192 lines
5.0 KiB
Python
Executable File
192 lines
5.0 KiB
Python
Executable File
#!/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 = """<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>{title} - Puercito Fiction</title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Permanent+Marker&family=Special+Elite&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="styles.css">
|
|
<style>
|
|
body.page {{
|
|
background-color: {bg_color};
|
|
background-image: none;
|
|
align-items: flex-start;
|
|
padding: 2rem;
|
|
}}
|
|
|
|
.page-container {{
|
|
max-width: 800px;
|
|
width: 100%;
|
|
}}
|
|
|
|
.back-link {{
|
|
font-family: 'Special Elite', monospace;
|
|
font-size: 1rem;
|
|
color: #292929;
|
|
text-decoration: none;
|
|
display: inline-block;
|
|
margin-bottom: 2rem;
|
|
transition: color 0.3s ease;
|
|
}}
|
|
|
|
.back-link:hover {{
|
|
color: #E6507D;
|
|
}}
|
|
|
|
.page-content {{
|
|
font-family: 'Special Elite', monospace;
|
|
line-height: 1.8;
|
|
color: #191919;
|
|
}}
|
|
|
|
.page-content h1 {{
|
|
font-family: 'Permanent Marker', cursive;
|
|
font-size: 2.5rem;
|
|
margin-bottom: 1.5rem;
|
|
color: #191919;
|
|
}}
|
|
|
|
.page-content h2 {{
|
|
font-family: 'Permanent Marker', cursive;
|
|
font-size: 1.8rem;
|
|
margin-top: 2rem;
|
|
margin-bottom: 1rem;
|
|
color: #191919;
|
|
}}
|
|
|
|
.page-content p {{
|
|
margin-bottom: 1rem;
|
|
}}
|
|
|
|
.page-content a {{
|
|
color: #E6507D;
|
|
text-decoration: underline;
|
|
}}
|
|
|
|
.page-content a:hover {{
|
|
color: #c93d65;
|
|
}}
|
|
|
|
.page-content ul, .page-content ol {{
|
|
margin-left: 2rem;
|
|
margin-bottom: 1rem;
|
|
}}
|
|
|
|
.page-content li {{
|
|
margin-bottom: 0.5rem;
|
|
}}
|
|
</style>
|
|
</head>
|
|
<body class="page">
|
|
<div class="page-container">
|
|
<a href="index.html" class="back-link">← Back to Home</a>
|
|
<div class="page-content">
|
|
{content}
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
"""
|
|
|
|
# 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()
|