Commit 282b77ee authored by XhmikosR's avatar XhmikosR
Browse files

docs search: take into account the current URL.

parent a16ffc7b
Showing with 17 additions and 4 deletions
+17 -4
<form class="bd-search d-flex align-items-center"> <form class="bd-search d-flex align-items-center">
<input type="search" class="form-control" id="search-input" placeholder="Search..." aria-label="Search for..." autocomplete="off" data-siteurl="{{ site.url }}" data-docs-version="{{ site.docs_version }}"> <input type="search" class="form-control" id="search-input" placeholder="Search..." aria-label="Search for..." autocomplete="off" data-docs-version="{{ site.docs_version }}">
<button class="btn btn-link bd-search-docs-toggle d-md-none p-0 ml-3" type="button" data-toggle="collapse" data-target="#bd-docs-nav" aria-controls="bd-docs-nav" aria-expanded="false" aria-label="Toggle docs navigation"> <button class="btn btn-link bd-search-docs-toggle d-md-none p-0 ml-3" type="button" data-toggle="collapse" data-target="#bd-docs-nav" aria-controls="bd-docs-nav" aria-expanded="false" aria-label="Toggle docs navigation">
{%- include icons/menu.svg width="30" height="30" -%} {%- include icons/menu.svg width="30" height="30" -%}
</button> </button>
......
...@@ -12,6 +12,19 @@ ...@@ -12,6 +12,19 @@
var inputElement = document.getElementById('search-input') var inputElement = document.getElementById('search-input')
var siteDocsVersion = inputElement.getAttribute('data-docs-version') var siteDocsVersion = inputElement.getAttribute('data-docs-version')
function getOrigin() {
var location = window.location
var origin = location.origin
if (!origin) {
var port = location.port ? ':' + location.port : ''
origin = location.protocol + '//' + location.hostname + port
}
return origin
}
window.docsearch({ window.docsearch({
apiKey: '5990ad008512000bba2cf951ccf0332f', apiKey: '5990ad008512000bba2cf951ccf0332f',
indexName: 'bootstrap', indexName: 'bootstrap',
...@@ -27,11 +40,11 @@ ...@@ -27,11 +40,11 @@
}, },
transformData: function (hits) { transformData: function (hits) {
return hits.map(function (hit) { return hits.map(function (hit) {
// When in production, return the result as is, var siteurl = getOrigin()
// otherwise remove our url from it.
var siteurl = inputElement.getAttribute('data-siteurl')
var urlRE = /^https?:\/\/getbootstrap\.com/ var urlRE = /^https?:\/\/getbootstrap\.com/
// When in production, return the result as is,
// otherwise remove our url from it.
hit.url = siteurl.match(urlRE) ? hit.url : hit.url.replace(urlRE, '') hit.url = siteurl.match(urlRE) ? hit.url : hit.url.replace(urlRE, '')
return hit return hit
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment