add ability to populate slug field
This commit is contained in:
+25
-4
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user