summaryrefslogtreecommitdiff
path: root/src/koszko_org_website/templates/__base.html.jinja
blob: c05a0a1ad82619861d5cf31dea7b5be5634c9980 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
{#
SPDX-License-Identifier: CC0-1.0

koszko.org website base page template.

Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org>
#}

{% macro same_lang_url(page_path) -%}
  {{ url_for('.show_page_in_' ~ lang_short, page_path=page_path) }}
{%- endmacro %}

{%
  set section_ns = namespace(
      in_section = false,
      id         = none,
      linked     = false,
      first      = true
  )
%}

{% macro maybe_link(to, link=true) %}
  {%- if to is not none and link -%}
    <a href="{{ to }}">{{ caller() }}</a>
  {%- else -%}
    {{ caller() }}
  {%- endif -%}
{% endmacro %}

{% macro header(level, text='', link_to_section=true) %}
  <h{{ level }}{{ header_attrs|default({})|xmlattr }}>
    {%
      set should_link = section_ns.in_section and
                        link_to_section       and
                        not section_ns.linked and
                        section_ns.id is not none
    %}
    {% set section_ns.linked = section_ns.linked or should_link %}
    {% set caller_markup = caller() if caller is defined else '' %}
    {% call maybe_link('#' ~ section_ns.id, link=should_link) -%}
      {{ text }}{{ caller_markup }}
    {%- endcall %}
  </h{{ level }}>
{% endmacro %}

{% macro section(id=none) %}
  {% set attrs = {} %}
  {% do attrs.update(section_attrs|default({})) %}
  {% if section_ns.first %}
    {% set section_ns.first = false %}
    {% set classes = attrs.get('class') %}
    {% set classes = (classes ~ ' ' if classes else '') ~ 'first-section' %}
    {% do attrs.update({'class': classes}) %}
  {% endif %}
  <section{{ attrs|xmlattr }}>
    {% if id is not none %}
      <div{{ {'class': 'section-anchor', 'id': id}|xmlattr }}></div>
    {% endif %}
    {% if section_ns.in_section %}
      {{ raise_exception('Section defined inside another section.') }}
    {% else %}
      {% set section_ns.in_section = true %}
      {% set section_ns.id         = id %}
      {% set section_ns.linked     = false %}
    {% endif %}
    {{ caller() }}
    {% set section_ns.in_section = false %}
  </section>
{% endmacro %}

{% macro para(ensure_containing_section=true) %}
  {% if section_ns.in_section or not ensure_containing_section %}
    <p>
      {{ caller() }}
    </p>
  {% else %}
    {% set caller_snapshot = caller %}
    {% call section() %}
      <p>
        {{ caller_snapshot() }}
      </p>
    {% endcall %}
  {% endif %}
{% endmacro %}

{% macro link(to, text='') -%}
  <a href="{{ to }}">{{ text }}
    {%- if caller is defined -%}
      {{ caller() }}
    {%- endif -%}
  </a>
{%- endmacro %}

{% macro bold(text='') -%}
  <span class="bold">{{ text }}
    {%- if caller is defined -%}
      {{ caller() }}
    {%- endif -%}
  </span>
{%- endmacro %}

{% macro italic(text='') -%}
  <span class="italic">{{ text }}
    {%- if caller is defined -%}
      {{ caller() }}
    {%- endif -%}
  </span>
{%- endmacro %}

{% macro unordered_list() %}
  <ul>
    {{ caller() }}
  </ul>
{% endmacro %}

{% macro list_entry() %}
  <li>
    {{ caller() }}
  </li>
{% endmacro %}

{% macro descriptions() %}
  <dl>
    {{ caller() }}
  </dl>
{% endmacro %}

{% macro desc_term(text='') %}
  {{ '<div>'|safe }}
  <dt>{{ text }}
    {%- if caller is defined -%}
      {{ caller() }}
    {%- endif -%}
  </dt>
{% endmacro %}

{% macro desc_desc(text='') %}
  <dd>{{ text }}
    {%- if caller is defined -%}
      {{ caller() }}
    {%- endif -%}
  </dd>
  {{ '</div>'|safe }}
{% endmacro %}

{% macro img(url, alt_text, extra_classes=[]) %}
  {% set attrs = {'class': (['pure-img'] + extra_classes)|join(' ')} %}
  {% do attrs.update({'src': url, 'alt': alt_text, 'draggable': false}) %}
  <img {{ attrs|xmlattr }}>
{% endmacro %}

{% macro aside(text='') %}
  <aside>{{ text }}
    {%- if caller is defined -%}
      {{ caller() }}
    {%- endif -%}
  </aside>
{% endmacro %}

{% macro sup(text='') -%}
  <sup>{{ text }}
    {%- if caller is defined -%}
      {{ caller() }}
    {%- endif -%}
  </sup>
{%- endmacro %}

{% set numberlinks_ns = namespace(next_num=1, nums={}) %}

{% macro numberlink(link_url) -%}
  {%- if link_url not in numberlinks_ns.nums -%}
    {%- do numberlinks_ns.nums.update({link_url: numberlinks_ns.next_num}) -%}
    {%- set numberlinks_ns.next_num = numberlinks_ns.next_num + 1 -%}
  {%- endif -%}
  {%- call sup() -%}
    {{ link(link_url, '[' ~ numberlinks_ns.nums[link_url] ~ ']') }}
  {%- endcall -%}
{%- endmacro %}

{% macro newline() %}
  <br>
{% endmacro %}

{% macro nbsp() -%}
  &nbsp;
{%- endmacro %}

{% macro unicode(code) -%}
  &#{{ code }};
{%- endmacro %}

<!DOCTYPE html>
<html>
  <head>
    {% block head %}
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <meta http-equiv="Content-Security-Policy" content="script-src 'none'">
      <title>
        {% block title %}
        {% endblock %}
      </title>
      {% block external_css %}
        <link rel="stylesheet" href="/static/normalize.css">
        <link rel="stylesheet" href="/static/pure-base.css">
        <link rel="stylesheet" href="/static/pure-tables.css">
        <link rel="stylesheet" href="/static/pure-menus-core.css">
        <link rel="stylesheet" href="/static/pure-menus-skin.css">
      {% endblock %}
      <style>
        {% block style %}
          .bold {
              font-weight: bold;
          }

          .italic {
              font-style: italic;
          }

          h1 a, h2 a, h1 a:visited, h2 a:visited {
              text-decoration: none;
              color: inherit;
          }

          .section-anchor {
              position: relative;
          }

          section > p, section > dl {
              margin-left: 20px;
          }

          section > .center_text {
              margin-left: 0px;
          }

          .center-text {
              text-align: center;
          }

          .pure-menu {
              user-select: none;
          }
        {% endblock %}
      </style>
    {% endblock %}
  </head>
  <body>
    {% block body %}
      Kocham Asię Ɛ>
    {% endblock %}
  </body>
</html>