Skip to content
Snippets Groups Projects
Commit 0e31f6bc authored by Lukáš Krupčík's avatar Lukáš Krupčík
Browse files

modified: scripts/maketitle.py

parent d9023adf
No related branches found
No related tags found
1 merge request!486new file: content/docs/anselm/compute-nodes.mdx
#!/usr/bin/python3
"""
Script to process Markdown files, convert them to MDX,
and add frontmatter based on the first H1 heading.
"""
import os
import re
from pathlib import Path
def process_md_file(md_path):
"""
Converts a Markdown file (.md) to MDX format (.mdx),
adds frontmatter with title from H1 heading, and removes the original file.
Args:
md_path (Path): Path to the Markdown file.
"""
try:
with open(md_path, 'r', encoding='utf-8') as f:
content = f.read()
with open(md_path, 'r', encoding='utf-8') as file_handle:
content = file_handle.read()
except UnicodeDecodeError:
print(f"Skipping {md_path} - unable to decode as UTF-8")
return
......@@ -49,14 +61,15 @@ def process_md_file(md_path):
# Create and write MDX file
mdx_path = md_path.with_suffix('.mdx')
with open(mdx_path, 'w', encoding='utf-8') as f:
f.write(new_content)
with open(mdx_path, 'w', encoding='utf-8') as file_handle:
file_handle.write(new_content)
# Remove original MD file
md_path.unlink()
print(f"Converted {md_path} to {mdx_path}")
def main():
"""Walks through directories and processes all Markdown files."""
for root, dirs, files in os.walk('.'):
dirs[:] = [d for d in dirs if not d.startswith('.')]
for file in files:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment