#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.11"
# dependencies = []
# ///
# How I start a new blog post:
# bin/newpost.pyt "Who are your draft readers?"
# which creates ~blog/posts/who-are-your-draft-readers.md
# Aug 3, 2025
import os
import sys
from datetime import date
import subprocess
def slugify(text):
return (
text.lower()
.strip()
.encode("ascii", "ignore")
.decode("utf-8")
.replace("’", "")
.replace("'", "")
.replace('"', "")
.replace("&", "and")
.replace("@", "at")
.replace(" ", "-")
.replace("/", "-")
.replace("?", "")
.replace(",", "")
.replace(".", "")
.replace(":", "")
.replace(";", "")
.replace("--", "-")
)
def main():
if len(sys.argv) < 2:
print('Usage: newpost.py "Post Title Here"')
sys.exit(1)
title = sys.argv[1].strip()
slug = slugify(title)[:40]
dt = date.today().isoformat()
post_dir = "content/posts"
os.makedirs(post_dir, exist_ok=True)
filename = f"{slug}.md"
filepath = os.path.join(post_dir, filename)
if not os.path.exists(filepath):
with open(filepath, "w") as f:
f.write(
f"""---
title: "{title}"
date: {dt}
draft: true
tags: []
---
"""
)
print(f"Created {filepath}")
subprocess.call(("open", f"obsidian:///Users/pradeep/quartz/{filepath}"))
if __name__ == "__main__":
main()