-
Notifications
You must be signed in to change notification settings - Fork 0
Add categories and tags placeholders in create post scripts #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mrbiggred
merged 20 commits into
main
from
feature/update-create-post-scripts-with-tags-and-categories
Mar 19, 2026
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c1cc945
Add categories and tags placeholders to blog post templates
mrbiggred 602c2f0
Refactor reminder messages in create_post.sh to be consistent with th…
mrbiggred 5a5618e
Refactor date calculation in create_post.sh for compatibility with ma…
mrbiggred e768f37
Add comment to category and tag section reminding people to use exist…
mrbiggred 7700ed3
Fix indentation in YAML frontmatter comments and correct typo in READ…
mrbiggred 6073e57
Add a script to harvest tags and categories. Initially by Grok, then…
normanlorrain 57a0a98
restored the mistakenly auto-formatted lines
normanlorrain 9e8a387
Refactor find_tags_categories.py to use string parsing instead of YAM…
mrbiggred 17ee852
Printer out tags in alphabetical order
mrbiggred 2ad9497
Moved the find tags script from docs/ to the new scripts/ folder.
mrbiggred a0e47b4
Fixed path to find tags script in create post scripts.
mrbiggred 49848f9
Updated documentation about the find tags script.
mrbiggred 82a366a
Removed unneeded check.
mrbiggred fe91f73
Moved discard tags to outside the loop.
mrbiggred ed97a82
Updated README tag/category examples to match the scripts
mrbiggred f0d1cae
Python should be launched with "py" or "python",
normanlorrain c5317c8
Re-added the YAML library to the find tags script.
mrbiggred ccf9aaa
Guard Python calls in create_post scripts to handle missing Python gr…
mrbiggred 3ad2aac
Fix incorrect return type annotation in extract_frontmatter()
mrbiggred 6884682
Normalize tags/categories to handle scalars and None in find_tags_cat…
mrbiggred File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mrbiggred marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Lists all unique tags and categories found in YAML front matter of .md files. | ||
| Looks for both 'tags' and 'categories' keys (common variations). | ||
| """ | ||
|
|
||
| import yaml | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
| DOCS_DIR = Path(__file__).parent.parent / "docs" | ||
| EXTENSIONS = (".md", ".markdown", ".mkd") | ||
|
|
||
|
|
||
| def extract_frontmatter(file_path: Path) -> dict[str, Any]: | ||
| """Extract YAML front matter if present.""" | ||
| content = file_path.read_text(encoding="utf-8") | ||
| if not content.startswith("---"): | ||
| return {} | ||
| try: | ||
| parts = content.split("---", 2) | ||
| if len(parts) < 3: | ||
| return {} | ||
| fm = yaml.safe_load(parts[1]) | ||
| if not isinstance(fm, dict): | ||
| return {} | ||
| return fm | ||
| except yaml.YAMLError: | ||
| print(f"Warning: Invalid YAML in {file_path}") | ||
| return {} | ||
|
|
||
|
|
||
| def collect_tags() -> tuple[set[str], set[str]]: | ||
| all_tags = set() | ||
| all_categories = set() | ||
|
|
||
| docs_path = Path(DOCS_DIR) | ||
| if not docs_path.is_dir(): | ||
| print(f"Error: Directory not found: {docs_path}") | ||
| return all_tags, all_categories | ||
|
|
||
| for file_path in docs_path.rglob("*"): | ||
| if not file_path.is_file() or file_path.suffix.lower() not in EXTENSIONS: | ||
| continue | ||
|
|
||
| fm = extract_frontmatter(file_path) | ||
|
|
||
| tags = fm.get("tags") or [] | ||
| if isinstance(tags, str): | ||
| tags = [tags] | ||
| elif not isinstance(tags, list): | ||
| tags = [] | ||
| all_tags.update(str(t).strip() for t in tags if t) | ||
|
|
||
| cats = fm.get("categories") or [] | ||
| if isinstance(cats, str): | ||
| cats = [cats] | ||
| elif not isinstance(cats, list): | ||
| cats = [] | ||
| all_categories.update(str(c).strip() for c in cats if c) | ||
|
|
||
| all_tags.discard('TAG_ONE') | ||
| all_tags.discard('TAG_TWO') | ||
| all_categories.discard('CATEGORY_ONE') | ||
| all_categories.discard('CATEGORY_TWO') | ||
|
|
||
| return all_tags, all_categories | ||
|
|
||
|
|
||
| def main() -> None: | ||
| tags, categories = collect_tags() | ||
|
|
||
| print("\nExisting categories:") | ||
| for cat in sorted(categories): | ||
| print(f" {cat}") | ||
| print(f"\nExisting tags:") | ||
| for tag in sorted(tags): | ||
| print(f" {tag}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.