2
0
mirror of https://github.com/tenrok/bootstrap.git synced 2026-06-05 16:42:29 +03:00

docs search: take into account the current URL.

This commit is contained in:
XhmikosR
2018-10-19 19:43:12 +03:00
parent a16ffc7ba1
commit 282b77ee9c
2 changed files with 17 additions and 4 deletions
+16 -3
View File
@@ -12,6 +12,19 @@
var inputElement = document.getElementById('search-input')
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({
apiKey: '5990ad008512000bba2cf951ccf0332f',
indexName: 'bootstrap',
@@ -27,11 +40,11 @@
},
transformData: function (hits) {
return hits.map(function (hit) {
// When in production, return the result as is,
// otherwise remove our url from it.
var siteurl = inputElement.getAttribute('data-siteurl')
var siteurl = getOrigin()
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, '')
return hit