Commit b9577a1c authored by XhmikosR's avatar XhmikosR
Browse files

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.
parent 483e49e3
Showing with 8 additions and 3 deletions
+8 -3
<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>
......
......@@ -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
})
},
......
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