This project automates metadata generation and application for Markdown (.md) files using a local language model (LM Studio). It first generates meaningful metadata (like title, category, summary, and tags), then safely applies it back to the files.
.
├── generate\_metadata.py # Uses LM Studio to extract metadata from Markdown content
├── apply\_metadata.py # Applies generated metadata to frontmatter of files
├── config.example.json # Example config file (copy & rename to config.json before use)
├── metadata\_output.json # Generated metadata (intermediate output)
└── archive/ # Backup of original Markdown files (created on first run)
- Python 3.x
- LM Studio running locally (default API:
http://localhost:1234/v1/chat/completions) - No external Python libraries needed (uses standard library only)
Before running, copy config.example.json to config.json and edit the path:
cp config.example.json config.jsonEdit config.json:
{
"MY_PATH": "path/to/your/markdown/files"
}Replace "path/to/your/markdown/files" with the absolute or relative path to your Markdown directory.
python generate_metadata.py-
Scans all
.mdfiles in the configured folder. -
Uses LM Studio to generate:
titlesummarytagscategory
-
Saves results to
metadata_output.json.
python apply_metadata.py- Reads
metadata_output.json. - Updates each file's frontmatter only if the field exists and is empty.
- Tags are normalized by replacing spaces with underscores.
- Creates backups of original files in
archive/folder before applying changes.
[
{
"filepath": "notes/example.md",
"filename": "example.md",
"title": "Benefits of Morning Walks",
"summary": "Walking early in the morning improves mental clarity and physical health.",
"tags": ["health", "exercise", "morning"],
"category": "health"
}
]- Original
.mdfiles are backed up toarchive/before changes. - Only existing and empty frontmatter fields are updated.
- Tags are automatically cleaned (
"artificial intelligence"→"artificial_intelligence"). <think>...</think>blocks (if any) are stripped from input text before analysis.
- LM Studio must be running locally and accessible at the defined API port.
- The script reads folder path from
config.json. Make sure to rename and edit the example config before running. - This system does not add new frontmatter fields if they don't already exist — it fills in missing values only.
- You can tweak the prompt behavior in
generate_metadata.py:
prompts = {
"category": "Return one simple category label...",
...
}- You can modify
apply_metadata.pyto allow adding new fields or change archiving behavior.
MIT — Use freely, modify safely.