#!/usr/bin/env python3

from pathlib import Path
import sys
from datetime import datetime

if len(sys.argv) != 4:
	print("Usage:")
	print(" ./newpost.py \"Post Title\" input.txt output.html")
	sys.exit(1)

title = sys.argv[1]
input_file = Path(sys.argv[2])
output_file = Path(sys.argv[3])

content = input_file.read_text()

paragraphs = content.strip().split("\n\n")
html_content = "\n".join(f"<p>{p.strip()}</p>" for p in paragraphs)

date = datetime.now().strftime("%Y-%m-%d")

template = f"""<!doctype html>
<html lang="en">
<head>
  <link rel="stylesheet" href="../static/style.css" type="text/css">
  <link rel='shortcut icon' href='../static/favicon.ico'>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>WKeyser.com - blog</title>
</head>

<body>
<div id="header">
  <h2><a href="../index.html">WKeyser.com</a></h2>
  <p> 
    <a href="../flood.html">blog</a>
    <a href="../about.html">about</a>
    <a href="https://webfreek.net/blog.html">archive</a>
  </p>
  <hr>  
</div> 

<div id="main">  
<h4>{title}</h4>
{html_content}
<br><br>
<p class="date">{date}</p>
</div>

<footer>Copyright Will Keyser 2026</footer>
</body>
</html>
"""

output_file.write_text(template)

print(f"Wrote {output_file}")
