Skip to content
Snippets Groups Projects
Verified Commit 018a4fd4 authored by Jake's avatar Jake :speech_balloon:
Browse files

added custom renderer

parent 1ee4528c
No related branches found
No related tags found
No related merge requests found
Pipeline #313198 passed
Showing
with 1145 additions and 3 deletions
......@@ -48,6 +48,16 @@
"only_pages": {
"title": "Seiten"
},
"no_content": "Diese Seite hat noch keine Inhalte."
"no_content": "Diese Seite hat noch keine Inhalte.",
"quotations": {
"double": {
"left": "„",
"right": "“"
},
"single": {
"left": "‚",
"right": "‘"
}
}
}
}
{% extends "base.html" %}
{%- macro article_translation_link(translation, is_current=False) -%}
<a href="{{ SITEURL }}/{{ translation.url }}" hreflang="{{ translation.lang }}" title="{{ l[translation.lang].langname|e }}">
<img alt="{{ l[translation.lang].langname|e }}" src="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/images/flags/{{ translation.lang }}.svg">
</a>
{%- endmacro -%}
{% block html_lang %}{{ article.lang }}{% endblock %}
{% block title %}{{ article.title|striptags }}{% endblock %}
{% block extra_head %}
{%- for translation in article.translations -%}
<link rel="alternate" hreflang="{{ translation.lang }}" href="{{ SITEURL }}/{{ translation.url }}">
{%- endfor -%}
{% if article.summary %}
<meta name="description" content="{{ article.summary | striptags | safe | truncate(150) }}" />
{% endif %}
{% endblock %}
{% block content %}
<article>
<header>
<h1>{{ article.title }}</h1>
</header>
{{ article.content }}
<footer>
{%- if article.authors -%}
<address>
{{ l[lang].article.authors_prefix }}
{% for author in article.authors %}
<a href="{{ SITEURL }}/{{ author.url }}">{{ author }}</a>
{% endfor %}
{{ l[lang].article.authors_suffix }}
</address>
{%- endif -%}
<span>{{ l[lang].article.published_prefix }}
<abbr title="{{ article.date.isoformat() }}">
{{ article.locale_date }}
</abbr>{{ l[lang].article.published_suffix }}</span>
{%- if article.modified -%}
<br />
<span>{{ l[lang].article.modified_prefix }}
<abbr title="{{ article.modified.isoformat() }}">{{ article.locale_modified }}</abbr>
{{ l[lang].article.modified_suffix }}</span>
{%- endif -%}
<br />
<span>{{ l[lang].article.category_prefix }}<a href="{{ SITEURL }}/{{ article.category.url }}">{{ article.category }}</a>{{ l[lang].article.category_suffix }}</span>
<br />
<span>{{ l[lang].article.languages_prefix }}</span>
<ul class="languages">
{%- for translation in article.translations -%}
<li>
{{ article_translation_link(translation) }}
</li>
{%- endfor -%}
<li>
{{ article_translation_link(article, True) }}
</li>
</ul>
{{ l[lang].article.languages_suffix }}
</footer>
</article>
{% endblock %}
<!DOCTYPE html>
{#- TODO lang irgendwie vernünftig setzen/erkennen -#}
{%- if lang is not defined -%}
{%- set lang = DEFAULT_LANG -%}
{%- else -%}
Hurra!!! lang ist definiert als {{ lang }}.
{{ diese_variable_existiert_nicht_werfe_fehler }}
{%- endif -%}
{%- import 'macros/getters.html' as get with context -%}
{%- import 'macros/cards.html' as cards with context -%}
{%- import 'macros/renderers.html' as render with context -%}
<html lang="{%- block html_lang -%}{{ DEFAULT_LANG }}{%- endblock html_lang -%}">
<head>
{% block head %}
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}{{ l[lang].title_prefix }}{{ l[lang].sitename }}{{ l[lang].title_suffix }}{%endblock%}</title>
<!-- <base target="_blank"> -->
<!-- <meta HTTP-EQUIV="REFRESH" content="500; url=#"> -->
<link rel="preload" href="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/css/{{ CSS_FILE }}" as="style" />
<link rel="stylesheet" type="text/css" href="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/css/{{ CSS_FILE }}" />
{#- TODO load javascript? -#}
{#- TODO og: meta tags -#}
{#- TODO favicon -#}
<!-- <link rel="icon" type="image/png" sizes="192x192" href="static/img/favicon-192x192.png"/>
<link rel="icon" type="image/png" sizes="32x32" href="static/img/favicon-32x32.png"/>-->
<!-- <link rel="icon" type="image/x-icon" sizes="16x16" href="static/img/favicon.ico"/> -->
{%- if FEED_ALL_ATOM %}
<link href="{{ FEED_DOMAIN }}/{% if FEED_ALL_ATOM_URL %}{{ FEED_ALL_ATOM_URL }}{% else %}{{ FEED_ALL_ATOM }}{% endif %}" type="application/atom+xml" rel="alternate" title="{{ l[lang].atom.title|e }}" />
{% endif -%}
{% block extra_head %}{% endblock extra_head %}
{% endblock head %}
</head>
<body>
<header>
{% block header %}
<h1><a href="{{ SITEURL }}/" title="{{ l[lang].banner.title|e }}" ><img alt="{{ l[lang].banner.alt|e }}" src="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/images/banner-logo.png"><span>{{ l[lang].banner.prefix|e }}{{ l[lang].sitename|e }}{{ l[lang].banner.suffix|e }}</span></a></h1>
{% block extra_header %}{% endblock extra_header %}
{% endblock header %}
</header>
<div class="nav-container">
<label for="show-header-menu" class="show-header-menu">&#9776;</label>
<input type="checkbox" id="show-header-menu" role="button">
<label for="show-header-menu" class="show-header-menu-bg"> </label>
<nav>
<ul>
{% for item in sc.menuitems -%}
{%- if item.category is defined -%}
{%- call(nativecat, sccat, _) get.category_by_name(item.category) -%}
<li style="--category-color: {{ sccat.color }}"><a href="{{ SITEURL }}/{{ nativecat.url }}">{{ sccat[lang]|e }}</a></li>
{%- endcall -%}
{%- elif item.tag is defined -%}
{%- call(nativetag, sccat, _) get.tag_by_name(item.tag) -%}
<li style="--category-color: {{ sccat.color }}"><a href="{{ SITEURL }}/{{ nativetag.url }}">{{ sccat[lang]|e }}</a></li>
{%- endcall -%}
{%- elif item.slug is defined -%}
{%- call(aop, _) get.article_or_page_by_slug(item.slug, lang) -%}
{%- call(__, sccat, ___) get.category_by_name(aop.category.name, True) -%}
<li style="--category-color: {{ sccat.color }}"><a href="{{ SITEURL }}/{{ aop.url }}">{{ aop.title }}</a></li>
{%- endcall -%}
{%- endcall -%}
{%- else -%}
<br />
<strong>ERROR: menuitems: Cannot parse item: {{ item|string|e }}</strong><br />
<br />
{%- endif -%}
{#- TODO add active class if this is the current site -#}
{%- endfor %}
</ul>
</nav>
</div>
<main>
{% block content %}
{% endblock content %}
</main>
<footer>
{% block footer %}
{#- TODO besserer footer -#}
<div>
<a href="https://asta.uni-goettingen.de/impressum/datenschutz/">Datenschutz</a>
<a href="/fg-website/Impressum.md">Impressum</a>
<div>
<div>Fachgruppe Informatik Göttingen, 2022.</div>
<!-- blablabla datenschutz,impressum etc... -->
{% block extra_footer %}{% endblock extra_footer %}
{% endblock footer %}
</footer>
</body>
<!-- The Cake Is A Lie! -->
</html>
{% extends "base.html" %}
{% block title %}{{ l[lang].title_prefix }}{{ l[lang].sitename }}{{ l[lang].title_suffix }} - {{ category }}{%endblock%}
{% block content %}
<section>
{{ render.section({"type": "category", "category": category.slug, "num": None}) }}
</section>
{% endblock content %}
{% extends "base.html" %}
{% block content_title %}{% endblock %}
{% block content %}
{%- for s in sc.startpage -%}
<section>
{{ render.section(s) }}
</section>
{%- endfor -%}
{% endblock content %}
# Macros
[TOC]
## [getters.html](getters.html)
```
{%- import 'macros/getters.html' as get with context -%}
```
Mit diesen Macros können Informationen abgefragt werden.
### `category_by_name(catname, ignore_native = False)`
**Argumente:**
- `catname` (String): Der Name der Kategorie.
- `ignore_native` (Boolean): Setzt den ersten und dritten Rückgabewert zu `None`. (Verkürzt die Laufzeit dieser Funktion.)
**Rückgabewerte:**
1. ([Category](https://gaumi-fginfo.pages.gwdg.de/pelican/_build/html/themes.html#object-author-cat-tag)): Die native Kategorie.
2. (Dict): Der Eintrag zu der Kategorie aus der config.json-Datei aus dem Inhaltsrepo.
3. (List\<[Article](https://gaumi-fginfo.pages.gwdg.de/pelican/_build/html/themes.html#article)\>): Die Artikel in der Kategorie.
**Beispiel Aufruf:**
```
{%- call(nativecat, sccat, catarticles) get.category_by_name(article.category.name) -%}
<ul>
<li>Kategorie: {{ nativecat.name }}</li>
<li>Farbe: {{ sccat.color }}</li>
<li>Anzahl Artikel: {{ catarticles|length }}</li>
</ul>
{%- endcall -%}
```
### `tag_by_name(tagname)`
**Argumente:**
- `catname` (String): Der Name des Tags.
**Rückgabewerte:**
1. ([Tag](https://gaumi-fginfo.pages.gwdg.de/pelican/_build/html/themes.html#object-author-cat-tag)): Der native Tag.
2. (Dict): Falls der Tag gleichnamig zu einer Kategorie ist, dann der Eintrag zu der Kategorie aus der config.json-Datei aus dem Inhaltsrepo, sonst `None`.
3. (List\<[Article](https://gaumi-fginfo.pages.gwdg.de/pelican/_build/html/themes.html#article)\>): Die Artikel die diesen Tag haben.
**Beispiel Aufruf:**
```
{%- call(nativetag, sccat, tagarticles) get.tag_by_name("event") -%}
<ul>
<li>Tag: {{ nativetag.name }}</li>
<li>Farbe: {% if sccat %}{{ sccat.color }}{% else %}Dieser Tag ist nicht gleichnamig zu einer Kategorie und hat deshalb keine Farbe.{% endif %}</li>
<li>Anzahl Artikel mit diesem Tag: {{ tagarticles|length }}</li>
</ul>
{%- endcall -%}
```
### `article_by_slug(slug, lang)`
**Argumente:**
- `slug` (String): Der Slug von dem Artikel.
- `lang` (String): Die Sprache von dem Artikel.
**Rückgabewerte:**
1. ([Article](https://gaumi-fginfo.pages.gwdg.de/pelican/_build/html/themes.html#article)): Der Artikel.
### `page_by_slug(slug, lang)`
**Argumente:**
- `slug` (String): Der Slug von der Seite.
- `lang` (String): Die Sprache von der Seite.
**Rückgabewerte:**
1. ([Page](https://gaumi-fginfo.pages.gwdg.de/pelican/_build/html/themes.html#page)): Die Seite.
### `article_or_page_by_slug(slug, lang)`
**Argumente:**
- `slug` (String): Der Slug von dem Artikel oder der Seite.
- `lang` (String): Die Sprache von dem Artikel oder der Seite.
**Rückgabewerte:**
1. ([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.
2. (String): "article" falls es ein Artikel ist. "page" falls es eine Seite ist.
## [cards.html](cards.html)
```
{%- import 'macros/cards.html' as cards with context -%}
```
Mit diesen Macros können Kachelblöcke erstellt werden.
In einem Kachelblock dürfen nur Kacheln sein und sonst nichts!
**Beispiel:**
```
{{ cards.open() }}
{%- for article in all_articles -%}
{{ cards.card_from_article_or_page(article) }}
{%- endfor -%}
{{ cards.card(title="Dies ist auch eine Kachel", url="https://www.youtube.com/watch?v=dQw4w9WgXcQ", catcolor="green") }}
{{ cards.close() }}
```
### `open(id = None, classes = None)`
Beginnt einen Kachelblock.
**Argumente:**
- `id` (String): Die ID von dem Kachelblock.
- `classes` (List\<String\>): Zusätzliche Klassen für den Kachelblock.
### `close()`
Schließt einen Kachelblock.
### `card(title, url, catcolor, escape_title = True, is_url_external = True)`
Erstellt eine Kachel.
**Argumente:**
- `title` (String): Der Titel.
- `url` (String): Der URL.
- `catcolor` (String): Die Farbe.
- `escape_title` (Boolean): Ob `title` escaped werden soll.
- `is_url_external` (Boolean): Ob `url` auf eine externe Resource zeigt, oder als relativen Link interpretiert werden soll.
### `card_from_article_or_page(aop)`
Erstellt eine Kachel von einem Artikel oder einer Seite.
**Argumente:**
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)
```
{%- import 'macros/renderers.html' as render with context -%}
```
**TODO: ** Die Dokumentation für diese Macros ist abhängig von der Dokumentation von der config.json-Datei im Inhaltsrepo.
### `section_news(s)`
### `section_custom(s)`
### `section_iframe(s)`
### `section_category(s)`
### `section_tag(s)`
### `section(s)`
{%- import 'macros/getters.html' as get with context -%}
{%- macro open(id = None, classes = None) -%}
<ul {%- if id %} id="{{ id|e }}"{% endif %} class="cards {%- if classes %}{% for class in classes %} {{ class|e }}{% endfor %}{% endif %}">
{%- endmacro -%}
{%- macro close() -%}
</ul>
{%- endmacro -%}
{%- macro card(title, url, catcolor, escape_title = True, is_url_external = True) -%}
<li style="--category-color: {{ catcolor }}"><a href="{% if not is_url_external %}{{ SITEURL }}/{% endif %}{{ url }}">{% if escape_title %}{{ title|e }}{% else %}{{ title }}{% endif %}</a></li>
{%- endmacro -%}
{%- macro card_from_article_or_page(aop) -%}
{%- call(_, sccat, __) get.category_by_name(aop.category.name, True) -%}
{{ card(title=aop.title, url=aop.url, catcolor=sccat.color, escape_title=False, is_url_external = False) }}
{%- 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 -%}
{%- macro category_by_name(catname, ignore_native = False) -%}
{%- if ignore_native -%}
{{- caller(None, sc.categories[catname], None) -}}
{%- else -%}
{%- for nativecat, catarticles in categories -%}
{%- if nativecat.name == catname -%}
{{- caller(nativecat, sc.categories[catname], catarticles) -}}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endmacro -%}
{%- macro tag_by_name(tagname) -%}
{%- for nativetag, tagarticles in tags -%}
{%- if nativetag.name == tagname -%}
{%- if tagname in sc.categories -%}
{{- caller(nativetag, sc.categories[tagname], tagarticles) -}}
{%- else -%}
{{- caller(nativetag, None, tagarticles) -}}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- endmacro -%}
{%- macro article_by_slug(slug, lang) -%}
{%- for a in all_articles -%}
{%- if a.slug == slug and a.lang == lang -%}
{{- caller(a) -}}
{%- endif -%}
{%- endfor -%}
{%- endmacro -%}
{%- macro page_by_slug(slug, lang) -%}
{%- for p in pages -%}
{%- if p.slug == slug and p.lang == lang -%}
{{- caller(p) -}}
{%- endif -%}
{%- endfor -%}
{%- endmacro -%}
{%- macro article_or_page_by_slug(slug, lang) -%}
{%- for a in all_articles -%}
{%- if a.slug == slug and a.lang == lang -%}
{{- caller(a, "article") -}}
{%- endif -%}
{%- endfor -%}
{%- for p in pages -%}
{%- if p.slug == slug and p.lang == lang -%}
{{- caller(p, "page") -}}
{%- endif -%}
{%- endfor -%}
{%- endmacro -%}
{%- import 'macros/getters.html' as get with context -%}
{%- import 'macros/cards.html' as cards with context -%}
{%- macro section_news(s) -%}
{{ cards.cards_from_articles_or_pages(all_articles, max=s.num) }}
{%- endmacro -%}
{%- macro section_custom(s) -%}
{{ cards.open() }}
{%- for c in s.content -%}
{{ cards.card(title=c[lang], url=c.url, catcolor=c.color) }}
{%- endfor -%}
{{ cards.close() }}
{%- endmacro -%}
{%- macro section_iframe(s) -%}
<iframe src="{{ s.url }}"></iframe>
{%- endmacro -%}
{%- macro section_category(s) -%}
{%- call(nativecat, sccat, catarticles) get.category_by_name(s.category) -%}
{%- if s.title is not defined -%}
<header>
<h2 {% if s.id is defined -%}id="{{ s.id }}"{%- endif %}>{{ sccat[lang]|e }}</h2>
</header>
{%- endif -%}
{{ cards.cards_from_articles_or_pages(catarticles, max=s.num) }}
{%- endcall -%}
{%- endmacro -%}
{%- macro section_tag(s) -%}
{%- call(nativetag, sccat, tagarticles) get.tag_by_name(s.tag) -%}
{%- if s.title is not defined -%}
<header>
<h2 {% if s.id is defined -%}id="{{ s.id }}"{%- endif %}>
{%- if sccat -%}
{{- sccat[lang]|e -}}
{%- else -%}
{{- s.tag|e -}}
{%- endif -%}
</h2>
</header>
{%- endif -%}
{{ cards.cards_from_articles_or_pages(tagarticles, max=s.num) }}
{%- endcall -%}
{%- endmacro -%}
{%- macro section(s) -%}
{%- if s.title is defined -%}
<header>
<h2 {% if s.id is defined -%}id="{{ s.id }}"{%- endif %}>{{ s.title[lang]|e }}</h2>
</header>
{%- endif -%}
{%- if s.type == "news" -%}
{{ section_news(s) }}
{%- elif s.type == "iframe" -%}
{{ section_iframe(s) }}
{%- elif s.type == "custom" -%}
{{ section_custom(s) }}
{%- elif s.type == "category" -%}
{{ section_category(s) }}
{%- elif s.type == "tag" -%}
{{ section_tag(s) }}
{%- else -%}
<br />
<strong>ERROR: render.section: Unknown section type: {{ s.type|e }}</strong><br />
<br />
{%- endif -%}
{%- endmacro -%}
{% extends "base.html" %}
{%- macro page_translation_link(translation, is_current=False) -%}
<a href="{{ SITEURL }}/{{ translation.url }}" hreflang="{{ translation.lang }}" title="{{ l[translation.lang].langname|e }}">
<img alt="{{ l[translation.lang].langname|e }}" src="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/images/flags/{{ translation.lang }}.svg">
</a>
{%- endmacro -%}
{% block html_lang %}{{ page.lang }}{% endblock %}
{% block title %}{{ page.title|striptags }}{% endblock %}
{% block extra_head %}
{%- for translation in page.translations -%}
<link rel="alternate" hreflang="{{ translation.lang }}" href="{{ SITEURL }}/{{ translation.url }}">
{%- endfor -%}
{% if page.summary %}
<meta name="description" content="{{ page.summary | striptags | safe | truncate(150) }}" />
{% endif %}
{% endblock %}
{% block content %}
<article>
<header>
<h1>{{ page.title }}</h1>
</header>
{{ page.content }}
<footer>
{%- if page.authors -%}
<address>
{{ l[lang].page.authors_prefix }}
{% for author in page.authors %}
<a href="{{ SITEURL }}/{{ author.url }}">{{ author }}</a>
{% endfor %}
{{ l[lang].page.authors_suffix }}
</address>
{%- endif -%}
<span>{{ l[lang].page.published_prefix }}
<abbr title="{{ page.date.isoformat() }}">
{{ page.locale_date }}
</abbr>{{ l[lang].page.published_suffix }}</span>
{%- if page.modified -%}
<br />
<span>{{ l[lang].page.modified_prefix }}
<abbr title="{{ page.modified.isoformat() }}">{{ page.locale_modified }}</abbr>
{{ l[lang].page.modified_suffix }}</span>
{%- endif -%}
<br />
<span>{{ l[lang].page.category_prefix }}<a href="{{ SITEURL }}/{{ page.category.url }}">{{ page.category }}</a>{{ l[lang].page.category_suffix }}</span>
<br />
<span>{{ l[lang].page.languages_prefix }}</span>
<ul class="languages">
{%- for translation in page.translations -%}
<li>
{{ page_translation_link(translation) }}
</li>
{%- endfor -%}
<li>
{{ page_translation_link(page, True) }}
</li>
</ul>
{{ l[lang].page.languages_suffix }}
</footer>
</article>
{% endblock %}
{% extends "base.html" %}
{% block title %}{{ l[lang].title_prefix }}{{ l[lang].sitename }}{{ l[lang].title_suffix }} - {{ tag }}{%endblock%}
{% block content %}
<section>
{{ render.section({"type": "tag", "tag": tag.slug, "num": None}) }}
</section>
{% endblock content %}
......@@ -3,6 +3,7 @@
{%- import 'macros/getters.html' as get with context -%}
{%- import 'macros/cards.html' as cards with context -%}
{%- import 'macros/renderers.html' as render with context -%}
{%- import 'macros/content_renderer.html' as content_renderer with context -%}
<html lang="{%- block html_lang -%}{{ l }}{%- endblock html_lang -%}">
<head>
......@@ -25,6 +26,8 @@
{% endif -%}#}
{% block extra_head %}{% endblock extra_head %}
{% endblock head %}
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
</head>
<body>
<header>
......
# Macros
[TOC]
## [getters.html](getters.html)
```
{%- import 'macros/getters.html' as get with context -%}
```
Mit diesen Macros können Informationen abgefragt werden.
### `category_by_name(catname, ignore_native = False)`
**Argumente:**
- `catname` (String): Der Name der Kategorie.
- `ignore_native` (Boolean): Setzt den ersten und dritten Rückgabewert zu `None`. (Verkürzt die Laufzeit dieser Funktion.)
**Rückgabewerte:**
1. ([Category](https://gaumi-fginfo.pages.gwdg.de/pelican/_build/html/themes.html#object-author-cat-tag)): Die native Kategorie.
2. (Dict): Der Eintrag zu der Kategorie aus der config.json-Datei aus dem Inhaltsrepo.
3. (List\<[Article](https://gaumi-fginfo.pages.gwdg.de/pelican/_build/html/themes.html#article)\>): Die Artikel in der Kategorie.
**Beispiel Aufruf:**
```
{%- call(nativecat, sccat, catarticles) get.category_by_name(article.category.name) -%}
<ul>
<li>Kategorie: {{ nativecat.name }}</li>
<li>Farbe: {{ sccat.color }}</li>
<li>Anzahl Artikel: {{ catarticles|length }}</li>
</ul>
{%- endcall -%}
```
### `tag_by_name(tagname)`
**Argumente:**
- `catname` (String): Der Name des Tags.
**Rückgabewerte:**
1. ([Tag](https://gaumi-fginfo.pages.gwdg.de/pelican/_build/html/themes.html#object-author-cat-tag)): Der native Tag.
2. (Dict): Falls der Tag gleichnamig zu einer Kategorie ist, dann der Eintrag zu der Kategorie aus der config.json-Datei aus dem Inhaltsrepo, sonst `None`.
3. (List\<[Article](https://gaumi-fginfo.pages.gwdg.de/pelican/_build/html/themes.html#article)\>): Die Artikel die diesen Tag haben.
**Beispiel Aufruf:**
```
{%- call(nativetag, sccat, tagarticles) get.tag_by_name("event") -%}
<ul>
<li>Tag: {{ nativetag.name }}</li>
<li>Farbe: {% if sccat %}{{ sccat.color }}{% else %}Dieser Tag ist nicht gleichnamig zu einer Kategorie und hat deshalb keine Farbe.{% endif %}</li>
<li>Anzahl Artikel mit diesem Tag: {{ tagarticles|length }}</li>
</ul>
{%- endcall -%}
```
### `article_by_slug(slug, lang)`
**Argumente:**
- `slug` (String): Der Slug von dem Artikel.
- `lang` (String): Die Sprache von dem Artikel.
**Rückgabewerte:**
1. ([Article](https://gaumi-fginfo.pages.gwdg.de/pelican/_build/html/themes.html#article)): Der Artikel.
### `page_by_slug(slug, lang)`
**Argumente:**
- `slug` (String): Der Slug von der Seite.
- `lang` (String): Die Sprache von der Seite.
**Rückgabewerte:**
1. ([Page](https://gaumi-fginfo.pages.gwdg.de/pelican/_build/html/themes.html#page)): Die Seite.
### `article_or_page_by_slug(slug, lang)`
**Argumente:**
- `slug` (String): Der Slug von dem Artikel oder der Seite.
- `lang` (String): Die Sprache von dem Artikel oder der Seite.
**Rückgabewerte:**
1. ([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.
2. (String): "article" falls es ein Artikel ist. "page" falls es eine Seite ist.
## [cards.html](cards.html)
```
{%- import 'macros/cards.html' as cards with context -%}
```
Mit diesen Macros können Kachelblöcke erstellt werden.
In einem Kachelblock dürfen nur Kacheln sein und sonst nichts!
**Beispiel:**
```
{{ cards.open() }}
{%- for article in all_articles -%}
{{ cards.card_from_article_or_page(article) }}
{%- endfor -%}
{{ cards.card(title="Dies ist auch eine Kachel", url="https://www.youtube.com/watch?v=dQw4w9WgXcQ", catcolor="green") }}
{{ cards.close() }}
```
### `open(id = None, classes = None)`
Beginnt einen Kachelblock.
**Argumente:**
- `id` (String): Die ID von dem Kachelblock.
- `classes` (List\<String\>): Zusätzliche Klassen für den Kachelblock.
### `close()`
Schließt einen Kachelblock.
### `card(title, url, catcolor, escape_title = True, is_url_external = True)`
Erstellt eine Kachel.
**Argumente:**
- `title` (String): Der Titel.
- `url` (String): Der URL.
- `catcolor` (String): Die Farbe.
- `escape_title` (Boolean): Ob `title` escaped werden soll.
- `is_url_external` (Boolean): Ob `url` auf eine externe Resource zeigt, oder als relativen Link interpretiert werden soll.
### `card_from_article_or_page(aop)`
Erstellt eine Kachel von einem Artikel oder einer Seite.
**Argumente:**
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)
```
{%- import 'macros/renderers.html' as render with context -%}
```
**TODO: ** Die Dokumentation für diese Macros ist abhängig von der Dokumentation von der config.json-Datei im Inhaltsrepo.
### `section_news(s)`
### `section_custom(s)`
### `section_iframe(s)`
### `section_category(s)`
### `section_tag(s)`
### `section(s)`
{#- Siehe https://gitlab.gwdg.de/GAUMI-fginfo/fg-website/-/blob/better-content-renderer/docs/content.md -#}
{%- macro render_content(content, lang) -%}
{{ render_blocks(content, lang) }}
{%- endmacro -%}
{%- macro render_attr_extra(key, value, lang) %}
{%- if value != None -%}
{%- if value is mapping and value['value'] != None -%}
{%- if value['escape'] %} {{ key }}="{{ value['value']|e }}"
{%- else %} {{ key }}="{{ value['value'] }}"
{%- endif -%}
{%- elif value is string %} {{ key }}="{{ value }}"
{%- endif -%}
{%- endif -%}
{%- endmacro -%}
{%- macro render_attr(attr, lang, extra_classes = [], extra = {}) -%}
{%- set id = attr['id']|d("") -%}
{%- set classes = attr['classes']|d([]) + extra_classes -%}
{%- set attr_extra = attr['extra']|d({}) -%}
{%- if id %} id="{{ id }}"{%- endif -%}
{%- if classes|length > 0 %} class="{{ classes|join(' ') }}"{%- endif -%}
{%- for key, value in attr_extra.items() -%}
{%- if key not in extra -%}
{{ render_attr_extra(key, value, lang) }}
{%- endif -%}
{%- endfor -%}
{%- for key, value in extra.items() -%}
{{ render_attr_extra(key, value, lang) }}
{%- endfor -%}
{%- endmacro -%}
{%- macro render_orderedlist_type(style, delim) -%}
{#- TODO also use delim: default | period | one_parenthesis | two_parentheses -#}
{%- if style == "default" -%}1
{%- elif style == "lower_alpha" -%}a
{%- elif style == "upper_alpha" -%}A
{%- elif style == "lower_roman" -%}i
{%- elif style == "upper_roman" -%}I
{%- elif style == "example" -%}1
{%- else -%}1
{%- endif -%}
{%- endmacro -%}
{%- macro render_link(url, content, lang, attr = None, title = None) -%}
<a {{ render_attr(attr, lang, extra={"href": url, "title": {"value":title, "escape": true}}) }}>
{%- if content is string -%}
{{ content|e }}
{%- else -%}
{{ render_blocks_or_inlines(content, lang) }}
{%- endif -%}
</a>
{%- endmacro -%}
{%- macro render_image(url, alt, lang, attr = None, title = None) -%}
<img {{ render_attr(attr, lang, extra={"src": url, "title": {"value":title, "escape": true}}) }} alt="
{%- if alt is string -%}
{{ alt|e }}
{%- else -%}
{{ render_inlines(alt, lang) }}
{%- endif -%}
">
{%- endmacro -%}
{%- macro render_blocks_or_inlines(bsois, lang) -%}
{%- for boi in bsois -%}
{{ render_block_or_inline(boi, lang) }}
{%- endfor -%}
{%- endmacro -%}
{%- macro render_block_or_inline(boi, lang) -%}
{%- set eclass = boi['class'] -%}
{%- if eclass == "block" -%}
{{ render_block(boi,lang) }}
{%- elif eclass == "inline" -%}
{{ render_inline(boi,lang) }}
{%- else -%}
<br><strong>ERROR: Cannot render block or inline: '{{ boi|e }}'</strong><br>
{%- endif -%}
{%- endmacro -%}
{#- ############################ BLOCKS ################################### -#}
{%- macro render_blocks(blocks, lang) -%}
{%- for block in blocks -%}
{{ render_block(block,lang) }}
{%- endfor -%}
{%- endmacro -%}
{%- macro render_block(block, lang) -%}
{%- set etype = block['type'] -%}
{%- if etype == "header" -%}
{{ render_block_header(block, lang) }}
{%- elif etype == "paragraph" -%}
{{ render_block_paragraph(block, lang) }}
{%- elif etype == "bulletlist" -%}
{{ render_block_bulletlist(block, lang) }}
{%- elif etype == "plain" -%}
{{ render_block_plain(block, lang) }}
{%- elif etype == "codeblock" -%}
{{ render_block_codeblock(block, lang) }}
{%- elif etype == "blockquote" -%}
{{ render_block_blockquote(block, lang) }}
{%- elif etype == "blockcontainer" -%}
{{ render_block_blockcontainer(block, lang) }}
{%- elif etype == "horizontalrule" -%}
{{ render_block_horizontalrule(block, lang) }}
{%- elif etype == "rawblock" -%}
{{ render_block_rawblock(block, lang) }}
{%- elif etype == "orderedlist" -%}
{{ render_block_orderedlist(block, lang) }}
{%- else -%}
<br><strong>ERROR: Unhandled block type: '{{ etype|e }}'</strong><br>
{%- endif -%}
{%- endmacro -%}
{%- macro render_block_header(block, lang) -%}
{%- set level = block['level'] -%}
{%- set attr = block['attr'] -%}
{%- set content = block['content'] -%}
<header {{ render_attr(attr, lang) }}>
<h{{ level }}>
{{ render_inlines(content, lang) }}
</h{{ level }}>
</header>
{%- endmacro -%}
{%- macro render_block_paragraph(block, lang) -%}
{%- set content = block['content'] -%}
<p>
{{ render_inlines(content, lang) }}
</p>
{%- endmacro -%}
{%- macro render_block_bulletlist(block, lang) -%}
{%- set items = block['items'] -%}
{%- set count = block['count'] -%}
<ul>
{%- for item in items -%}
<li>{{ render_blocks(item, lang) }}</li>
{%- endfor -%}
</ul>
{%- endmacro -%}
{%- macro render_block_plain(block, lang) -%}
{%- set content = block['content'] -%}
{{ render_inlines(content, lang) }}
{%- endmacro -%}
{%- macro render_block_codeblock(block, lang) -%}
{%- set attr = block['attr'] -%}
{%- set code = block['code'] -%}
{%- set code_lines = block['code_lines'] -%}
<pre {{ render_attr(attr, lang, extra_classes=["codeblock"]) }}>{{ code|e }}</pre>
{%- endmacro -%}
{%- macro render_block_blockquote(block, lang) -%}
{%- set content = block['content'] -%}
<blockquote>
{{ render_blocks(content, lang) }}
</blockquote>
{%- endmacro -%}
{%- macro render_block_blockcontainer(block, lang) -%}
{%- set attr = block['attr'] -%}
{%- set content = block['content'] -%}
<div {{ render_attr(attr, lang) }}>
{{ render_blocks(content, lang) }}
</div>
{%- endmacro -%}
{%- macro render_block_horizontalrule(block, lang) -%}
<hr>
{%- endmacro -%}
{%- macro render_block_rawblock(block, lang) -%}
{%- set format = block['format'] -%}
{%- set raw = block['raw'] -%}
{%- if format == "html" -%}
<div class="rawblock {{ format|e }}">
{{ raw }}
</div>
{%- else -%}
<div class="rawblock {{ format|e }}">{{ raw | e }}</div>
{%- endif -%}
{%- endmacro -%}
{%- macro render_block_orderedlist(block, lang) -%}
{%- set items = block['items'] -%}
{%- set count = block['count'] -%}
{%- set start = block['start'] -%}
{%- set style = block['style'] -%}
{%- set delim = block['delim'] -%}
{#- ol start="{{ start|e }}" style="list-style-type: {{ render_orderedlist_type(style, delim) }};" -#}
<ol start="{{ start|e }}" type="{{ render_orderedlist_type(style, delim) }}">
{%- for item in items -%}
<li>{{ render_blocks(item, lang) }}</li>
{%- endfor -%}
</ol>
{%- endmacro -%}
{#- ############################ INLINES ################################## -#}
{%- macro render_inlines(inlines, lang) -%}
{%- for inline in inlines -%}
{{ render_inline(inline,lang) }}
{%- endfor -%}
{%- endmacro -%}
{%- macro render_inline(inline, lang) -%}
{%- set etype = inline['type'] -%}
{%- if etype == "space" -%}
{{ render_inline_space(inline, lang) }}
{%- elif etype == "string" -%}
{{ render_inline_string(inline, lang) }}
{%- elif etype == "linebreak" -%}
{{ render_inline_linebreak(inline, lang) }}
{%- elif etype == "strong" -%}{{ render_inline_simple(inline, lang, "b") }}
{%- elif etype == "emph" -%}{{ render_inline_simple(inline, lang, "i") }}
{%- elif etype == "strikeout" -%}{{ render_inline_simple(inline, lang, "s") }}
{%- elif etype == "superscript" -%}{{ render_inline_simple(inline, lang, "sup") }}
{%- elif etype == "subscript" -%}{{ render_inline_simple(inline, lang, "sub") }}
{%- elif etype == "underline" -%}{{ render_inline_underline(inline, lang) }}
{%- elif etype == "smallcaps" -%}{{ render_inline_smallcaps(inline, lang) }}
{%- elif etype == "inlinecontainer" -%}
{{ render_inline_inlinecontainer(inline, lang) }}
{%- elif etype == "rawinline" -%}
{{ render_inline_rawinline(inline, lang) }}
{%- elif etype == "code" -%}
{{ render_inline_code(inline, lang) }}
{%- elif etype == "quoted" -%}
{{ render_inline_quoted(inline, lang) }}
{%- elif etype == "footnote" -%}
{{ render_inline_footnote(inline, lang) }}
{%- elif etype == "link" -%}
{{ render_inline_link(inline, lang) }}
{%- elif etype == "image" -%}
{{ render_inline_image(inline, lang) }}
{%- elif etype == "math" -%}
{{ render_inline_math(inline, lang) }}
{%- else -%}
<br><strong>ERROR: Unhandled inline type: '{{ etype|e }}'</strong><br>
{%- endif -%}
{%- endmacro -%}
{%- macro render_inline_space(inline, lang) %} {% endmacro -%}
{%- macro render_inline_string(inline, lang) -%}
{%- set text = inline['text'] -%}
{{ text|e }}
{%- endmacro -%}
{%- macro render_inline_linebreak(inline, lang) -%}
<br>
{%- endmacro -%}
{%- macro render_inline_simple(inline, lang, tag) -%}
{%- set content = inline['content'] -%}
<{{ tag }}>{{ render_inlines(content, lang) }}</{{ tag }}>
{%- endmacro -%}
{%- macro render_inline_underline(inline, lang) -%}
{%- set content = inline['content'] -%}
<span class="underline">{{ render_inlines(content, lang) }}</span>
{%- endmacro -%}
{%- macro render_inline_smallcaps(inline, lang) -%}
{%- set content = inline['content'] -%}
<span class="smallcaps">{{ render_inlines(content, lang) }}</span>
{%- endmacro -%}
{%- macro render_inline_inlinecontainer(inline, lang) -%}
{%- set attr = inline['attr'] -%}
{%- set content = inline['content'] -%}
<span {{ render_attr(attr, lang) }}>
{{ render_inlines(content, lang) }}
</span>
{%- endmacro -%}
{%- macro render_inline_rawinline(inline, lang) -%}
{%- set format = inline['format'] -%}
{%- set raw = inline['raw'] -%}
{%- if format == "html" -%}
<span class="rawinline {{ format|e }}">
{{ raw }}
</span>
{%- else -%}
<span class="rawinline {{ format|e }}">{{ raw | e }}</span>
{%- endif -%}
{%- endmacro -%}
{%- macro render_inline_code(inline, lang) -%}
{%- set attr = inline['attr'] -%}
{%- set code = inline['code'] -%}
{%- set code_lines = inline['code_lines'] -%}
<code {{ render_attr(attr, lang, extra_classes=["codeinline"]) }}>{{ code|e }}</code>
{%- endmacro -%}
{%- macro render_inline_quoted(inline, lang) -%}
{%- set quotetype = inline['quotetype'] -%}
{%- set text = inline['text'] -%}
{%- if quotetype == "single" -%}
{{ t[lang].quotations.single.left }}{{ text|e }}{{ t[lang].quotations.single.right }}
{%- elif quotetype == "double" -%}
{{ t[lang].quotations.double.left }}{{ text|e }}{{ t[lang].quotations.double.right }}
{%- else -%}
&quot;{{ text|e }}&quot;
{%- endif -%}
{%- endmacro -%}
{%- macro render_inline_footnote(inline, lang) -%}
{%- set content = inline['content'] -%}
<sup>[TODO FOOTNOTES]</sup>
{%- endmacro -%}
{%- macro render_inline_link(inline, lang) -%}
{%- set attr = inline['attr'] -%}
{%- set content = inline['content'] -%}
{%- set url = inline['url'] -%}
{%- set title = inline['title'] -%}
{{ render_link(url, content, lang, attr, title) }}
{%- endmacro -%}
{%- macro render_inline_image(inline, lang) -%}
{%- set attr = inline['attr'] -%}
{%- set alt = inline['alt'] -%}
{%- set url = inline['url'] -%}
{%- set title = inline['title'] -%}
{{ render_image(url, alt, lang, attr, title) }}
{%- endmacro -%}
{%- macro render_inline_math(inline, lang) -%}
{%- set mathtype = inline['mathtype'] -%}
{%- set math = inline['math'] -%}
{%- if mathtype == "inline" -%}
<span class="math inline">\({{ math|e }}\)</span>
{%- elif mathtype == "display" -%}
<span class="math display">\[{{ math|e }}\]</span>
{%- else -%}
<br><strong>ERROR: Unhandled mathtype: '{{ mathtype|e }}'</strong><br>
{%- endif -%}
{%- endmacro -%}
{%- import 'macros/getters.html' as get with context -%}
{%- import 'macros/cards.html' as cards with context -%}
{%- import 'macros/content_renderer.html' as content_renderer with context -%}
{%- macro section_news(s, lang) -%}
{{ cards.cards_from_pages(pages_modified, max=s.num) }}
......@@ -27,7 +28,7 @@
{{ cards.cards_from_pages(tagpages, lang, max=s.num) }}
{%- if tagpage -%}
{{ tagpage.content }}
{{ content_renderer.render_content(tagpage.content, lang) }}
{%- endif -%}
{%- endcall -%}
{%- endmacro -%}
......
......@@ -28,7 +28,7 @@
{%- call(s) get.metadata_entry(page.slug, l, 'before') -%}
{{ render.sections(s, l) }}
{%- endcall -%}
{{ page.content }}
{{ content_renderer.render_content(page.content, l) }}
{%- call(s) get.metadata_entry(page.slug, l, 'after') -%}
{{ render.sections(s, l) }}
{%- endcall -%}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment