summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--generate_me.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/generate_me.py b/generate_me.py
index ae19ebd..a0fcffd 100644
--- a/generate_me.py
+++ b/generate_me.py
@@ -4,6 +4,7 @@ from jinja2 import Environment, FileSystemLoader
from distutils.dir_util import copy_tree
import datetime
import email.utils
+from helper_libs.image_utils import ImageText
templates = Environment(loader=FileSystemLoader("templates"))
src_folder = "Content"
@@ -14,6 +15,11 @@ f_title = "Navan's Archive"
f_description = "Rare Tips, Tricks and Posts"
f_date = email.utils.format_datetime(datetime.datetime.now())
+image_title_color = (74, 74, 74)
+image_line_color = (29,116,132)
+image_title_font = "fonts/futura_bold.ttf"
+image_text_font = "fonts/futura_light.ttf"
+
md = Markdown(extras=["fenced-code-blocks","metadata","task_list","tables","target-blank-links"])
def render_markdown_post(html,metadata=None,template="post.html",posts=[]):
@@ -62,8 +68,27 @@ for x in os.walk(src_folder):
_post["title"] = _post_title
_post["link"] = fpath.replace(src_folder,"").replace("md","html")
_post["tags"] = [x.strip() for x in _post["tags"].split(",")]
+ _post["image_link"] = "/images/opengraph" + fpath.replace(src_folder,"").replace("md","png")
+
+ to_write_path = "./Resources" + _post["image_link"]
+ img = ImageText((1200,630), background=(238,238,238))
+ img.write_text_box((100, 50), _post_title, box_width=1000, font_filename=image_title_font,
+ font_size=65, color=image_title_color, place='center')
+ img.line(shape=[(400, 400), (800, 400)],fill=image_line_color)
+ img.write_text_box((100, 430), f'Tags: {", ".join(_post["tags"])}', box_width=1000, font_filename=image_text_font,
+ font_size=32, color=(0,0,0), place='left')
+ img.write_text_box((100, 400), f'Date: {_post["date"]}', box_width=1000, font_filename=image_text_font,
+ font_size=32, color=(0,0,0), place='left')
+ try:
+ img.save(to_write_path)
+ except FileNotFoundError as e:
+ if not os.path.exists(to_write_path.rsplit("/",1)[0]):
+ os.makedirs(to_write_path.rsplit("/",1)[0])
+ img.save(to_write_path)
+ else:
+ print(e)
+ exit(1)
-
if "draft" in _post:
if _post["draft"] == 'true':
@@ -121,4 +146,6 @@ for post in post_collection_html:
with open(os.path.join(out_folder,"feed.rss"),"w") as f:
f.write(templates.get_template("feed.rss").render(feed={
"title":f_title,"date":f_date,"description":f_description,"link":base_link
- },posts=post_collection_html)) \ No newline at end of file
+ },posts=post_collection_html))
+
+copy_tree(resources_folder,out_folder) \ No newline at end of file