add ability to populate slug field

This commit is contained in:
2026-02-07 12:30:28 -06:00
parent e6ef974f5b
commit ddd240d865
3 changed files with 35 additions and 6 deletions
BIN
View File
Binary file not shown.
+10 -2
View File
@@ -1,12 +1,19 @@
# Note Tagging & SEO Automation
Automatically tag your Obsidian notes and add SEO metadata using a local LLM.
Automatically tag your Obsidian notes, add slugs, and add SEO metadata using a local LLM.
The script requires 4 frontmatter fields named as such:
The script requires 5 frontmatter fields named as such:
- tags
- seo-title
- seo-description
- seo-keywords
- slug
**Note:** The script sends only the first 20,000 characters of the note to the LLM. This should be more than sufficient for most notes, however if you have extremely long notes then you can increase this amount by editing the following line in `tag-notes.py`:
```py
llm_response = call_llm(None, body[:20000], taxonomy) # Limit content to first 20000 chars
```
## Setup
@@ -41,6 +48,7 @@ The script will:
- ✓ Add SEO title (clean, non-clickbaity)
- ✓ Add SEO description (150-160 chars, factual)
- ✓ Add SEO keywords (generous, 10-15 keywords)
- ✓ Add slug based off of filename
-**Only updates empty fields** - preserves existing values
- ✓ Updates files directly (no confirmation needed)
-**Only touches**: `tags`, `seo-title`, `seo-description`, `seo-keywords`
+25 -4
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""
Note Tagging and SEO Metadata Script
Processes markdown notes using a local LLM to add tags and SEO metadata
Processes markdown notes using a local LLM to add tags, slugs, and SEO metadata
"""
import os
@@ -129,14 +129,36 @@ def process_note(file_path, taxonomy):
existing_tags = []
needs_tags = not existing_tags
needs_slug = not frontmatter.get('slug')
needs_seo_title = not frontmatter.get('seo-title')
needs_seo_desc = not frontmatter.get('seo-description')
needs_seo_keywords = not frontmatter.get('seo-keywords')
if not (needs_tags or needs_seo_title or needs_seo_desc or needs_seo_keywords):
if not (needs_tags or needs_slug or needs_seo_title or needs_seo_desc or needs_seo_keywords):
print(f" ✓ All fields already populated, skipping")
return
updated = False
# Generate slug from filename if needed
if needs_slug:
# Get filename without extension
filename = Path(file_path).stem
# Convert to lowercase and replace spaces with hyphens
slug = filename.lower().replace(' ', '-')
frontmatter['slug'] = slug
print(f" + Added slug: {slug}")
updated = True
# Only call LLM if we need tags or SEO fields
if not (needs_tags or needs_seo_title or needs_seo_desc or needs_seo_keywords):
# Only needed slug, we're done
new_content = reconstruct_markdown(frontmatter, body)
with open(file_path, 'w', encoding='utf-8') as f:
f.write(new_content)
print(f" ✓ Updated successfully")
return
# Call LLM
llm_response = call_llm(None, body[:20000], taxonomy) # Limit content to first 20000 chars
@@ -145,7 +167,6 @@ def process_note(file_path, taxonomy):
return
# Update frontmatter with new values (only if empty)
updated = False
if needs_tags:
# Combine taxonomy tags and new suggestions
@@ -232,4 +253,4 @@ def main():
print("\n✓ Processing complete!")
if __name__ == "__main__":
main()
main()