-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update search to DocSearch v3 #32098
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
40af85e
Implementation of DocSearch v3 with bootstrap v5 and icon support
shortcuts e1b7f78
Merge branch 'main' into feat/docsearch-v3
shortcuts b931fde
Removed `mark` padding and updated docsearch instance
shortcuts 335a27d
Removed unused options
shortcuts 3af70bf
Merge branch 'main' into feat/docsearch-v3
shortcuts c30298f
Removed unused options and fixed icon centering
shortcuts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,58 +9,122 @@ | |
return | ||
} | ||
|
||
var inputElement = document.getElementById('search-input') | ||
var siteDocsVersion = inputElement.getAttribute('data-docs-version') | ||
|
||
document.addEventListener('keydown', function (event) { | ||
if (event.ctrlKey && event.key === '/') { | ||
event.preventDefault() | ||
inputElement.focus() | ||
} | ||
}) | ||
function isIconHit(hit) { | ||
return hit.hierarchy.lvl0 === 'Bootstrap Icons' | ||
} | ||
|
||
function getOrigin() { | ||
var location = window.location | ||
var origin = location.origin | ||
function IconName(hit) { | ||
return hit.url | ||
.replace(/https:\/\/icons.getbootstrap.com\/icons\//g, '') | ||
.replace(/\/#content/g, '') | ||
} | ||
|
||
if (!origin) { | ||
var port = location.port ? ':' + location.port : '' | ||
function IconSVG(hit) { | ||
return { | ||
type: 'svg', | ||
ref: undefined, | ||
constructor: undefined, | ||
key: undefined, | ||
props: { | ||
width: 20, | ||
height: 20, | ||
fill: 'currentColor', | ||
children: { | ||
type: 'use', | ||
ref: undefined, | ||
constructor: undefined, | ||
key: undefined, | ||
props: { | ||
xlinkHref: | ||
'/docs/5.0/assets/img/bootstrap-icons.svg#' + IconName(hit), | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
origin = location.protocol + '//' + location.hostname + port | ||
function Hits({ hit, children }) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. based on the lint error, I think destructuring might not be allowed in this file |
||
if (isIconHit(hit)) { | ||
return { | ||
type: 'a', | ||
ref: undefined, | ||
constructor: undefined, | ||
key: undefined, | ||
props: { | ||
href: hit.url, | ||
children: { | ||
type: 'div', | ||
ref: undefined, | ||
constructor: undefined, | ||
key: undefined, | ||
props: { | ||
className: 'DocSearch-Hit-Container', | ||
children: [ | ||
{ | ||
type: 'div', | ||
ref: undefined, | ||
constructor: undefined, | ||
key: undefined, | ||
props: { | ||
className: 'DocSearch-Hit-icon', | ||
children: IconSVG(hit), | ||
}, | ||
}, | ||
{ | ||
type: 'div', | ||
ref: undefined, | ||
constructor: undefined, | ||
key: undefined, | ||
props: { | ||
className: 'DocSearch-Hit-content-wrapper', | ||
children: [ | ||
{ | ||
type: 'span', | ||
ref: undefined, | ||
constructor: undefined, | ||
key: undefined, | ||
props: { | ||
className: 'DocSearch-Hit-title', | ||
children: hit.hierarchy.lvl1, | ||
}, | ||
}, | ||
{ | ||
type: 'span', | ||
ref: undefined, | ||
constructor: undefined, | ||
key: undefined, | ||
props: { | ||
className: 'DocSearch-Hit-path', | ||
children: 'Icon', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
return origin | ||
return { | ||
type: 'a', | ||
ref: undefined, | ||
constructor: undefined, | ||
key: undefined, | ||
props: { | ||
href: hit.url, | ||
children, | ||
}, | ||
} | ||
} | ||
|
||
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 ? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the url replacing code likely needs to be put back in the v3 |
||
// 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 | ||
appId: 'BH4D9OD16A', | ||
apiKey: 'c121570761efc762fb8b433b124415fb', | ||
indexName: 'bootstrap-icons', | ||
container: '#search-input', | ||
hitComponent: Hits, | ||
}) | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,22 @@ | ||
// Docsearch theming | ||
|
||
.algolia-autocomplete { | ||
width: 100%; | ||
:root { | ||
--docsearch-primary-color: #7952b3; | ||
} | ||
|
||
.ds-dropdown-menu { | ||
.DocSearch-SearchButton { | ||
width: 100%; | ||
padding: $dropdown-padding-y 0; | ||
margin: $dropdown-spacer 0 0; | ||
@include font-size(.875rem); | ||
background-color: $dropdown-bg; | ||
border: $dropdown-border-width solid $dropdown-border-color; | ||
@include border-radius($dropdown-border-radius); | ||
@include box-shadow($dropdown-box-shadow); | ||
|
||
@include media-breakpoint-up(md) { | ||
width: 400px; | ||
} | ||
} | ||
|
||
.algolia-docsearch-suggestion--category-header { | ||
padding: .125rem 1rem; | ||
font-weight: 600; | ||
color: $bd-purple-bright; | ||
|
||
// stylelint-disable-next-line selector-class-pattern | ||
:not(.algolia-docsearch-suggestion__main) > & { | ||
display: none; | ||
} | ||
|
||
.ds-suggestion:not(:first-child) & { | ||
padding-top: .75rem; | ||
margin-top: .75rem; | ||
border-top: 1px solid rgba(0, 0, 0, .1); | ||
} | ||
} | ||
|
||
.algolia-docsearch-suggestion--content { | ||
padding: .25rem 1rem; | ||
|
||
.ds-cursor & { | ||
background-color: rgba($bd-purple-light, .2); | ||
} | ||
} | ||
|
||
.algolia-docsearch-suggestion { | ||
display: block; | ||
text-decoration: none; | ||
} | ||
|
||
.algolia-docsearch-suggestion--subcategory-column { | ||
display: none; | ||
} | ||
|
||
.algolia-docsearch-suggestion--subcategory-inline { | ||
display: inline; | ||
color: $gray-700; | ||
|
||
&::after { | ||
padding: 0 .25rem; | ||
content: "/"; | ||
} | ||
} | ||
|
||
.algolia-docsearch-suggestion--title { | ||
display: inline; | ||
font-weight: 500; | ||
color: $gray-800; | ||
} | ||
|
||
.algolia-docsearch-suggestion--text { | ||
color: $gray-800; | ||
@include font-size(.75rem); | ||
margin: 0px; | ||
border-radius: 0.25rem; | ||
} | ||
|
||
.algolia-docsearch-suggestion--highlight { | ||
color: $purple; | ||
background-color: rgba($purple, .1); | ||
.DocSearch-Hit-content-wrapper { | ||
overflow: hidden; | ||
} | ||
|
||
.algolia-docsearch-footer { | ||
padding: .5rem 1rem 0; | ||
margin-top: .625rem; | ||
@include font-size(.75rem); | ||
color: $gray-600; | ||
border-top: 1px solid rgba(0, 0, 0, .1); | ||
.DocSearch-Modal mark { | ||
padding: 0; | ||
} | ||
|
||
.algolia-docsearch-footer--logo { | ||
color: inherit; | ||
.DocSearch-Modal svg { | ||
vertical-align: unset; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.