mirror of
https://github.com/twbs/bootstrap.git
synced 2024-12-03 15:24:19 +01:00
b46f05a948
This commit includes all the needed workarounds and most changes from the main branch for everything to work, like: * removing empty lines in raw HTML that break output * read .browserslistrc, CSS variables from disk instead of duplicating it * using Hugo mounts * using Hugo for the docs CSS/JS * move ToC Sass code to a separate file while adapting it for Hugo Thus, this patch makes our npm scripts faster since lint runs on one step and there's no separate docs assets processing.
61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
|
|
// IT'S ALL JUST JUNK FOR OUR DOCS!
|
|
// ++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
(function () {
|
|
'use strict'
|
|
|
|
var inputElement = document.getElementById('search-input')
|
|
|
|
if (!window.docsearch || !inputElement) {
|
|
return
|
|
}
|
|
|
|
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',
|
|
inputSelector: '#search-input',
|
|
algoliaOptions: {
|
|
facetFilters: ['version:' + siteDocsVersion]
|
|
},
|
|
transformData: function (hits) {
|
|
return hits.map(function (hit) {
|
|
var currentUrl = getOrigin()
|
|
var liveUrl = 'https://getbootstrap.com/'
|
|
|
|
hit.url = currentUrl.lastIndexOf(liveUrl, 0) === 0 ?
|
|
// On production, return the result as is
|
|
hit.url :
|
|
// On development or Netlify, replace `hit.url` with a trailing slash,
|
|
// so that the result link is relative to the server root
|
|
hit.url.replace(liveUrl, '/')
|
|
|
|
// Prevent jumping to first header
|
|
if (hit.anchor === 'content') {
|
|
hit.url = hit.url.replace(/#content$/, '')
|
|
hit.anchor = null
|
|
}
|
|
|
|
return hit
|
|
})
|
|
},
|
|
// Set debug to `true` if you want to inspect the dropdown
|
|
debug: false
|
|
})
|
|
})()
|