From ecfddb4e383e0ca3a6abe827bd93cfcf5e943791 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 b095d3bbd9..8ff2f934c5 100644 --- a/site/assets/js/search.js +++ b/site/assets/js/search.js @@ -13,7 +13,7 @@ const siteDocsVersion = searchElement.getAttribute('data-bd-docs-version') - window.docsearch({ + const search = window.docsearch({ apiKey: '3151f502c7b9e9dafd5e6372b691a24e', indexName: 'bootstrap', appId: 'AK7KMZKZHQ', @@ -42,4 +42,15 @@ }) } }) + + 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 ba58893286..a7ad916ee8 100644 --- a/site/layouts/partials/header.html +++ b/site/layouts/partials/header.html @@ -10,6 +10,7 @@ {{ 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/static/documentation-search.xml b/site/static/documentation-search.xml new file mode 100644 index 0000000000..9fdd82d496 --- /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 + +