From 39ff7724b9f31b8b54dcd791043583955227c880 Mon Sep 17 00:00:00 2001
From: Jake <j.vondoemming@stud.uni-goettingen.de>
Date: Tue, 2 Aug 2022 11:46:01 +0200
Subject: [PATCH] tags working

---
 fgs/generator.py                    | 24 ++++++++++++++----------
 fgs/reader.py                       |  2 +-
 theme/templates/macros/getters.html |  2 +-
 theme/templates/tag.html            | 12 ++++++++++++
 4 files changed, 28 insertions(+), 12 deletions(-)
 create mode 100644 theme/templates/tag.html

diff --git a/fgs/generator.py b/fgs/generator.py
index 540f32b..e620c4a 100644
--- a/fgs/generator.py
+++ b/fgs/generator.py
@@ -42,22 +42,22 @@ class Generator:
         # categories
         categories = {}
         for page in published_pages:
-            if page.category not in categories:
-                categories[page.category] = {}
-            if page.lang not in categories[page.category]:
-                categories[page.category][page.lang] = []
-            categories[page.category][page.lang].append(page)
+            if page.lang not in categories:
+                categories[page.lang] = {}
+            if page.category not in categories[page.lang]:
+                categories[page.lang][page.category] = []
+            categories[page.lang][page.category].append(page)
         self.context['categories'] = categories
 
         # tags
         tags = {}
         for page in published_pages:
             for tag in page.tags:
-                if tag not in tags:
-                    tags[tag] = {}
-                if page.lang not in tags[tag]:
-                    tags[tag][page.lang] = []
-                tags[tag][page.lang].append(page)
+                if page.lang not in tags:
+                    tags[page.lang] = {}
+                if tag not in tags[page.lang]:
+                    tags[page.lang][tag] = []
+                tags[page.lang][tag].append(page)
         self.context['tags'] = tags
 
 
@@ -77,6 +77,10 @@ class Generator:
             for page in self.context['pages'][lang].values():
                 writer.write_template(page.template, page.url, lang, {'page': page})
 
+            # all tags
+            for tag, tagpages in self.context['tags'][lang].items():
+                writer.write_template('tag.html', lang + '/tag/' + tag + '.html', lang, {'tag': tag, 'tagpages': tagpages})
+
             # homepages for languages
             self.generate_homepage(writer, lang, lang + "/index.html")
         
diff --git a/fgs/reader.py b/fgs/reader.py
index 96ddee4..9cc1406 100644
--- a/fgs/reader.py
+++ b/fgs/reader.py
@@ -150,7 +150,7 @@ class MarkdownReader:
         if not isinstance(slug, str):
             raise Exception("slug is not a string: '", slug, "'")
         slug = slug.lower()
-        whitelist = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
+        whitelist = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"
         res = ""
         for c in slug:
             if c in whitelist:
diff --git a/theme/templates/macros/getters.html b/theme/templates/macros/getters.html
index ad8b7e5..1684d18 100644
--- a/theme/templates/macros/getters.html
+++ b/theme/templates/macros/getters.html
@@ -10,7 +10,7 @@
 		{%- endcall -%}
 	{%- endif -%}
 	
-	{{- caller(ns.tagtitle, ns.tagcolor, [lang, 'tag', tagname + '.html']|join('/') , ns.tagpage, tags[tagname][lang]) -}}
+	{{- caller(ns.tagtitle, ns.tagcolor, [lang, 'tag', tagname + '.html']|join('/') , ns.tagpage, tags[lang][tagname]) -}}
 {%- endmacro -%}
 
 {%- macro metadata_entry(slug, lang, key) -%}
diff --git a/theme/templates/tag.html b/theme/templates/tag.html
new file mode 100644
index 0000000..3c0cca1
--- /dev/null
+++ b/theme/templates/tag.html
@@ -0,0 +1,12 @@
+{% extends "base.html" %}
+{% block title -%}
+	{%- call(tagtitle, tagcolor, tagurl, tagpage, tagpages) get.tag_by_name(tag, l) -%}
+		{{ t[l].title_prefix }}{{ t[l].sitename }}{{ t[l].title_suffix }} - {{ tagtitle|e }}
+	{%- endcall -%}
+{%- endblock -%}
+
+{% block content %}
+	<section>
+		{{ render.section({"type": "tag", "tag": tag, "num": None}, l) }}
+	</section>
+{% endblock content %}
-- 
GitLab