I have a question: I use Wordpress right now without giving titles to posts.
I want to move and I think I can deal with themes not working correctly by patching them in some way or another.
My question was what the envisioned authoring flow would be for me. I couldn’t really see it scanning the documentation.
Currently when I click new post, Wordpress will get the next largest ID and let me write something. Is there a way I could automate this without jumping through too many hoops?
OK. Give that the filenames are numbers, the hugo new command needs to be passed a number that is sequentially increasing (or just unique). I think I can deal with that.
#!/usr/bin/env python3
"""
Find the highest numeric folder name in content/posts and return the next available number.
"""
import os
from pathlib import Path
def find_next_available_number(posts_dir='content/posts'):
"""Find the highest numeric folder name and return next available."""
posts_path = Path(posts_dir)
if not posts_path.exists():
print(f"Error: Directory {posts_dir} does not exist")
return None
numeric_folders = []
# Get all directories in content/posts
for item in posts_path.iterdir():
if item.is_dir():
try:
# Try to convert folder name to integer
number = int(item.name)
numeric_folders.append(number)
except ValueError:
# Skip non-numeric folder names
continue
if not numeric_folders:
print("No numeric folders found")
return 1
# Sort the numbers
numeric_folders.sort()
highest = numeric_folders[-1]
next_number = highest + 1
# print(f"Found {len(numeric_folders)} numeric folders")
# print(f"Highest number: {highest}")
print(f"{next_number}")
return next_number
if __name__ == '__main__':
find_next_available_number()
next_number := `uv run find_next_number.py`
_write title:
echo "New path: content/posts/{{ title }}/index.md"
hugo new content/posts/{{ title }}/index.md
code content/posts/{{ title }}/index.md
write slug=next_number: (_write slug)
So I can type:
just write or just write something-about-pets
And it’ll find a new number and open it up in my editor.