aboutsummaryrefslogtreecommitdiff
path: root/templates/macros
diff options
context:
space:
mode:
authorJieiku2023-08-25 01:44:50 -0700
committerJieiku2023-08-25 01:44:50 -0700
commit009d3f90b1881530bd28003abe83cfc3735882be (patch)
tree5112554449edf2aaff956b9c364133ec41ff39c5 /templates/macros
parentc04ff0a3ac2aff149c3454f7563de3f7941e373d (diff)
downloadabridge-009d3f90b1881530bd28003abe83cfc3735882be.tar.gz
abridge-009d3f90b1881530bd28003abe83cfc3735882be.tar.bz2
abridge-009d3f90b1881530bd28003abe83cfc3735882be.zip
Refactor Documentation, PWA Fix, image shortcodes fix, simplify js script loading
Diffstat (limited to 'templates/macros')
-rw-r--r--templates/macros/head.html75
1 files changed, 28 insertions, 47 deletions
diff --git a/templates/macros/head.html b/templates/macros/head.html
index 673954b..fe4eb53 100644
--- a/templates/macros/head.html
+++ b/templates/macros/head.html
@@ -1,26 +1,18 @@
{#- Theme Switcher Button to toggle between dark/light #}
{%- macro theme(config) %}
{%- if config.extra.js_switcher | default(value=true) %}
- {%- set js_theme=config.extra.js_theme | default(value="") -%}
- {%- if not js_theme %}
- {%- set js_theme="js/theme.min.js" -%}
- {%- if config.extra.js_switcher_default %}{%- if config.extra.js_switcher_default == "light" %}
- {%- set js_theme="js/theme_light.min.js" -%}
- {%- endif %}{%- endif %}
+ {%- set js_theme="js/theme.min.js" %}
+ {%- if config.extra.js_switcher_default %}
+ {%- if config.extra.js_switcher_default == "light" %}{% set js_theme="js/theme_light.min.js" %}{% endif %}
{%- endif %}
- <script src="{{ get_url(path=js_theme, trailing_slash=false) | safe }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path=js_theme, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
+ <script src="{{ get_url(path=js_theme , trailing_slash=false) | safe }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path=js_theme, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
{%- endif %}
{%- endmacro %}
-
{#- Service Worker for PWA #}
{%- macro pwa(config) %}
{%- if config.extra.pwa | default(value=false) %}
- {%- set js_swload=config.extra.js_swload | default(value="") -%}
- {%- if not js_swload %}
- {%- set js_swload="js/sw_load.min.js" -%}
- {%- endif %}
- <script defer src="{{ get_url(path=js_swload, trailing_slash=false, cachebust=true) | safe }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path=js_swload, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
+ <script defer src="{{ get_url(path='js/sw_load.min.js' , trailing_slash=false, cachebust=true) | safe }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path='js/sw_load.min.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
{%- endif %}
{%- endmacro %}
@@ -28,7 +20,7 @@
{%- macro stylesheets(config) %}
{%- set stylesheets=config.extra.stylesheets | default(value=[ "abridge.css" ]) -%}
{%- if stylesheets %}{%- for i in stylesheets %}
- <link rel="stylesheet" href="{{ get_url(path=i, trailing_slash=false, cachebust=true) | safe }}" />
+ <link rel="stylesheet" href="{{ get_url(path=i , trailing_slash=false, cachebust=true) | safe }}" />
{%- endfor %}{%- endif %}
{%- endmacro %}
@@ -96,49 +88,38 @@
{%- if config.extra.js_bundle %}
{%- if config.build_search_index %}
- <script defer src="{{ get_url(path='js/abridge.min.js', trailing_slash=false, cachebust=true) | safe }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path='js/abridge.min.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
+ <script defer src="{{ get_url(path='js/abridge.min.js' , trailing_slash=false, cachebust=true) | safe }}"{%- if config.extra.integrity | default(value=true) %} 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-nosearch.min.js', trailing_slash=false, cachebust=true) | safe }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path='js/abridge-nosearch.min.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
+ <script defer src="{{ get_url(path='js/abridge_nosearch.min.js' , trailing_slash=false, cachebust=true) | safe }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path='js/abridge_nosearch.min.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
{%- 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, cachebust=true) | safe }}"{%- if config.extra.integrity | default(value=true) %} 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, cachebust=true) | safe }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path='js/lunr.' ~ lang ~ '.min.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
+ <script defer src="{{ get_url(path='js/lunr.stemmer.support.min.js', trailing_slash=false) | safe }}"{%- if config.extra.integrity | default(value=true) %} 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 config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path='js/lunr.' ~ lang ~ '.min.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
{%- endif %}
{%- endif %}
{%- endif %}
-{%- else %}
+{%- else %}{#- Not js_bundle #}
{%- if preStyle == true %}
- {%- set js_prestyle=config.extra.js_prestyle | default(value="js/prestyle.js") -%}
- {%- if js_prestyle %}
- <script defer src="{{ get_url(path=js_prestyle, trailing_slash=false, cachebust=true) | safe }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path=js_prestyle, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
+ {%- if config.extra.js_prestyle | default(value=true) %}
+ <script defer src="{{ get_url(path='js/prestyle.js' , trailing_slash=false, cachebust=true) | safe }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path='js/prestyle.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
{%- endif %}
{%- endif %}
{%- if config.extra.js_switcher | default(value=true) %}
- {%- set js_theme=config.extra.js_theme | default(value="js/theme.min.js") -%}
- {%- if js_theme %}
- {%- set js_themeButton=config.extra.js_themeButton | default(value="js/theme_button.js") -%}
- {%- if js_themeButton %}
- <script defer src="{{ get_url(path=js_themeButton, trailing_slash=false, cachebust=true) | safe }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path=js_themeButton, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
- {%- endif %}
- {%- endif %}
+ <script defer src="{{ get_url(path='js/theme_button.js' , trailing_slash=false, cachebust=true) | safe }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path='js/theme_button.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
{%- endif %}
- {%- set js_email=config.extra.js_email | default(value="js/email.js") -%}
- {%- if js_email %}
- {%- if config.extra.mail_encode | default(value=true) %}
- <script defer src="{{ get_url(path=js_email, trzailing_slash=false, cachebust=true) | safe }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path=js_email, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
- {%- endif %}
+ {%- if config.extra.js_email_encode | default(value=true) %}
+ <script defer src="{{ get_url(path='js/email.js' , trailing_slash=false, cachebust=true) | safe }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path='js/email.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
{%- endif %}
- {%- set js_codecopy=config.extra.js_codecopy | default(value="js/codecopy.js") -%}
- {%- if js_codecopy %}
- <script defer src="{{ get_url(path=js_codecopy, trailing_slash=false, cachebust=true) | safe }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path=js_codecopy, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
+ {%- if config.extra.js_copycode | default(value=true) %}
+ <script defer src="{{ get_url(path='js/codecopy.js' , trailing_slash=false, cachebust=true) | safe }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path='js/codecopy.js', sha_type=384, base64=true) | safe }}"{%- endif %}></script>
{%- endif %}
{%- if search_library == "tinysearch" %}
@@ -155,7 +136,7 @@
{%- endif %}
{%- set uglyurls=config.extra.uglyurls | default(value=false) -%}
- {%- if search_index_format == "elasticlunr_javascript" %}
+ {%- 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 config.extra.integrity | default(value=true) %} 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 config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path='search_index.' ~ lang ~ '.js' , sha_type=384, base64=true) | safe }}"{%- endif %}></script>
@@ -170,8 +151,8 @@
{%- endif %}
{%- if lang != "en" %}
- <script defer src="{{ get_url(path='js/lunr.stemmer.support.min.js', trailing_slash=false, cachebust=true) | safe }}"{%- if config.extra.integrity | default(value=true) %} 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, cachebust=true) | safe }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path='js/lunr.' ~ lang ~ '.min.js' , sha_type=384, base64=true) | safe }}"{%- endif %}></script>
+ <script defer src="{{ get_url(path='js/lunr.stemmer.support.min.js', trailing_slash=false) | safe }}"{%- if config.extra.integrity | default(value=true) %} 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 config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path='js/lunr.' ~ lang ~ '.min.js' , sha_type=384, base64=true) | safe }}"{%- endif %}></script>
{%- endif %}
{%- endif %}
@@ -186,35 +167,35 @@
{%- set katex_bundle=config.extra.katex_bundle | default(value="js/katexbundle.min.js") -%}
{%- if katex_bundle %}
- <script defer src="{{ get_url(path=katex_bundle, trailing_slash=false, cachebust=true) }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path=katex_bundle, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
+ <script defer src="{{ get_url(path=katex_bundle , trailing_slash=false, cachebust=true) }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path=katex_bundle, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
{%- else %}
{%- set katex_js=config.extra.katex_js | default(value="js/katex.min.js") -%}
{%- if katex_js %}{%- if katex_js is matching("^http[s]?://") %}
- <script defer src="{{ katex_js | safe }}"{%- if config.extra.integrity | default(value=true) and config.extra.katex_js_integrity %} integrity="{{ config.extra.katex_js_integrity | safe }}"{%- endif %} crossorigin="anonymous"></script>
+ <script defer src="{{ katex_js | safe }}"{%- if config.extra.integrity | default(value=true) 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 config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path=katex_js, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
+ <script defer src="{{ get_url(path=katex_js , trailing_slash=false, cachebust=true) }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path=katex_js, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
{%- endif %}{%- endif %}
{%- set mathtex_js=config.extra.mathtex_js | default(value="js/mathtex-script-type.min.js") -%}
{%- if mathtex_js %}{%- if mathtex_js is matching("^http[s]?://") %}
<script defer src="{{ mathtex_js | safe }}"{%- if config.extra.integrity | default(value=true) 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 config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path=mathtex_js, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
+ <script defer src="{{ get_url(path=mathtex_js , trailing_slash=false, cachebust=true) }}"{%- if config.extra.integrity | default(value=true) %} 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 | default(value="js/katex-auto-render.min.js") -%}
{%- if katex_autorender_js %}
{%- if katex_autorender_js is matching("^http[s]?://") %}
- <script defer src="{{ katex_autorender_js | safe }}"{%- if config.extra.integrity | default(value=true) and config.extra.katex_autorender_js_integrity %} integrity="{{ config.extra.katex_autorender_js_integrity | safe }}"{%- endif %} crossorigin="anonymous"></script>
+ <script defer src="{{ katex_autorender_js | safe }}"{%- if config.extra.integrity | default(value=true) 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 config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path=katex_autorender_js, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
+ <script defer src="{{ get_url(path=katex_autorender_js , trailing_slash=false, cachebust=true) }}"{%- if config.extra.integrity | default(value=true) %} 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 | default(value="js/katexoptions.js") -%}
{%- if katex_options %}
- <script defer src="{{ get_url(path=katex_options, trailing_slash=false, cachebust=true) }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path=katex_options, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
+ <script defer src="{{ get_url(path=katex_options , trailing_slash=false, cachebust=true) }}"{%- if config.extra.integrity | default(value=true) %} integrity="sha384-{{ get_hash(path=katex_options, sha_type=384, base64=true) | safe }}"{%- endif %}></script>
{%- endif %}
{%- endif %}
{%- endif %}