Peter Stuifzand
62bad5ec91
All checks were successful
continuous-integration/drone/push Build is passing
46 lines
1.6 KiB
JavaScript
46 lines
1.6 KiB
JavaScript
import Fuse from 'fuse.js'
|
|
|
|
function createTitleSearch() {
|
|
return new Promise(function (resolve, reject) {
|
|
fetch('/links.json')
|
|
.then(result => result.json())
|
|
.then(documents => {
|
|
const options = {
|
|
keys: ['title'],
|
|
}
|
|
|
|
let commands = [
|
|
{title: 'Current Time', name: 'time'},
|
|
{title: 'Today', name: 'today'},
|
|
{title: 'Tomorrow', name: 'tomorrow'},
|
|
{title: 'Yesterday', name: 'yesterday'},
|
|
{title: 'TODO', name: 'todo'},
|
|
{title: 'DONE', name: 'done'},
|
|
{title: 'Page Reference', name: 'page_reference'},
|
|
{title: 'Code Block', name: 'code_block'},
|
|
];
|
|
|
|
const fuseIndex = Fuse.createIndex(options.keys, documents)
|
|
let titleFuse = new Fuse(documents, options, fuseIndex)
|
|
let commandFuse = new Fuse(commands, {keys: ['title', 'name']})
|
|
|
|
resolve({
|
|
documents,
|
|
titleSearch: query => {
|
|
return new Promise((resolve, reject) => {
|
|
resolve(titleFuse.search(query))
|
|
})
|
|
},
|
|
commandSearch: query => {
|
|
return new Promise((resolve, reject) => {
|
|
resolve(commandFuse.search(query))
|
|
})
|
|
},
|
|
commands: commands,
|
|
})
|
|
})
|
|
})
|
|
}
|
|
|
|
export default createTitleSearch
|