Created
August 11, 2024 03:32
-
-
Save vdbsh/2b2c4f8bcf9d04451204848f031552d4 to your computer and use it in GitHub Desktop.
Generating hugo posts with Python
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
| #!/usr/bin/env python3 | |
| from datetime import datetime, timezone | |
| from platform import system | |
| from subprocess import call | |
| from sys import argv | |
| from os import path | |
| hugo_posts_dir = '/home/user/blog/content/posts' | |
| if __name__ == '__main__': | |
| post_file = path.join(hugo_posts_dir, | |
| f'{argv[1].lower().replace(" ", "-")}.md') | |
| now = datetime.now(tz=timezone.utc) | |
| timestamp = now.strftime('%Y-%m-%dT%H:%M:%SZ') | |
| with open(post_file, 'w') as f: | |
| f.write(f'+++\n' | |
| f'date="{timestamp}"\n' | |
| f'title="{argv[1]}"\n' | |
| f'description=""\n' | |
| f'categories=[]\n' | |
| f'tags=[]\n' | |
| f'cover=""\n' | |
| f'+++\n\n') | |
| os_id = system().lower() | |
| if 'windows' in os_id: | |
| call(('start', post_file)) | |
| elif 'osx' in os_id or 'darwin' in os_id: | |
| call(('open', post_file)) | |
| else: | |
| call(('xdg-open', post_file)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment