aboutsummaryrefslogtreecommitdiff
path: root/site/assets/js/search.js
diff options
context:
space:
mode:
authorBobby <[email protected]>2024-08-16 20:47:33 -0400
committerGitHub <[email protected]>2024-08-16 20:47:33 -0400
commit6b28433d9cfde435be8ec2bd6cf91e6324d08865 (patch)
tree8343c27b8b95ff5639233e81cf157f92e5688466 /site/assets/js/search.js
parentd53094ec16ba385faae2973ddee648698b32ab24 (diff)
parent048f56f51460df75e92a2f7b472e1c56baeb68f7 (diff)
downloadbootstrap-main.tar.xz
bootstrap-main.zip
Merge branch 'twbs:main' into mainHEADmain
Diffstat (limited to 'site/assets/js/search.js')
-rw-r--r--site/assets/js/search.js70
1 files changed, 36 insertions, 34 deletions
diff --git a/site/assets/js/search.js b/site/assets/js/search.js
index d88263d3f..48047abc8 100644
--- a/site/assets/js/search.js
+++ b/site/assets/js/search.js
@@ -2,52 +2,54 @@
// IT'S ALL JUST JUNK FOR OUR DOCS!
// ++++++++++++++++++++++++++++++++++++++++++
-(function () {
- 'use strict'
-
- var inputElement = document.getElementById('search-input')
-
- if (!window.docsearch || !inputElement) {
+/*!
+ * JavaScript for Bootstrap's docs (https://getbootstrap.com/)
+ * Copyright 2024 The Bootstrap Authors
+ * Licensed under the Creative Commons Attribution 3.0 Unported License.
+ * For details, see https://creativecommons.org/licenses/by/3.0/.
+ */
+
+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')
+
+ if (!searchElement) {
return
}
- var siteDocsVersion = inputElement.getAttribute('data-bd-docs-version')
+ const siteDocsVersion = searchElement.getAttribute('data-bd-docs-version')
- document.addEventListener('keydown', function (event) {
- if (event.ctrlKey && event.key === '/') {
- event.preventDefault()
- inputElement.focus()
- }
- })
-
- window.docsearch({
- apiKey: '5990ad008512000bba2cf951ccf0332f',
- indexName: 'bootstrap',
- inputSelector: '#search-input',
- algoliaOptions: {
- facetFilters: ['version:' + siteDocsVersion]
+ docsearch({
+ apiKey,
+ indexName,
+ appId,
+ container: searchElement,
+ searchParameters: {
+ facetFilters: [`version:${siteDocsVersion}`]
},
- transformData: function (hits) {
- return hits.map(function (hit) {
- var liveUrl = 'https://getbootstrap.com/'
+ transformItems(items) {
+ return items.map(item => {
+ const liveUrl = 'https://getbootstrap.com/'
- hit.url = window.location.origin.startsWith(liveUrl) ?
+ item.url = window.location.origin.startsWith(liveUrl) ?
// On production, return the result as is
- hit.url :
- // On development or Netlify, replace `hit.url` with a trailing slash,
+ item.url :
+ // On development or Netlify, replace `item.url` with a trailing slash,
// so that the result link is relative to the server root
- hit.url.replace(liveUrl, '/')
+ item.url.replace(liveUrl, '/')
// Prevent jumping to first header
- if (hit.anchor === 'content') {
- hit.url = hit.url.replace(/#content$/, '')
- hit.anchor = null
+ if (item.anchor === 'content') {
+ item.url = item.url.replace(/#content$/, '')
+ item.anchor = null
}
- return hit
+ return item
})
- },
- // Set debug to `true` if you want to inspect the dropdown
- debug: false
+ }
})
})()