set years from date

This commit is contained in:
2020-11-28 08:48:47 +01:00
parent 3261284ddf
commit abfab2a6b8
+16 -2
View File
@@ -62,16 +62,20 @@ def remove_previous_images(previous_images, yml):
remove(image_path) remove(image_path)
def init_date(): def init_date_and_years():
yml = yaml.load(get_frontmatters(), Loader=Loader) yml = yaml.load(get_frontmatters(), Loader=Loader)
yml = set_date(yml) yml = set_date(yml)
yml = set_years(yml)
lines = get_frontmatters() lines = get_frontmatters()
lines = update_date(yml, lines) lines = update_date(yml, lines)
lines = update_years(yml, lines)
content = get_content() content = get_content()
with open(get_post_file_path(), "w") as f: with open(get_post_file_path(), "w") as f:
f.write("---\n") f.write("---\n")
@@ -129,6 +133,12 @@ def set_date(yml):
return yml return yml
def set_years(yml):
yml['years'] = settings_get_date()[0:4]
return yml
def get_image_path(yml): def get_image_path(yml):
return path.join(get_out_path(), get_image_resource_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) 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): def update_featured_image(yml, lines):
return re.sub("\nfeatured_image:.*\n", f"\nfeatured_image: {yml['featured_image']}\n",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) mkdir(image_path)
print(f"Image directory created: '{get_image_resource_path(yml)}' ") 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. " 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}': " f"After that you can update the post directory '{get_out_path()}' and the post file '{post_file_name}': "