From 6d9c4c6c4886795f8a08df561c0b7951c393b6ef Mon Sep 17 00:00:00 2001
From: Jake <j.vondoemming@stud.uni-goettingen.de>
Date: Tue, 2 Aug 2022 00:40:10 +0200
Subject: [PATCH] added cards_from_articles_or_pages() macro

---
 theme/templates/macros/README.md      | 17 +++++++++++++++++
 theme/templates/macros/cards.html     | 14 ++++++++++++++
 theme/templates/macros/renderers.html | 26 +++++---------------------
 3 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/theme/templates/macros/README.md b/theme/templates/macros/README.md
index 59201f4..75ed312 100644
--- a/theme/templates/macros/README.md
+++ b/theme/templates/macros/README.md
@@ -151,6 +151,23 @@ Erstellt eine Kachel von einem Artikel oder einer Seite.
 
 1. `aop` ([Article](https://gaumi-fginfo.pages.gwdg.de/pelican/_build/html/themes.html#article) | [Page](https://gaumi-fginfo.pages.gwdg.de/pelican/_build/html/themes.html#page)): Der Artikel oder die Seite.
 
+
+### `cards_from_articles_or_pages(asops, max = None, standalone = True)`
+
+Erstellt mehrere Kacheln oder einen vollständigen Kachelblock von mehreren Artikeln oder Seiten.
+
+**Argumente:**
+
+1. `asops` (List\<[Article](https://gaumi-fginfo.pages.gwdg.de/pelican/_build/html/themes.html#article) | [Page](https://gaumi-fginfo.pages.gwdg.de/pelican/_build/html/themes.html#page)\>): Die Artikel oder Seiten. Kann auch gemischt sein.
+2. `max` (Int | None): Falls vorhanden werden maximal `max` Kacheln gerendert.
+3. `standalone` (Boolean): Ob `open()` und `close()` automatisch mit ausgeführt werden soll.
+
+**Beispiel Aufruf:**
+
+```
+{{ cards_from_articles_or_pages(all_articles, max=5) }}
+```
+
 ## [renderers.html](renderers.html)
 
 ```
diff --git a/theme/templates/macros/cards.html b/theme/templates/macros/cards.html
index 298c679..bea528c 100644
--- a/theme/templates/macros/cards.html
+++ b/theme/templates/macros/cards.html
@@ -19,3 +19,17 @@
 	{%- endcall -%}
 {%- endmacro -%}
 
+{%- macro cards_from_articles_or_pages(asops, max = None, standalone = True) -%}
+	{%- if standalone -%}
+		{{ open() }}
+	{%- endif -%}
+	{%- for aop in asops -%}
+		{%- if max == None or loop.index < max -%}
+			{{ cards.card_from_article_or_page(aop) }}
+		{%- endif -%}
+	{%- endfor -%}
+	{%- if standalone -%}
+		{{ close() }}
+	{%- endif -%}
+{%- endmacro -%}
+
diff --git a/theme/templates/macros/renderers.html b/theme/templates/macros/renderers.html
index dff958d..698dbcc 100644
--- a/theme/templates/macros/renderers.html
+++ b/theme/templates/macros/renderers.html
@@ -2,13 +2,7 @@
 {%- import 'macros/cards.html' as cards with context -%}
 
 {%- macro section_news(s) -%}
-	{{ cards.open() }}
-	{%- for article in all_articles -%}
-	{%- if loop.index < s.num -%}
-		{{ cards.card_from_article_or_page(article) }}
-	{%- endif -%}
-	{%- endfor -%}
-	{{ cards.close() }}
+	{{ cards.cards_from_articles_or_pages(all_articles, max=s.num) }}
 {%- endmacro -%}
 
 {%- macro section_custom(s) -%}
@@ -30,13 +24,7 @@
 			<h2 {% if s.id is defined -%}id="{{ s.id }}"{%- endif %}>{{ sccat[lang]|e }}</h2>
 		</header>
 	{%- endif -%}
-	{{ cards.open() }}
-	{%- for article in catarticles -%}
-	{%- if loop.index < s.num -%}
-		{{ cards.card_from_article_or_page(article) }}
-	{%- endif -%}
-	{%- endfor -%}
-	{{ cards.close() }}
+	{{ cards.cards_from_articles_or_pages(catarticles, max=s.num) }}
 	{%- endcall -%}
 {%- endmacro -%}
 
@@ -53,13 +41,9 @@
 			</h2>
 		</header>
 	{%- endif -%}
-	{{ cards.open() }}
-	{%- for article in tagarticles -%}
-	{%- if loop.index < s.num -%}
-		{{ cards.card_from_article_or_page(article) }}
-	{%- endif -%}
-	{%- endfor -%}
-	{{ cards.close() }}
+	{{ cards.cards_from_articles_or_pages(tagarticles, max=s.num) }}
+
+
 	{%- endcall -%}
 {%- endmacro -%}
 
-- 
GitLab