cheatsheets/_parcel/behaviors/searchable-item.js

14 lines
365 B
JavaScript

import onmount from 'onmount'
import permutate from '../helpers/permutate'
/**
* Sets search indices (`data-search-index` attribute)
*/
onmount('[data-js-searchable-item]', function () {
const data = JSON.parse(this.getAttribute('data-js-searchable-item') || '{}')
const words = permutate(data)
this.setAttribute('data-search-index', words.join(' '))
})