mirror of https://github.com/onweru/compose.git

weru
31.38.2021 dd3d144201ce9994503a4f69f6368b781cd1035f
refactor script #29
1 files modified
26 ■■■■ changed files
assets/js/search.js 26 ●●●● patch | view | raw | blame | history
assets/js/search.js
@@ -1,13 +1,4 @@
const idx = [
  {{- range .Site.Pages }}
  {
    "link": "{{ .Permalink }}",
    "title": "{{ .Title }}",
    "body": `{{ .PlainWords }}`.toLowerCase() // @TODO: move this definition to an index.json file.
  },
  {{- end }}
];
function initializeSearch(index) {
const searchKeys = ['title', 'link', 'body', 'id'];
const searchPageElement = elem('#searchpage');
@@ -21,7 +12,7 @@
  threshold: 0.0
};
const index = new Fuse(idx, searchOptions);
  index = new Fuse(index, searchOptions);
function minQueryLen(query) {
  query = query.trim();
@@ -187,14 +178,12 @@
  main = elem('.main');
}
window.addEventListener('load', function() {
  searchPageElement ? false : liveSearch();
  passiveSearch();
  wrapText(findQuery(), main);
  onEscape(clearSearchResults);
});
window.addEventListener('click', function(event){
  const target = event.target;
@@ -203,3 +192,14 @@
    clearSearchResults();
  }
});
}
window.addEventListener('load', function() {
  fetch("/index.json")
  .then(response => response.json())
  .then(function(data) {
    data = data.length ? data : [];
    initializeSearch(data);
  })
  .catch((error) => console.error(error));
});