chore: add script for removing now redundant frontmatter
This commit is contained in:
parent
67a407153e
commit
fbad4fc2a0
1 changed files with 28 additions and 0 deletions
28
scripts/remove_frontmatter.py
Normal file
28
scripts/remove_frontmatter.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
# Remove 'title' and 'categories' from Yaml frontmatter of old entries
|
||||
import os
|
||||
import re
|
||||
|
||||
# Define the directory
|
||||
directory = "/home/thomas/repos/eolas-bak/zk"
|
||||
|
||||
# Define the regex patterns
|
||||
title_pattern = re.compile(r"title:.*\n")
|
||||
categories_pattern = re.compile(r"categories:.*\n(\s*-.*\n)*")
|
||||
|
||||
# Iterate over all files in the directory
|
||||
for filename in os.listdir(directory):
|
||||
# Check if the file is a markdown file
|
||||
if filename.endswith(".md"):
|
||||
# Open the file
|
||||
with open(os.path.join(directory, filename), "r+") as file:
|
||||
# Read the file content
|
||||
content = file.read()
|
||||
# Remove the 'title' and 'categories' sections
|
||||
content = title_pattern.sub("", content)
|
||||
content = categories_pattern.sub("", content)
|
||||
# Seek to the beginning of the file
|
||||
file.seek(0)
|
||||
# Write the modified content back to the file
|
||||
file.write(content)
|
||||
# Truncate the file to remove any remaining old content
|
||||
file.truncate()
|
Loading…
Add table
Reference in a new issue