File tree Expand file tree Collapse file tree 4 files changed +56
-0
lines changed
components/docs-viewer/x-nav Expand file tree Collapse file tree 4 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ export default Component.extend({
77 layout,
88
99 store : service ( ) ,
10+ docsSearch : service ( ) ,
1011
1112 tagName : 'nav' ,
1213
@@ -16,6 +17,11 @@ export default Component.extend({
1617 return this . get ( 'store' ) . peekAll ( 'project-version' ) . get ( 'firstObject' ) ;
1718 } ) ,
1819
20+ init ( ) {
21+ this . _super ( ) ;
22+ this . get ( 'docsSearch' ) . loadSearchIndex ( ) ;
23+ }
24+
1925 // didInsertElement() {
2026 // this._super(...arguments);
2127 //
Original file line number Diff line number Diff line change 1+ import Service from '@ember/service' ;
2+ import { getOwner } from '@ember/application' ;
3+ import { computed } from '@ember/object' ;
4+ import $ from 'jquery' ;
5+ import lunr from 'lunr' ;
6+
7+ export default Service . extend ( {
8+ search ( phrase , { exact = false } = { } ) {
9+ if ( ! exact ) {
10+ phrase = `*${ phrase } *` ;
11+ }
12+
13+ return this . loadSearchIndex ( )
14+ . then ( ( { index, documents } ) => {
15+ return index . search ( phrase ) . map ( resultInfo => {
16+ let document = documents [ resultInfo . ref ] ;
17+ return { resultInfo, document } ;
18+ } ) ;
19+ } ) ;
20+ } ,
21+
22+ loadSearchIndex ( ) {
23+ if ( ! this . _searchIndex ) {
24+ this . _searchIndex = $ . get ( this . get ( '_indexURL' ) )
25+ . then ( json => {
26+ return {
27+ index : lunr . Index . load ( json . index ) ,
28+ documents : json . documents
29+ } ;
30+ } ) ;
31+ }
32+
33+ return this . _searchIndex ;
34+ } ,
35+
36+ _indexURL : computed ( function ( ) {
37+ let config = getOwner ( this ) . resolveRegistration ( 'config:environment' ) ;
38+ return `${ config . rootURL } ember-cli-addon-docs/search-index.json` ;
39+ } )
40+ } ) ;
Original file line number Diff line number Diff line change 1+ export { default } from 'ember-cli-addon-docs/services/docs-search' ;
Original file line number Diff line number Diff line change @@ -64,6 +64,10 @@ module.exports = {
6464 let importer = findImporter ( this ) ;
6565
6666 importer . import ( `${ this . _hasEmberSource ( ) ? 'vendor' : 'bower_components' } /ember/ember-template-compiler.js` ) ;
67+ importer . import ( 'vendor/lunr/lunr.js' , {
68+ using : [ { transformation : 'amd' , as : 'lunr' } ]
69+ } ) ;
70+
6771 // importer.import('vendor/highlightjs-styles/default.css');
6872 // importer.import('vendor/styles/highlightjs-styles/default.css');
6973 // importer.import('vendor/highlight.js/styles/monokai.css');
@@ -91,6 +95,7 @@ module.exports = {
9195 return new MergeTrees ( [
9296 vendor ,
9397 this . _highlightJSTree ( ) ,
98+ this . _lunrTree ( ) ,
9499 this . _templateCompilerTree ( )
95100 ] . filter ( Boolean ) ) ;
96101 } ,
@@ -118,6 +123,10 @@ module.exports = {
118123 return new MergeTrees ( [ defaultTree , docsTree , searchIndexTree ] ) ;
119124 } ,
120125
126+ _lunrTree ( ) {
127+ return new Funnel ( path . dirname ( require . resolve ( 'lunr/package.json' ) ) , { destDir : 'lunr' } ) ;
128+ } ,
129+
121130 _highlightJSTree ( ) {
122131 return new Funnel ( path . dirname ( require . resolve ( 'highlightjs/package.json' ) ) , {
123132 srcDir : 'styles' ,
You can’t perform that action at this time.
0 commit comments