aboutsummaryrefslogtreecommitdiff
path: root/templates/partials/head_js.html
blob: ae67802f184491fc59afddc70effe6243a952579 (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
{#- JAVASCRIPT -#}
  {%- set integrity = (config.extra.integrity if config.extra.integrity is defined else true) -%}
  {%- if config.extra.search_library %}{%- if config.extra.search_library == "offline" %}{%- set integrity = false -%}{%- endif -%}{%- endif -%}
  {%- set search_library=(config.extra.search_library if config.extra.search_library else "elasticlunr") -%}

  {%- set preStyle = false -%}

  {%- if config.extra.fonts -%}{%- for i in config.extra.fonts -%}
    {%- if i.url is matching(pat="^http[s]?://") -%}
      {%- set preStyle = true -%}
    {%- endif -%}
  {%- endfor -%}{%- endif -%}

  {%- if config.extra.fontawesome -%}
    {%- set preStyle = true -%}
  {%- endif -%}

  {%- if config.extra.math or page?.extra?.math -%}
    {%- set katex_css=(config.extra.katex_css if config.extra.katex_css else "katex.min.css") -%}
    {%- if katex_css -%}
      {%- set preStyle = true -%}
    {%- endif -%}
  {%- endif -%}

{%- if config.mode != "serve" -%}{%- set notserve = true -%}{%- endif -%}
{%- if config.extra.js_bundle -%}

  {%- if config.build_search_index -%}
  {%- if notserve and (config.extra.pwa or false) %}
  <script defer src="{{               get_url(path='js/abridge.min.js'             , trailing_slash=false, cachebust=true) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='js/abridge.min.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- else %}
  <script defer src="{{               get_url(path='js/abridge_nopwa.min.js'             , trailing_slash=false, cachebust=true) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='js/abridge_nopwa.min.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- endif -%}

  {%- else %}
  {%- if notserve and (config.extra.pwa or false) %}
  <script defer src="{{               get_url(path='js/abridge_nosearch.min.js'    , trailing_slash=false, cachebust=true) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='js/abridge_nosearch.min.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- else %}
  <script defer src="{{               get_url(path='js/abridge_nosearch_nopwa.min.js'    , trailing_slash=false, cachebust=true) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='js/abridge_nosearch_nopwa.min.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- endif %}
  {%- endif %}

  {%- if config.build_search_index %}
  {%- if search_library == "elasticlunr" %}
  {%- if lang != "en" %}
  <script defer src="{{               get_url(path='js/lunr.stemmer.support.min.js', trailing_slash=false) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='js/lunr.stemmer.support.min.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  <script defer src="{{               get_url(path='js/lunr.' ~ lang ~ '.min.js'   , trailing_slash=false) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='js/lunr.' ~ lang ~ '.min.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- endif %}
  {%- endif %}
  {%- endif %}

{%- else %}{#- Not js_bundle #}

  {%- if preStyle == true %}
  {%- if (config.extra.js_prestyle if config.extra.js_prestyle is defined else true) %}
  <script defer src="{{               get_url(path='js/prestyle.js'                , trailing_slash=false, cachebust=true) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='js/prestyle.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- endif %}
  {%- endif %}

  {%- if (config.extra.js_switcher if config.extra.js_switcher is defined else true) %}
  <script defer src="{{               get_url(path='js/theme_button.js'            , trailing_slash=false, cachebust=true) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='js/theme_button.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- endif %}

  {%- if (config.extra.js_email_encode if config.extra.js_email_encode is defined else true) %}
  <script defer src="{{               get_url(path='js/email.js'                   , trailing_slash=false, cachebust=true) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='js/email.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- endif %}

  {%- if (config.extra.js_copycode if config.extra.js_copycode is defined else true) %}
  <script defer src="{{               get_url(path='js/codecopy.js'                , trailing_slash=false, cachebust=true) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='js/codecopy.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- endif %}

  {%- if notserve and (config.extra.pwa or false) %}
  <script defer src="{{               get_url(path='js/sw_load.js'             , trailing_slash=false, cachebust=true) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='js/sw_load.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- endif %}

  {%-   if search_library == "tinysearch" %}
  <script defer type="module" src="{{ get_url(path='js/tinysearch.js'   , trailing_slash=false, cachebust=true) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='js/tinysearch.js'   , sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- elif config.build_search_index %}

  {%- set search_index_format="elasticlunr_json" -%}
  {%- if config.search.index_format %}
    {%- if config.search.index_format == "elasticlunr_javascript" %}
      {%- set search_index_format="elasticlunr_javascript" -%}
    {%- endif %}
  {%- endif %}

  {%- set uglyurls = (config.extra.uglyurls or false) -%}
  {%- if config.extra.search_library %}{%- if config.extra.search_library == "offline" %}{% set uglyurls = true %}{% endif %}{% endif %}
  {%- if search_index_format == "elasticlunr_javascript" %}{#- Javascript index format #}
  <script defer src="{{               get_url(path='js/elasticlunr.min.js'         , trailing_slash=false, cachebust=true) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='js/elasticlunr.min.js'         , sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  <script defer src="{{               get_url(path='search_index.' ~ lang ~ '.js'  , trailing_slash=false, cachebust=true) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='search_index.' ~ lang ~ '.js'  , sha_type=384, base64=true) | safe }}"{%- endif %}></script>

  {%- if uglyurls %}
  <script defer src="{{               get_url(path='js/searchjavaugly.js'          , trailing_slash=false, cachebust=true) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='js/searchjavaugly.js'          , sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- else %}
  <script defer src="{{               get_url(path='js/searchjava.js'              , trailing_slash=false, cachebust=true) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='js/searchjava.js'              , sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- endif %}

  {%- else %}
  <script defer src="{{               get_url(path='js/search_elasticlunr.min.js'  , trailing_slash=false, cachebust=true) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='js/search_elasticlunr.min.js'  , sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- endif %}

  {%- if lang != "en" %}
  <script defer src="{{               get_url(path='js/lunr.stemmer.support.min.js', trailing_slash=false) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='js/lunr.stemmer.support.min.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  <script defer src="{{               get_url(path='js/lunr.' ~ lang ~ '.min.js'   , trailing_slash=false) | safe }}"{%- if integrity %} integrity="sha384-{{ get_hash(path='js/lunr.' ~ lang ~ '.min.js'   , sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- endif %}

  {%- endif %}

{%- endif %}





{#- Katex #}
{#- https://katex.org/docs/autorender.html #}
{#- https://github.com/KaTeX/KaTeX/ #}
{#- https://github.com/KaTeX/KaTeX/tree/main/contrib/mathtex-script-type/ #}
{%- if config.extra.math or page?.extra?.math %}

{%- set katex_bundle=(config.extra.katex_bundle if config.extra.katex_bundle else "js/katexbundle.min.js") -%}
{%- if katex_bundle %}
  <script defer src="{{               get_url(path=katex_bundle                    , trailing_slash=false, cachebust=true) }}"{%- if integrity %} integrity="sha384-{{ get_hash(path=katex_bundle, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
{%- else %}

  {%- set katex_js=(config.extra.katex_js if config.extra.katex_js else "js/katex.min.js") -%}
  {%- if katex_js %}{%- if katex_js is matching(pat="^http[s]?://") %}
  <script defer src="{{               katex_js | safe }}"{%- if integrity and config.extra.katex_js_integrity %} integrity="{{ config.extra.katex_js_integrity | safe }}"{%- endif %} crossorigin="anonymous"></script>
  {%- else %}
  <script defer src="{{               get_url(path=katex_js                        , trailing_slash=false, cachebust=true) }}"{%- if integrity %} integrity="sha384-{{ get_hash(path=katex_js, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- endif %}{%- endif %}

  {%- set mathtex_js=(config.extra.mathtex_js if config.extra.mathtex_js else "js/mathtex-script-type.min.js") -%}
  {%- if mathtex_js %}{%- if mathtex_js is matching(pat="^http[s]?://") %}
  <script defer src="{{ mathtex_js | safe }}"{%- if integrity and config.extra.mathtex_js_integrity %} integrity="{{ config.extra.mathtex_js_integrity | safe }}"{%- endif %} crossorigin="anonymous"></script>
  {%- else %}
  <script defer src="{{               get_url(path=mathtex_js                      , trailing_slash=false, cachebust=true) }}"{%- if integrity %} integrity="sha384-{{ get_hash(path=mathtex_js, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- endif %}{%- endif %}

 {%- if config.extra.math_auto_render or page?.extra?.math_auto_render %}
  {%- set katex_autorender_js=(config.extra.katex_autorender_js if config.extra.katex_autorender_js else "js/katex-auto-render.min.js") -%}
  {%- if katex_autorender_js %}
  {%- if katex_autorender_js is matching(pat="^http[s]?://") %}
  <script defer src="{{               katex_autorender_js | safe }}"{%- if integrity and config.extra.katex_autorender_js_integrity %} integrity="{{ config.extra.katex_autorender_js_integrity | safe }}"{%- endif %} crossorigin="anonymous"></script>
  {%- else %}
  <script defer src="{{               get_url(path=katex_autorender_js             , trailing_slash=false, cachebust=true) }}"{%- if integrity %} integrity="sha384-{{ get_hash(path=katex_autorender_js, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- endif %}
  {%- endif %}
  {%- set katex_options=(config.extra.katex_options if config.extra.katex_options else "js/katexoptions.js") -%}
  {%- if katex_options %}
  <script defer src="{{               get_url(path=katex_options                   , trailing_slash=false, cachebust=true) }}"{%- if integrity %} integrity="sha384-{{ get_hash(path=katex_options, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
  {%- endif %}
 {%- endif %}
{%- endif %}

{%- endif %}
  <noscript><link rel="stylesheet" href="{{ get_url(path='nojs.css', trailing_slash=false) | safe }}" /></noscript>





{#- End of head_js partial #}