Skip to content

Commit

Permalink
perf: separate styles from main HB bundle
Browse files Browse the repository at this point in the history
feat: add the hb.search.modal parameter to enable/disable modal, default to true

feat: add the form partial

style: tweak the search layout
  • Loading branch information
razonyang committed Dec 16, 2023
1 parent e220e30 commit 4d696c4
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! purgecss start ignore */
@import "../../../../search/scss/index";
@import "hugo:vars";
@import "../../../search/scss/index";

:root {
--search-primary: var(--#{$prefix}primary);
Expand All @@ -21,5 +21,3 @@
padding: 0;
}
}

/*! purgecss start end */
10 changes: 10 additions & 0 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ path = "github.com/hbstack/hb"

[params.hugopress.modules.search.hooks.head-end]
disabled = true

[params.hugopress.modules.search.hooks.body-end]
disabled = true

[params.hugopress.modules.hb-search.hooks.head-end]

[params.hugopress.modules.hb-search.hooks.body-end]

[params.hb.search]
modal = true
11 changes: 11 additions & 0 deletions layouts/index.search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- define "title" }}
{{- printf "%s - %s" (i18n "search") .Site.Title -}}
{{- end }}

{{- define "main" }}
{{ partial "hb/modules/search/assets/css" . }}
<div class="hb-module">
{{ partial "search/index" . }}
</div>
{{ partial "search/assets/js" . }}
{{- end -}}
13 changes: 13 additions & 0 deletions layouts/partials/hb/modules/search/assets/css.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- $rtl := eq .Language.LanguageDirection "rtl" }}
{{- $opts := dict
"targetPath" (cond $rtl "css/search.rtl.css" "css/search.css")
"outputStyle" (cond hugo.IsProduction "compressed" "")
"vars" (dict
"prefix" (default "hb" site.Params.hb.styles.prefix)
)
}}
{{- $css := resources.Get "hb/modules/search/index.scss" | toCSS $opts }}
{{- if hugo.IsProduction }}
{{- $css = $css | fingerprint }}
{{- end }}
<link rel="stylesheet" href="{{ $css.RelPermalink }}" />
10 changes: 10 additions & 0 deletions layouts/partials/hb/modules/search/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{- $url := partial "search/functions/search-url" . }}
<form class="hb-module hb-search-form position-relative" action="{{ $url }}">
<input name="q" class="form-control form-control-lg pe-5" placeholder="{{ i18n `search` }}">
<button
type="submit"
class="position-absolute end-0 top-0 mt-4 me-4 p-0 border-0 bg-transparent"
title="{{ i18n `search` }}">
{{ partial "icons/icon" (dict "vendor" "bs" "name" "search" "width" "1.5rem" "height" "1.5rem") }}
</button>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- if default true site.Params.hb.search.modal }}
{{ partial "search/assets/js" .Page }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- if default true site.Params.hb.search.modal }}
{{ partial "hb/modules/search/assets/css" .Page }}
{{- end }}

0 comments on commit 4d696c4

Please sign in to comment.