From abfab2a6b86779e1ceff5587f7c5f57041a5c957 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 28 Nov 2020 08:48:47 +0100 Subject: [PATCH] set years from date --- redaktion/red.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/redaktion/red.py b/redaktion/red.py index 2e25e8e..cff54ca 100644 --- a/redaktion/red.py +++ b/redaktion/red.py @@ -62,16 +62,20 @@ def remove_previous_images(previous_images, yml): remove(image_path) -def init_date(): +def init_date_and_years(): yml = yaml.load(get_frontmatters(), Loader=Loader) yml = set_date(yml) + yml = set_years(yml) + lines = get_frontmatters() lines = update_date(yml, lines) + lines = update_years(yml, lines) + content = get_content() with open(get_post_file_path(), "w") as f: f.write("---\n") @@ -129,6 +133,12 @@ def set_date(yml): return yml +def set_years(yml): + yml['years'] = settings_get_date()[0:4] + + return yml + + def get_image_path(yml): return path.join(get_out_path(), get_image_resource_path(yml)) @@ -282,6 +292,10 @@ def update_date(yml, lines): return re.sub("\ndate:.*\n", f"\ndate: {yml['date']}\n",lines) +def update_years(yml, lines): + return re.sub("\nyears:.*\n", f"\nyears: {yml['years']}\n",lines) + + def update_featured_image(yml, lines): return re.sub("\nfeatured_image:.*\n", f"\nfeatured_image: {yml['featured_image']}\n",lines) @@ -480,7 +494,7 @@ def execute_init(): mkdir(image_path) print(f"Image directory created: '{get_image_resource_path(yml)}' ") - init_date() + init_date_and_years() print(f"The next step would be to add your images into the '{get_in_path()}' directory. " f"After that you can update the post directory '{get_out_path()}' and the post file '{post_file_name}': "