forked from getsentry/sentry-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
029f693
commit 89951f3
Showing
11 changed files
with
81 additions
and
281 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,17 @@ | ||
.search-results { | ||
&:empty { | ||
&::before { | ||
content: 'Searching the docs'; | ||
} | ||
&::after { | ||
content: '...'; | ||
animation-name: search-loading; | ||
animation-duration: 0.75s; | ||
animation-iteration-count: infinite; | ||
} | ||
} | ||
|
||
.path-segment { | ||
color: $jewel0; | ||
#hits { | ||
position: relative; | ||
|
||
+ .path-segment { | ||
&::before { | ||
color: $mediumPurple; | ||
content: ' » '; | ||
} | ||
} | ||
.list-group { | ||
position: absolute; | ||
z-index: 5; | ||
} | ||
} | ||
|
||
@keyframes search-loading { | ||
0% { | ||
content: '.'; | ||
} | ||
33% { | ||
content: '..'; | ||
} | ||
66% { | ||
content: '...'; | ||
} | ||
100% { | ||
content: ''; | ||
} | ||
.ais-Highlight { | ||
color: $highlightPurple; | ||
} | ||
|
||
.search-results { | ||
font-size: 14px; | ||
width: 200%; | ||
} |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,70 +1,46 @@ | ||
import qs from 'query-string'; | ||
import Lunr from './Lunr'; | ||
import { escape } from './Helpers'; | ||
|
||
const renderResult = function(data) { | ||
const relativePath = data.path.replace(/^\/|\/$/g, ''); | ||
|
||
const url = escape(`${window.location.origin}/${relativePath}/`); | ||
const path = relativePath | ||
.split(/[#\/]/) | ||
.map(segment => { | ||
return `<span class="path-segment">${escape(segment)}</span>`; | ||
}) | ||
.join(''); | ||
return $(` | ||
<div class="mb-3"> | ||
<h3 class="h5 mb-0"><a href="${url}">${escape(data.title)}</a></h3> | ||
<div class="pl-2"> | ||
<aside>(${path})</aside> | ||
<p class="mb-0">${escape(data.excerpt)}</p> | ||
</div> | ||
</div> | ||
`); | ||
}; | ||
|
||
const renderResults = function(results, query) { | ||
const $results = $('[data-search-results]').clone(); | ||
if (!results || !results.length) { | ||
const msg = `No results${!!results ? ` matching "${escape(query)}"` : ''}`; | ||
$results.append(`<p>${msg}</p>`); | ||
} | ||
$.each(results, function(i, result) { | ||
$results.append(renderResult(result)); | ||
}); | ||
return $results; | ||
}; | ||
|
||
class Search { | ||
constructor($target) { | ||
this.data; | ||
this.results = {}; | ||
this.pageTemplate = $('html').html(); | ||
|
||
this.init = this.init.bind(this); | ||
|
||
this.$target = $target; | ||
this.Lunr = new Lunr({ | ||
cacheUrl: '/search/cache.json', | ||
indexUrl: '/search/index.json' | ||
}); | ||
} | ||
|
||
// Fetch search results and attach the results | ||
init() { | ||
const params = qs.parse(location.search); | ||
|
||
if (!params.q) { | ||
return Promise.resolve().then(() => { | ||
$('[data-search-results]').append(renderResults()); | ||
}); | ||
import instantsearch from 'instantsearch.js'; | ||
import { searchBox, hits } from 'instantsearch.js/es/widgets'; | ||
$(function() { | ||
const search = instantsearch({ | ||
appId: 'OOK48W9UCL', | ||
apiKey: '2d64ec1106519cbc672d863b0d200782', | ||
indexName: 'sentry-docs', | ||
searchFunction: function(helper) { | ||
var $hits = $('#hits'); | ||
if (helper.state.query === '') { | ||
$hits.addClass('d-none'); | ||
} else { | ||
helper.search(); | ||
$hits.removeClass('d-none'); | ||
} | ||
} | ||
$('input[name="q"]').val(params.q); | ||
}); | ||
|
||
return this.Lunr.search(params.q).then(results => { | ||
$('[data-search-results]').append(renderResults(results, params.q)); | ||
}); | ||
} | ||
} | ||
search.addWidget( | ||
searchBox({ | ||
container: '#search-box', | ||
placeholder: 'Search the docs', | ||
magnifier: false, | ||
reset: false, | ||
cssClasses: { | ||
input: 'form-control' | ||
} | ||
}) | ||
); | ||
|
||
search.addWidget( | ||
hits({ | ||
container: '#hits', | ||
cssClasses: { | ||
root: 'list-group search-results' | ||
}, | ||
templates: { | ||
empty: '<div class="list-group-item">No results</div>', | ||
allItems: | ||
'{{#hits}}<a href="{{ url }}" class="list-group-item list-group-item-action"><h6 class="mb-1">{{{ _highlightResult.title.value }}}</h6>{{{ _snippetResult.content.value }}}</a>{{/hits}}' | ||
} | ||
}) | ||
); | ||
|
||
export default new Search(); | ||
search.start(); | ||
}); |
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
Oops, something went wrong.