diff --git a/scripts/new-photo-post b/scripts/new-photo-post index f2ddcb4..e372c45 100755 --- a/scripts/new-photo-post +++ b/scripts/new-photo-post @@ -1,13 +1,14 @@ -#!env/bin/python3 +#!/usr/bin/env python3 # Eryn Wells ''' New script. ''' + import argparse import datetime -import json +import os import os.path import shutil import subprocess @@ -22,6 +23,7 @@ PHOTOS_CONTENT_DIR = 'content/photos' def parse_args(argv, *a, **kw): parser = argparse.ArgumentParser(*a, **kw) + parser.add_argument('-e', '--edit', action='store_true') parser.add_argument('-n', '--dry-run', action='store_true') parser.add_argument('-t', '--title') parser.add_argument('-s', '--slug') @@ -115,9 +117,10 @@ def main(argv): print(f'Failed to create new Hugo post', file=sys.stderr) return -1 + index_file_path = os.path.join(post_path, 'index.md') + if args.title and not args.dry_run: # The hugo command can't set a title for a post so I need to do it myself. - index_file_path = os.path.join(post_path, 'index.md') with open(index_file_path) as index_file: index_file_contents = index_file.readlines() @@ -133,6 +136,10 @@ def main(argv): with open(index_file_path, 'w') as index_file: index_file.writelines(index_file_contents) + if not args.dry_run and args.edit: + editor = os.environ.get('EDITOR', 'vi') + subprocess.run([editor, index_file_path], shell=True) + for photo in args.photos: print(f'Copy {photo} -> {post_path}') try: