add demo
This commit is contained in:
Родитель
5aa57d92a6
Коммит
b656cc9a13
|
@ -0,0 +1,8 @@
|
|||
const index = require('.')
|
||||
|
||||
module.exports = {
|
||||
context: [
|
||||
{name: 'index', value: index},
|
||||
{name: 'titles', value: index.map(index => index.title)}
|
||||
]
|
||||
}
|
|
@ -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
|
||||
// })
|
11
package.json
11
package.json
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче