From 2242a4d001c9f3e863dffb6b3fa544bb90cfe2e4 Mon Sep 17 00:00:00 2001 From: Alice Bowman Date: Tue, 17 Sep 2024 17:01:39 +0200 Subject: [PATCH] feat: offline search --- config.toml | 3 +- layouts/partials/navbar.html | 2 +- layouts/partials/search-input.html | 61 ++++++++++++++++++++++++++++++ layouts/partials/sidebar-tree.html | 1 - static/css/rosenpass.css | 52 +++++++++++++++++++++++++ 5 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 layouts/partials/search-input.html diff --git a/config.toml b/config.toml index 1e63d4a7..133be06b 100644 --- a/config.toml +++ b/config.toml @@ -99,6 +99,7 @@ enableRobotsTXT = true time_format_blog = "Monday, January 02, 2006" time_format_default = "January 2, 2006" rss_sections = ["blog"] + offlineSearch = true [outputFormats] [outputFormats.PRINT] @@ -149,5 +150,5 @@ enableRobotsTXT = true sidebar_menu_compact = false sidebar_menu_foldable = true ul_show = 3 - sidebar_search_disable = false + sidebar_search_disable = true showLightDarkModeMenu = false diff --git a/layouts/partials/navbar.html b/layouts/partials/navbar.html index c320ec50..aabf2fa1 100644 --- a/layouts/partials/navbar.html +++ b/layouts/partials/navbar.html @@ -66,7 +66,7 @@ {{ end -}} - diff --git a/layouts/partials/search-input.html b/layouts/partials/search-input.html new file mode 100644 index 00000000..7817e0ab --- /dev/null +++ b/layouts/partials/search-input.html @@ -0,0 +1,61 @@ +{{ .Scratch.Set "docsy-search" 0 -}} + +{{ if .Site.Params.gcs_engine_id -}} +{{ .Scratch.Add "docsy-search" 1 -}} + + + +{{- end -}} + + +{{ if and .Site.Params.search (isset .Site.Params.search "algolia") -}} +{{ .Scratch.Add "docsy-search" 1 -}} +{{ .Scratch.Add "docsearch-id-num" 1 -}} + + + +{{- end -}} + + +{{ if .Site.Params.offlineSearch -}} +{{ .Scratch.Add "docsy-search" 1 -}} + +{{ $offlineSearchIndex := resources.Get "json/offline-search-index.json" | resources.ExecuteAsTemplate "offline-search-index.json" . -}} +{{ if hugo.IsProduction -}} +{{/* Use `md5` as finger print hash function to shorten file name to avoid `file name too long` error. */ -}} +{{ $offlineSearchIndex = $offlineSearchIndex | fingerprint "md5" -}} +{{ end -}} +{{ $offlineSearchLink := $offlineSearchIndex.RelPermalink -}} + + + +{{- end -}} + +{{ if gt (.Scratch.Get "docsy-search") 1 -}} +{{ warnf `You have more than one site-search option configured: choose only one. + For details, see https://www.docsy.dev/docs/adding-content/search.` -}} +{{ end -}} diff --git a/layouts/partials/sidebar-tree.html b/layouts/partials/sidebar-tree.html index 13a01ba6..1b507aca 100644 --- a/layouts/partials/sidebar-tree.html +++ b/layouts/partials/sidebar-tree.html @@ -11,7 +11,6 @@ {{ else -}}
diff --git a/static/css/rosenpass.css b/static/css/rosenpass.css index 63e0246d..007e7ddc 100644 --- a/static/css/rosenpass.css +++ b/static/css/rosenpass.css @@ -876,6 +876,58 @@ margin-left: 1rem; font-size: larger; } +/* Search Bar */ +.navbar-nav:has(.td-search){ + align-self: stretch; + align-content: center; + padding-bottom: 0 !important; +} + +.navbar-nav:has(input.td-search__input:not(:hover, :focus)) { + transition: all 0.5s 1s; + max-height: 200px; + + + div.td-search input.td-search__input:not(:hover) { + width: 36px; + } + + div.td-search div.td-search__icon { + padding: var(--bs-nav-link-padding-y) var(--bs-nav-link-padding-x); + display: block !important; + } + +} + +.container-fluid:has(input.td-search__input:focus), +.container-fluid:has(input.td-search__input:hover), +body:has(.td-offline-search-results) { + .td-search__input { + transition: all 0.5s ease-in-out 0.2s; + width: 207px !important; + margin-left: 0.2rem; + margin-right: 0.1rem; + } + #main_navbar { + width: min-content !important; + } + #navbar-custom { + overflow: hidden !important; + } + +} +.navbar-nav { + @media(min-width:768px){ + max-height: 99px !important; + } + @media(min-width:947px){ + max-height: 48px !important; + } + @media(min-width:1000px){ + max-height: 40px !important; + } + } + /* MAIN COVER */ .new-update-bar {