Add a --edit argument to the new-photo-post script
This commit is contained in:
parent
9ce6362402
commit
2d6912aed2
1 changed files with 10 additions and 3 deletions
|
@ -1,13 +1,14 @@
|
||||||
#!env/bin/python3
|
#!/usr/bin/env python3
|
||||||
# Eryn Wells <eryn@erynwells.me>
|
# Eryn Wells <eryn@erynwells.me>
|
||||||
|
|
||||||
'''
|
'''
|
||||||
New script.
|
New script.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -22,6 +23,7 @@ PHOTOS_CONTENT_DIR = 'content/photos'
|
||||||
|
|
||||||
def parse_args(argv, *a, **kw):
|
def parse_args(argv, *a, **kw):
|
||||||
parser = argparse.ArgumentParser(*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('-n', '--dry-run', action='store_true')
|
||||||
parser.add_argument('-t', '--title')
|
parser.add_argument('-t', '--title')
|
||||||
parser.add_argument('-s', '--slug')
|
parser.add_argument('-s', '--slug')
|
||||||
|
@ -115,9 +117,10 @@ def main(argv):
|
||||||
print(f'Failed to create new Hugo post', file=sys.stderr)
|
print(f'Failed to create new Hugo post', file=sys.stderr)
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
index_file_path = os.path.join(post_path, 'index.md')
|
||||||
|
|
||||||
if args.title and not args.dry_run:
|
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.
|
# 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:
|
with open(index_file_path) as index_file:
|
||||||
index_file_contents = index_file.readlines()
|
index_file_contents = index_file.readlines()
|
||||||
|
|
||||||
|
@ -133,6 +136,10 @@ def main(argv):
|
||||||
with open(index_file_path, 'w') as index_file:
|
with open(index_file_path, 'w') as index_file:
|
||||||
index_file.writelines(index_file_contents)
|
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:
|
for photo in args.photos:
|
||||||
print(f'Copy {photo} -> {post_path}')
|
print(f'Copy {photo} -> {post_path}')
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue