From 67250dca95369b7cd1afbdaf694b022b008e5009 Mon Sep 17 00:00:00 2001 From: sptaule Date: Thu, 27 Jan 2022 15:03:27 +0100 Subject: Added gobal Search, template partials, deleted shortcodes not in use --- config.toml | 8 +- static/images/garage-logo.svg | 168 ++++++++++++------------- static/js/site.js | 97 +++++++++++++-- tailwind.config.js | 3 +- templates/base.html | 204 ++++++------------------------- templates/partials/shared/footer.html | 11 ++ templates/partials/shared/head.html | 50 ++++++++ templates/partials/shared/nav.html | 31 +++++ templates/partials/shared/paginator.html | 40 ++++++ templates/shortcodes/chart.html | 1 - templates/shortcodes/galleria.html | 1 - templates/shortcodes/mapbox.html | 11 -- 12 files changed, 344 insertions(+), 281 deletions(-) create mode 100644 templates/partials/shared/footer.html create mode 100644 templates/partials/shared/head.html create mode 100644 templates/partials/shared/nav.html create mode 100644 templates/partials/shared/paginator.html delete mode 100755 templates/shortcodes/chart.html delete mode 100755 templates/shortcodes/galleria.html delete mode 100755 templates/shortcodes/mapbox.html diff --git a/config.toml b/config.toml index 3a90373..c06a535 100755 --- a/config.toml +++ b/config.toml @@ -44,11 +44,11 @@ include_path = false include_content = true [extra] -katex.enabled = true -katex.auto_render = true -chart.enabled = true +katex.enabled = false +katex.auto_render = false +chart.enabled = false mermaid.enabled = true -galleria.enabled = true +galleria.enabled = false navbar_items = [ { code = "en", nav_items = [ { url = "$BASE_URL/", name = "Overview" }, diff --git a/static/images/garage-logo.svg b/static/images/garage-logo.svg index 654e25b..af33380 100644 --- a/static/images/garage-logo.svg +++ b/static/images/garage-logo.svg @@ -2,9 +2,9 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/static/js/site.js b/static/js/site.js index 4b64425..f764289 100755 --- a/static/js/site.js +++ b/static/js/site.js @@ -1,5 +1,7 @@ "use strict"; +var indexScriptLoaded = false; + function debounce(func, wait) { var timeout; @@ -110,17 +112,12 @@ function makeTeaser(body, terms) { function formatSearchResultItem(item, terms) { return ( - `
` + - `

` + - `${item.doc.title}` + - `

` + - `
` + - `${makeTeaser(item.doc.body, terms)}` + - `` + - `Read More ` + - `` + - `
` + - `` + `` + + `

` + `${item.doc.title}` + `

` + + `
` + + `${makeTeaser(item.doc.body, terms)}` + + `
` + + `
` ); } @@ -168,4 +165,82 @@ function search() { } }, 150) ); +} + +function openSearchModal() { + if (indexScriptLoaded === false) { + var indexScript = document.createElement('script'); + indexScript.setAttribute('src', './search_index.en.js'); + document.head.appendChild(indexScript); + indexScriptLoaded = true; + } + document.getElementById('search-modal').classList.remove('hidden'); + document.getElementById('search').focus(); + document.getElementById('search').select(); +} + +function closeSearchModal() { + document.getElementById('search-modal').classList.add('hidden'); +} + +function documentReadyCallback() { + + if (localStorage.getItem("theme") === "dark") { + document.body.setAttribute("theme", "dark"); + document.querySelectorAll("img, picture, video, pre").forEach(img => img.setAttribute("theme", "dark")); + document.querySelectorAll(".vimeo, .youtube, .chart").forEach(video => video.setAttribute("theme", "dark")); + document.getElementById("dark-mode").setAttribute("title", "Switch to light theme"); + } + + document.addEventListener('click', function(ev) { + if (ev.target.matches('#nav-search-btn') || ev.target.matches('#nav-search-btn-icon')) { + openSearchModal(); + } + else if (ev.target.matches('#close-modal-btn') + || ev.target.matches('#close-modal-btn-icon') + || !ev.target.closest('#search-modal')) { + closeSearchModal(); + } + }); + + document.addEventListener('keydown', function(event) { + if (event.altKey && event.key === 's') { + if (document.getElementById('search-modal').classList.contains('hidden')) { + openSearchModal(); + } else { + closeSearchModal(); + } + } + }); + + document.addEventListener('keyup', function(ev) { + if (ev.key === "Escape") { + closeSearchModal(); + } + }); + + document.getElementById("search").addEventListener("keyup", () => { + search(); + }); + + if (typeof mermaid !== "undefined") { + mermaid.initialize({ startOnLoad: true }); + } + + if (typeof renderMathInElement !== "undefined") { + renderMathInElement(document.body, { + delimiters: [ + { left: '$$', right: '$$', display: true }, + { left: '$', right: '$', display: false }, + { left: '\\(', right: '\\)', display: false }, + { left: '\\[', right: '\\]', display: true } + ] + }); + } +}; + +if (document.readyState === 'loading') { // Loading hasn't finished yet + document.addEventListener('DOMContentLoaded', documentReadyCallback); +} else { // `DOMContentLoaded` has already fired + documentReadyCallback(); } \ No newline at end of file diff --git a/tailwind.config.js b/tailwind.config.js index 0a515b8..0d3f330 100755 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -1,6 +1,7 @@ module.exports = { content: [ - "./templates/**/*.html" + "./templates/**/*.html", + "./static/js/site.js", ], theme: { extend: { diff --git a/templates/base.html b/templates/base.html index 1e44aa7..8170b44 100755 --- a/templates/base.html +++ b/templates/base.html @@ -1,206 +1,70 @@ {% import 'macros.html' as macros %} - + - - - - {% if config.extra.favicon.webmanifest %} - - {% endif %} - {% if config.extra.favicon.safari_pinned_tab %} - - {% endif %} - {% if config.extra.favicon.favicon_16x16 %} - - {% endif %} - {% if config.extra.favicon.favicon_32x32 %} - - {% endif %} - {% if config.extra.favicon.apple_touch_icon %} - - {% endif %} - - {% if config.extra.galleria.enabled %} - - {% endif %} - - {% if config.extra.mapbox.enabled %} - - {% endif %} - - - - - - {% block user_custom_stylesheet %} - {% endblock %} - - - {% block title %} - {{ config.title }} - {% endblock title %} - - - {% if config.extra.katex.enabled %} - - - - - {% if config.extra.katex.auto_render %} - - {% endif %} - {% endif %} + {% include "partials/shared/head.html" %} - + + {% include "partials/shared/nav.html" %}
{% block content %}{% endblock %}
- - {% block pagination %} - {% if paginator.previous or paginator.next %} -
-
- + {% block search %} + - {% endif %} {% endblock %} - {% block comment %} + {% block pagination %} + {% include "partials/shared/paginator.html" %} {% endblock %} -
-
-

- {{ macros:: social_links( social_config=config.extra.social) }} -

-

- Powered by Zola -

-
-
+ {% block comment %}{% endblock %} + + {% include "partials/shared/footer.html" %} - {% if config.extra.galleria.enabled %} - - - - {% endif %} {% if config.extra.mermaid.enabled %} {% endif %} - {% if config.extra.chart.enabled %} - - {% endif %} + - + {%- if lang != "en" -%} - {%- block other_lang_search_js -%} - {%- endblock -%} + {%- block other_lang_search_js -%}{%- endblock -%} {%- endif -%} - {% block custom_js %} - {% endblock %} + {% block custom_js %}{% endblock %} - {% block user_custom_js %} - {% endblock %} + {% block user_custom_js %}{% endblock %} \ No newline at end of file diff --git a/templates/partials/shared/footer.html b/templates/partials/shared/footer.html new file mode 100644 index 0000000..de58caf --- /dev/null +++ b/templates/partials/shared/footer.html @@ -0,0 +1,11 @@ +
+
+

+ {{ macros:: social_links( social_config=config.extra.social) }} +

+

+ Powered by Zola +

+
+
\ No newline at end of file diff --git a/templates/partials/shared/head.html b/templates/partials/shared/head.html new file mode 100644 index 0000000..185a97b --- /dev/null +++ b/templates/partials/shared/head.html @@ -0,0 +1,50 @@ +{% if config.extra.favicon.webmanifest %} + +{% endif %} +{% if config.extra.favicon.safari_pinned_tab %} + +{% endif %} +{% if config.extra.favicon.favicon_16x16 %} + +{% endif %} +{% if config.extra.favicon.favicon_32x32 %} + +{% endif %} +{% if config.extra.favicon.apple_touch_icon %} + +{% endif %} + +{% if config.extra.galleria.enabled %} + +{% endif %} + + + + + +{% block user_custom_stylesheet %}{% endblock %} + + + {% block title %} + {{ config.title }} + {% endblock title %} + + +{% if config.extra.katex.enabled %} + + + + + {% if config.extra.katex.auto_render %} + + {% endif %} +{% endif %} \ No newline at end of file diff --git a/templates/partials/shared/nav.html b/templates/partials/shared/nav.html new file mode 100644 index 0000000..2489bf6 --- /dev/null +++ b/templates/partials/shared/nav.html @@ -0,0 +1,31 @@ + \ No newline at end of file diff --git a/templates/partials/shared/paginator.html b/templates/partials/shared/paginator.html new file mode 100644 index 0000000..470d411 --- /dev/null +++ b/templates/partials/shared/paginator.html @@ -0,0 +1,40 @@ +{% if paginator.previous or paginator.next %} +
+
+ +
+
+{% endif %} \ No newline at end of file diff --git a/templates/shortcodes/chart.html b/templates/shortcodes/chart.html deleted file mode 100755 index 539aeea..0000000 --- a/templates/shortcodes/chart.html +++ /dev/null @@ -1 +0,0 @@ -{{body | safe}} diff --git a/templates/shortcodes/galleria.html b/templates/shortcodes/galleria.html deleted file mode 100755 index 0e23cd3..0000000 --- a/templates/shortcodes/galleria.html +++ /dev/null @@ -1 +0,0 @@ -
{{body | safe}}
\ No newline at end of file diff --git a/templates/shortcodes/mapbox.html b/templates/shortcodes/mapbox.html deleted file mode 100755 index 13d3488..0000000 --- a/templates/shortcodes/mapbox.html +++ /dev/null @@ -1,11 +0,0 @@ -
-
- {{config.extra.mapbox.access_token}} -
-
- {{zoom}} -
-
- {{body}} -
-
-- cgit v1.2.3