From 6b4245b4889b5f251d7d2e70df6c4199b2a4e617 Mon Sep 17 00:00:00 2001 From: Diego CC Date: Fri, 7 Jun 2024 12:30:50 +0200 Subject: [PATCH] load projects index on page load --- .eleventy.js | 1 - src/js/functions.js | 12 +++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.eleventy.js b/.eleventy.js index 77361d7..64ae8c0 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -1,6 +1,5 @@ const lunr = require("lunr"); const markdownit = require("markdown-it"); -const mila = require("markdown-it-link-attributes"); const CleanCSS = require("clean-css"); module.exports = function (eleventyConfig) { diff --git a/src/js/functions.js b/src/js/functions.js index f6ee4d7..a9cd299 100644 --- a/src/js/functions.js +++ b/src/js/functions.js @@ -194,6 +194,8 @@ async function resetServicesMenu() { } export async function initProjectSearch() { + // load the index data + const indexData = await _requestIndex(); // search when the user types const searchInput = document.getElementById("text-input"); searchInput.addEventListener("input", () => { @@ -201,14 +203,14 @@ export async function initProjectSearch() { const category = document.querySelector( 'input[name="category"]:checked' ).value; - _projectSearch(searchInput.value, category); + _projectSearch(searchInput.value, category, indexData); }); // search when the user selects a category const categoryInputs = document.querySelectorAll('input[name="category"]'); categoryInputs.forEach((input) => { input.addEventListener("change", () => { console.log(input.value); - _projectSearch(searchInput.value, input.value); + _projectSearch(searchInput.value, input.value, indexData); }); }); const urlParams = new URLSearchParams(window.location.search); @@ -218,13 +220,13 @@ export async function initProjectSearch() { document.querySelector( `input[name="category"][value="${category}"]` ).checked = true; - await _projectSearch("", category); + await _projectSearch("", category, indexData); } } -async function _projectSearch(query, category) { +async function _projectSearch(query, category, indexData) { // load the index data into lunr - const indexData = await _requestIndex(); + const idx = lunr.Index.load(indexData.index); const textSearchResults = idx.query((q) => {