search-input.html 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. {{ .Scratch.Set "docsy-search" 0 -}}
  2. {{ if .Site.Params.gcs_engine_id -}}
  3. {{ .Scratch.Add "docsy-search" 1 -}}
  4. <div class="td-search">
  5. <div class="td-search__icon"></div>
  6. <input type="search" class="td-search__input form-control td-search-input" placeholder="{{ T "ui_search" }}" aria-label="{{ T "ui_search" }}" autocomplete="off">
  7. </div>
  8. {{- end -}}
  9. {{ if and .Site.Params.search (isset .Site.Params.search "algolia") -}}
  10. {{ .Scratch.Add "docsy-search" 1 -}}
  11. {{ .Scratch.Add "docsearch-id-num" 1 -}}
  12. <div class="td-search">
  13. <div class="td-search--algolia" id="docsearch-{{ mod (.Scratch.Get "docsearch-id-num") 2 }}"></div>
  14. </div>
  15. {{- end -}}
  16. {{ if .Site.Params.offlineSearch -}}
  17. {{ .Scratch.Add "docsy-search" 1 -}}
  18. {{ $offlineSearchIndex := resources.Get "json/offline-search-index.json" | resources.ExecuteAsTemplate "offline-search-index.json" . -}}
  19. {{ if hugo.IsProduction -}}
  20. {{/* Use `md5` as finger print hash function to shorten file name to avoid `file name too long` error. */ -}}
  21. {{ $offlineSearchIndex = $offlineSearchIndex | fingerprint "md5" -}}
  22. {{ end -}}
  23. {{ $offlineSearchLink := $offlineSearchIndex.RelPermalink -}}
  24. <div class="td-search td-search--offline">
  25. <div class="td-search__icon"></div>
  26. <input
  27. type="search"
  28. class="td-search__input form-control"
  29. placeholder="{{ T "ui_search" }}"
  30. aria-label="{{ T "ui_search" }}"
  31. autocomplete="off"
  32. {{/*
  33. The data attribute name of the json file URL must end with `src` since
  34. Hugo's absurlreplacer requires `src`, `href`, `action` or `srcset` suffix for the attribute name.
  35. If the absurlreplacer is not applied, the URL will start with `/`.
  36. It causes the json file loading error when when relativeURLs is enabled.
  37. https://github.com/google/docsy/issues/181
  38. */}}
  39. data-offline-search-index-json-src="{{ $offlineSearchLink }}"
  40. data-offline-search-base-href="/"
  41. data-offline-search-max-results="{{ .Site.Params.offlineSearchMaxResults | default 10 }}"
  42. >
  43. </div>
  44. {{- end -}}
  45. {{ if gt (.Scratch.Get "docsy-search") 1 -}}
  46. {{ warnf `You have more than one site-search option configured: choose only one.
  47. For details, see https://www.docsy.dev/docs/adding-content/search.` -}}
  48. {{ end -}}