# this script will look for each markdown with YAML frontmatter header and will rename the file name to the slug from the title in the header from slugify import slugify # https://pypi.org/project/python-frontmatter/ import os import pyaml import json import frontmatter INP_DIR = "./janco_website/true_content/posts" from pathlib import Path renamed = 0 for path in Path(INP_DIR).rglob('*.md'): print(path) post = frontmatter.load(path) if post['title'].startswith("CHANGE_ME"): continue new_name = slugify.slugify(post['title']) + '.md' if new_name == path: print("same") continue print("rename") os.rename(path, path.parent / ('/' + new_name)) renamed += 1 # path, slugify.slugify(post['title']) print(f"{renamed} files renamed")