Skip to content

Instantly share code, notes, and snippets.

@kmalloy24
kmalloy24 / md-filename-as-title.py
Last active March 25, 2025 17:13
A Python script that adds the filename as Title frontmatter to all .md or .mdx files in the directory that it is run in.
import os
import re
# Function to generate title from filename
def generate_title(filename):
# Remove the extension
base = os.path.splitext(filename)[0]
# Remove numbers
base = re.sub(r'\d+', '', base)
# Replace dashes and underscores with spaces