summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorBotond Hende <contact@wazul.moe>2026-05-02 01:28:12 +0200
committerBotond Hende <contact@wazul.moe>2026-05-02 01:40:55 +0200
commit9b99142654b30184992aef9ee201856e4355aa23 (patch)
treead3f5a323bb4244a92209c4a068fa3e8d2987460 /modules
parent389a88088e8f5e40127d024a95c8f63318669b02 (diff)
navbar implemented on blog, comics and codenames
Diffstat (limited to 'modules')
-rw-r--r--modules/blog_generate.py39
-rw-r--r--modules/codenames_generate.py10
-rw-r--r--modules/comic_generate.py10
-rw-r--r--modules/main_generate.py9
4 files changed, 38 insertions, 30 deletions
diff --git a/modules/blog_generate.py b/modules/blog_generate.py
index 3bf21be..4bf3524 100644
--- a/modules/blog_generate.py
+++ b/modules/blog_generate.py
@@ -7,35 +7,40 @@ import jinja2
from . import blogpost_processor
from ..config import Config
+class Cache:
+ POSTS = None
+ TAGS = None
-def generate(jinja_env: jinja2.Environment, output_root_path: str, local: bool):
- if os.path.exists(output_root_path):
- shutil.rmtree(output_root_path)
-
- os.mkdir(output_root_path)
-
- posts = blogpost_processor.get_posts(Config.POST_SOURCE_DIR, local)
+def init(jinja_env: jinja2.Environment, local: bool):
+ Cache.POSTS = blogpost_processor.get_posts(Config.POST_SOURCE_DIR, local)
tag_occurrence_count = {}
- for post in posts:
+ for post in Cache.POSTS:
for tag in post.meta_data[blogpost_processor.TAGS_KEY]:
if tag in tag_occurrence_count:
tag_occurrence_count[tag] += 1
else:
tag_occurrence_count[tag] = 1
- tags = [str(key) for key in tag_occurrence_count.keys()]
- tags.sort(key=lambda key: tag_occurrence_count[key], reverse=True)
- top_tags = tags[:10]
+ Cache.TAGS = [str(key) for key in tag_occurrence_count.keys()]
+ Cache.TAGS.sort(key=lambda key: tag_occurrence_count[key], reverse=True)
+ top_tags = Cache.TAGS[:10]
jinja_env.globals.update(blog={
"blog_name": Config.BLOG_NAME,
+ "blog_url": Config.BLOG_ROOT_URL,
"subtitle": Config.BLOG_SUBTITLE,
"top_tags": top_tags
})
+def generate(jinja_env: jinja2.Environment, output_root_path: str, local: bool):
+ if os.path.exists(output_root_path):
+ shutil.rmtree(output_root_path)
+
+ os.mkdir(output_root_path)
+
blogpost_template = jinja_env.get_template("blogpost.html.j2")
subpage_template = jinja_env.get_template("blogpost_sub.html.j2")
- for post in posts:
+ for post in Cache.POSTS:
output_dir = os.path.join(output_root_path, "posts", post.get_publish_year(), post.name)
os.makedirs(output_dir, exist_ok=True)
for extra_file in post.extra_files:
@@ -69,18 +74,18 @@ def generate(jinja_env: jinja2.Environment, output_root_path: str, local: bool):
ctx = {
"config": Config,
- "tags_ls": " ".join([f'<a href="{tag}.html">{tag}/</a>' for tag in tags]),
+ "tags_ls": " ".join([f'<a href="{tag}.html">{tag}/</a>' for tag in Cache.TAGS]),
"url": f"{Config.BLOG_ROOT_URL}/tags"
}
with open(os.path.join(output_dir, "index.html"), "w") as f:
f.write(tags_template.render(ctx))
tag_template = jinja_env.get_template("tag.html.j2")
- for tag in tags:
+ for tag in Cache.TAGS:
ctx = {
"config": Config,
"tag": tag,
- "posts": [post for post in posts if tag in post.meta_data["tags"]],
+ "posts": [post for post in Cache.POSTS if tag in post.meta_data["tags"]],
"url": f"{Config.BLOG_ROOT_URL}/tags/{tag}.html"
}
with open(os.path.join(output_dir, "{}.html".format(tag)), "w") as f:
@@ -88,7 +93,7 @@ def generate(jinja_env: jinja2.Environment, output_root_path: str, local: bool):
index_template = jinja_env.get_template("index.html.j2")
ctx = {
- "posts": posts,
+ "posts": Cache.POSTS,
"url": Config.BLOG_ROOT_URL
}
with open(os.path.join(output_root_path, "index.html"), "w") as f:
@@ -101,7 +106,7 @@ def generate(jinja_env: jinja2.Environment, output_root_path: str, local: bool):
rss_template = jinja_env.get_template("blog_feed.xml.j2")
ctx = {
"build_date": email.utils.format_datetime(datetime.datetime.now(Config.TIMEZONE)),
- "posts": posts[:5]
+ "posts": Cache.POSTS[:5]
}
with open(os.path.join(output_root_path, Config.RSS_FILE_NAME), "w") as f:
f.write(rss_template.render(ctx))
diff --git a/modules/codenames_generate.py b/modules/codenames_generate.py
index d5aba60..3a56f3b 100644
--- a/modules/codenames_generate.py
+++ b/modules/codenames_generate.py
@@ -10,6 +10,11 @@ import jinja2
from ..config import Config
+def init(jinja_env: jinja2.Environment, local: bool):
+ jinja_env.globals.update(codenames={
+ "codenames_name": Config.CODENAMES_NAME,
+ "codenames_url": Config.CODENAMES_ROOT_URL,
+ })
def generate(jinja_env: jinja2.Environment, output_root_path: str, local: bool):
if os.path.exists(output_root_path):
@@ -17,11 +22,6 @@ def generate(jinja_env: jinja2.Environment, output_root_path: str, local: bool):
os.mkdir(output_root_path)
- jinja_env.globals.update(codenames={
- "codenames_name": Config.CODENAMES_NAME,
- "codenames_url": Config.CODENAMES_ROOT_URL,
- })
-
root_template = jinja_env.get_template("codenames.html.j2")
with open(os.path.join(output_root_path, "index.html"), "w") as f:
f.write(root_template.render({"url" : Config.CODENAMES_ROOT_URL, "title": Config.CODENAMES_NAME}))
diff --git a/modules/comic_generate.py b/modules/comic_generate.py
index cb12161..353a213 100644
--- a/modules/comic_generate.py
+++ b/modules/comic_generate.py
@@ -47,6 +47,12 @@ class Issue:
return self.meta_data[EXTRA_ATTR_KEY] if EXTRA_ATTR_KEY in self.meta_data.keys() else ""
+def init(jinja_env: jinja2.Environment, local: bool):
+ jinja_env.globals.update(comic={
+ "comic_name": Config.COMIC_NAME,
+ "comic_url": Config.COMIC_ROOT_URL,
+ })
+
def get_issues(path: str, local: bool) -> list[Issue]:
return_list = []
@@ -66,10 +72,6 @@ def generate(jinja_env: jinja2.Environment, output_root_path: str, local: bool):
os.mkdir(output_root_path)
- jinja_env.globals.update(comic={
- "comic_name": Config.COMIC_NAME,
- })
-
issues = get_issues(Config.ISSUE_SOURCE_DIR, local)
issue_template = jinja_env.get_template("issue.html.j2")
diff --git a/modules/main_generate.py b/modules/main_generate.py
index 7137537..a166a93 100644
--- a/modules/main_generate.py
+++ b/modules/main_generate.py
@@ -11,16 +11,17 @@ import jinja2
from ..config import Config
+def init(jinja_env: jinja2.Environment, local: bool):
+ jinja_env.globals.update(main={
+ "main_url": Config.MAIN_ROOT_URL,
+ })
+
def generate(jinja_env: jinja2.Environment, output_root_path: str, local: bool):
if os.path.exists(output_root_path):
shutil.rmtree(output_root_path)
os.mkdir(output_root_path)
- jinja_env.globals.update(main={
- "main_url": Config.MAIN_ROOT_URL,
- })
-
root_template = jinja_env.get_template("main.html.j2")
with open(os.path.join(output_root_path, "index.html"), "w") as f:
f.write(root_template.render({"url" : Config.MAIN_ROOT_URL, "title": Config.MAIN_NAME}))