From a2653e185c2151dde1eefca1199a6819fe2b8c04 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 4 Mar 2023 10:25:04 -0800 Subject: [PATCH] For new photo posts use YYYY/name if possible, and fall back on YYYY/MM/name if not --- scripts/new-photo-post.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/new-photo-post.py b/scripts/new-photo-post.py index fed79c5..a4005e0 100755 --- a/scripts/new-photo-post.py +++ b/scripts/new-photo-post.py @@ -48,7 +48,20 @@ def main(argv): month = earliest_exif_date.month name = args.title if args.title else os.path.splitext(os.path.basename(photo))[0] - post_path = os.path.join(PHOTOS_CONTENT_DIR, f'{year:04}', f'{month:02}', name) + + post_path_year = os.path.join(PHOTOS_CONTENT_DIR, f'{year:04}', name) + post_path_year_month = os.path.join(PHOTOS_CONTENT_DIR, f'{year:04}', f'{month:02}', name) + + if os.path.exists(post_path_year): + if os.path.exists(post_path_year_month): + print("Couldn't find path for photo post. Both of the following paths exist.", file=sys.stderr) + print(f' {post_path_year}', file=sys.stderr) + print(f' {post_path_year_month}', file=sys.stderr) + return -1 + else: + post_path = post_path_year_month + else: + post_path = post_path_year try: hugo_command = ['hugo', 'new', '--clock', earliest_exif_date.isoformat(), post_path]