From 55c06064f8d282d83119c52926ff31de043240af Mon Sep 17 00:00:00 2001 From: Martijn Cuppens Date: Mon, 16 Dec 2019 21:41:44 +0200 Subject: [PATCH] docs: enable OpenSearch --- site/assets/js/search.js | 13 ++++++++++++- site/layouts/partials/header.html | 1 + site/static/documentation-search.xml | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 site/static/documentation-search.xml diff --git a/site/assets/js/search.js b/site/assets/js/search.js index d88263d3f..b7ab91eba 100644 --- a/site/assets/js/search.js +++ b/site/assets/js/search.js @@ -20,7 +20,7 @@ } }) - window.docsearch({ + var search = window.docsearch({ apiKey: '5990ad008512000bba2cf951ccf0332f', indexName: 'bootstrap', inputSelector: '#search-input', @@ -50,4 +50,15 @@ // Set debug to `true` if you want to inspect the dropdown debug: false }) + + 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) })() diff --git a/site/layouts/partials/header.html b/site/layouts/partials/header.html index 2d2eb29d9..114112f80 100644 --- a/site/layouts/partials/header.html +++ b/site/layouts/partials/header.html @@ -10,6 +10,7 @@ {{ if .IsHome }}{{ .Site.Title | markdownify }} · {{ .Site.Params.description | markdownify }}{{ else }}{{ .Title | markdownify }} · {{ .Site.Title | markdownify }} v{{ .Site.Params.docs_version }}{{ end }} + {{ with .Params.robots -}} diff --git a/site/static/documentation-search.xml b/site/static/documentation-search.xml new file mode 100644 index 000000000..9fdd82d49 --- /dev/null +++ b/site/static/documentation-search.xml @@ -0,0 +1,7 @@ + + + Bootstrap Documentation + Search in the latest Bootstrap documentation + https://deploy-preview-29872--twbs-bootstrap.netlify.com/favicon.ico + +