diff --git a/config.yml b/config.yml index 616993e15..c9e203164 100644 --- a/config.yml +++ b/config.yml @@ -20,6 +20,18 @@ enableRobotsTXT: true metaDataFormat: "yaml" disableKinds: ["404", "taxonomy", "taxonomyTerm", "RSS"] +outputFormats: + OpenSearch: + baseName: opensearch + isPlainText: true + mediaType: application/xml + notAlternative: true + +outputs: + home: + - HTML + - OpenSearch + publishDir: "_gh_pages" module: diff --git a/site/assets/js/search.js b/site/assets/js/search.js index d88263d3f..ce9e1b318 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,18 @@ // Set debug to `true` if you want to inspect the dropdown debug: false }) + + function hashSearch() { + var SEARCH_WORD = '#search=' + + if (window.location.hash && window.location.hash.startsWith(SEARCH_WORD)) { + search.input.autocomplete.setVal(window.location.hash.slice(SEARCH_WORD.length)) + search.input.autocomplete.open() + } + } + + hashSearch() + + // For the nerds: search by changing the url hash + window.addEventListener('hashchange', hashSearch, false) })() diff --git a/site/layouts/_default/list.opensearch.xml b/site/layouts/_default/list.opensearch.xml new file mode 100644 index 000000000..15258eb65 --- /dev/null +++ b/site/layouts/_default/list.opensearch.xml @@ -0,0 +1,8 @@ + + + {{ .Site.Title }} + Search {{ .Site.Title }} documentation + UTF-8 + {{ (printf "/docs/%s/assets/img/favicons/favicon.ico" .Site.Params.docs_version) | absURL }} + + diff --git a/site/layouts/partials/header.html b/site/layouts/partials/header.html index 2d2eb29d9..4eddd4715 100644 --- a/site/layouts/partials/header.html +++ b/site/layouts/partials/header.html @@ -11,6 +11,10 @@ +{{ with .OutputFormats.Get "opensearch" -}} + +{{ end -}} + {{ with .Params.robots -}} {{- end }}