This commit is contained in:
Zeke Sikelianos 2018-05-14 08:27:08 -07:00
Родитель 5aa57d92a6
Коммит b656cc9a13
3 изменённых файлов: 109 добавлений и 2 удалений

8
.replrc.js Normal file
Просмотреть файл

@ -0,0 +1,8 @@
const index = require('.')
module.exports = {
context: [
{name: 'index', value: index},
{name: 'titles', value: index.map(index => index.title)}
]
}

92
demo.js Normal file
Просмотреть файл

@ -0,0 +1,92 @@
const html = require('nanohtml')
const instantsearch = require('instantsearch.js')
document.title = 'Electron Search'
const $main = html`
<main>
<style>
* {
box-sizing: border-box;
}
body {
padding: 50px;
font-family: 'helvetica neue', helvetica, arial;
}
#search-box input {
padding: 10px;
width: 100%;
}
.ais-hits--item {
padding: 10px;
}
.ais-hits--item em {
background-color: yellow;
}
.ais-search-box--magnifier {
display: none;
}
.ais-search-box--reset {
top: 12px;
width: 30px;
height: 30px;
border: none;
position: absolute;
right: 10px;
opacity: 0.2;
}
</style>
<div id="search-box"></div>
<div id="refinement-list"></div>
<div id="hits"></div>
</main>
`
document.body.appendChild($main)
const search = instantsearch({
appId: 'L9LD9GHGQJ',
apiKey: '24e7e99910a15eb5d9d93531e5682370',
indexName: 'electron-apis',
routing: true
})
search.addWidget(
instantsearch.widgets.hits({
container: '#hits',
templates: {
empty: 'No results',
item: `
<b>{{{_highlightResult.title.value}}}</b> -
{{{_highlightResult.tldr.value}}}
`
}
})
)
search.addWidget(
instantsearch.widgets.searchBox({
container: '#search-box',
placeholder: 'Search Electron APIs'
})
)
search.addWidget(
instantsearch.widgets.refinementList({
container: '#refinement-list',
attributeName: 'type'
})
)
search.start()
// autocomplete(/* your existing code */)
// .on('autocomplete:selected', function (event, suggestion, dataset) {
// location.href = suggestion.url
// })

Просмотреть файл

@ -9,13 +9,20 @@
"scripts": {
"build": "script/build.js > index.json",
"pretest": "npm run build",
"test": "tape test.js | tap-spec && standard --fix"
"test": "tape test.js | tap-spec && standard --fix",
"lint": "standard --fix",
"demo": "budo demo.js --live --no-debug --open",
"repl": "local-repl"
},
"devDependencies": {
"budo": "^11.2.0",
"instantsearch.js": "^2.7.4",
"is-url": "^1.2.4",
"local-repl": "^4.0.0",
"nanohtml": "^1.2.4",
"prettier-standard": "^8.0.1",
"standard": "^11.0.1",
"tap-spec": "^4.1.1",
"tape": "^4.9.0"
}
}
}