From a1c09804f28ad43a2f91cdf6fb6f0331cbcab580 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 13 Mar 2024 08:38:53 +0200 Subject: [PATCH] docs: move algolia config to hugo config --- hugo.yml | 5 +++++ site/assets/js/search.js | 9 ++++++--- site/layouts/partials/header.html | 2 +- site/layouts/partials/scripts.html | 6 ++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/hugo.yml b/hugo.yml index ba23d38c0260..1ff261b04228 100644 --- a/hugo.yml +++ b/hugo.yml @@ -73,6 +73,11 @@ params: analytics: fathom_site: "ITUSEYJG" + algolia: + appId: "AK7KMZKZHQ" + apiKey: "3151f502c7b9e9dafd5e6372b691a24e" + indexName: "bootstrap" + download: source: "https://github.com/twbs/bootstrap/archive/v5.3.3.zip" dist: "https://github.com/twbs/bootstrap/releases/download/v5.3.3/bootstrap-5.3.3-dist.zip" diff --git a/site/assets/js/search.js b/site/assets/js/search.js index 95d920c445fe..48047abc8750 100644 --- a/site/assets/js/search.js +++ b/site/assets/js/search.js @@ -10,6 +10,9 @@ */ import docsearch from '@docsearch/js' +// https://gohugo.io/hugo-pipes/js/#options +// eslint-disable-next-line import/no-unresolved +import { appId, apiKey, indexName } from '@params'; (() => { const searchElement = document.getElementById('docsearch') @@ -21,9 +24,9 @@ import docsearch from '@docsearch/js' const siteDocsVersion = searchElement.getAttribute('data-bd-docs-version') docsearch({ - apiKey: '3151f502c7b9e9dafd5e6372b691a24e', - indexName: 'bootstrap', - appId: 'AK7KMZKZHQ', + apiKey, + indexName, + appId, container: searchElement, searchParameters: { facetFilters: [`version:${siteDocsVersion}`] diff --git a/site/layouts/partials/header.html b/site/layouts/partials/header.html index 3f259ac5e842..66bdf2fb1bcf 100644 --- a/site/layouts/partials/header.html +++ b/site/layouts/partials/header.html @@ -10,7 +10,7 @@ {{ if (ne .Page.Layout "examples") -}} - + {{- end }} {{ if .IsHome }}{{ .Site.Title | markdownify }} · {{ .Site.Params.subtitle | markdownify }}{{ else }}{{ .Title | markdownify }} · {{ .Site.Title | markdownify }} v{{ .Site.Params.docs_version }}{{ end }} diff --git a/site/layouts/partials/scripts.html b/site/layouts/partials/scripts.html index 9d9f797d87d1..a7297dc0bca9 100644 --- a/site/layouts/partials/scripts.html +++ b/site/layouts/partials/scripts.html @@ -15,6 +15,12 @@ {{- if (ne .Page.Layout "examples") -}} +{{- $esbuildParams := dict + "apiKey" .Site.Params.algolia.apiKey + "appId" .Site.Params.algolia.appId + "indexName" .Site.Params.algolia.indexName +-}} +{{- $esbuildOptions = merge $esbuildOptions (dict "params" $esbuildParams) -}} {{- $searchJs := resources.Get "js/search.js" | js.Build $esbuildOptions | resources.Copy (path.Join $targetDocsJSPath "/assets/js/search.js") }} {{- end -}}