0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-11-29 11:24:18 +01:00

Alternative solution.

Rely on `site.url` which is different for production. In that case do nothing with the search result, otherwise when in development remove our url from it.
This commit is contained in:
XhmikosR 2018-03-14 19:44:32 +02:00
parent 483e49e3c6
commit b9577a1cf7
2 changed files with 8 additions and 3 deletions

View File

@ -1,5 +1,5 @@
<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-baseurl="{{ site.baseurl }}/docs/{{ site.docs_version }}">
<input type="search" class="form-control" id="search-input" placeholder="Search..." aria-label="Search for..." autocomplete="off" data-siteurl="{{ site.url }}">
<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" -%}
</button>

View File

@ -115,8 +115,13 @@
},
transformData: function (hits) {
return hits.map(function (hit) {
var baseurl = document.getElementById('search-input').getAttribute('data-baseurl')
hit.url = hit.url.replace('https://getbootstrap.com' + baseurl, baseurl)
// When in production, return the result as is,
// otherwise remove our url from it.
var siteurl = document.getElementById('search-input').getAttribute('data-siteurl')
var urlRE = /^https?:\/\/getbootstrap\.com/
hit.url = siteurl.match(urlRE) ? hit.url : hit.url.replace(urlRE, '')
return hit
})
},