]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
docs: enable OpenSearch
authorMartijn Cuppens <martijn.cuppens@gmail.com>
Mon, 16 Dec 2019 19:41:44 +0000 (21:41 +0200)
committerXhmikosR <xhmikosr@gmail.com>
Mon, 11 Mar 2024 19:05:44 +0000 (21:05 +0200)
site/assets/js/search.js
site/layouts/partials/header.html
site/static/documentation-search.xml [new file with mode: 0644]

index b095d3bbd95d6b04d91ac4bc898fc889e5279012..8ff2f934c5a7bdcba4e48bbb0c55deed8b9dcad6 100644 (file)
@@ -13,7 +13,7 @@
 
   const siteDocsVersion = searchElement.getAttribute('data-bd-docs-version')
 
-  window.docsearch({
+  const search = window.docsearch({
     apiKey: '3151f502c7b9e9dafd5e6372b691a24e',
     indexName: 'bootstrap',
     appId: 'AK7KMZKZHQ',
       })
     }
   })
+
+  function hashSearch() {
+    if (window.location.hash && window.location.hash.indexOf('#search=') === 0) {
+      search.input.autocomplete.setVal(window.location.hash.slice(8))
+      search.input.autocomplete.open()
+    }
+  }
+
+  hashSearch()
+  // For the nerds: search by changing the url hash
+  window.addEventListener('hashchange', hashSearch, false)
 })()
index ba58893286a06dfbcdee2251134c15a572ccd606..a7ad916ee8209872240eb171f47a3736b4c5062c 100644 (file)
@@ -10,6 +10,7 @@
 <title>{{ if .IsHome }}{{ .Site.Title | markdownify }} · {{ .Site.Params.subtitle | markdownify }}{{ else }}{{ .Title | markdownify }} · {{ .Site.Title | markdownify }} v{{ .Site.Params.docs_version }}{{ end }}</title>
 
 <link rel="canonical" href="{{ .Permalink }}">
+<link rel="search" href="/documentation-search.xml" type="application/opensearchdescription+xml">
 
 <link rel="preconnect" href="https://AK7KMZKZHQ-dsn.algolia.net" crossorigin>
 
diff --git a/site/static/documentation-search.xml b/site/static/documentation-search.xml
new file mode 100644 (file)
index 0000000..9fdd82d
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
+  <ShortName>Bootstrap Documentation</ShortName>
+  <Description>Search in the latest Bootstrap documentation</Description>
+  <Image height="16" width="16" type="image/x-icon">https://deploy-preview-29872--twbs-bootstrap.netlify.com/favicon.ico</Image>
+  <Url type="text/html" method="get" template="https://deploy-preview-29872--twbs-bootstrap.netlify.com/docs/4.3/getting-started/introduction/#search={searchTerms}" />
+</OpenSearchDescription>