Skip to content

Commit

Permalink
load projects index on page load
Browse files Browse the repository at this point in the history
  • Loading branch information
dzenreda committed Jun 7, 2024
1 parent 7cd1538 commit 6b4245b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 0 additions & 1 deletion .eleventy.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
12 changes: 7 additions & 5 deletions src/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,23 @@ 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", () => {
// get selected category
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);
Expand All @@ -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) => {
Expand Down

0 comments on commit 6b4245b

Please sign in to comment.