diff --git a/_includes/base.njk b/_includes/base.njk index 48bfc45..42e2a8d 100644 --- a/_includes/base.njk +++ b/_includes/base.njk @@ -4,8 +4,6 @@ - - neoBeta diff --git a/eleventy.config.js b/eleventy.config.js index e1f65b3..f7fd917 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -1,4 +1,4 @@ -import lunr from 'lunr'; +import elasticlunr from 'elasticlunr'; import fs from 'fs'; let allPlugins = []; @@ -9,33 +9,29 @@ export default function (eleventyConfig) { eleventyConfig.addPassthroughCopy("projects/**/*.jpg"); eleventyConfig.addPassthroughCopy("projects/**/*.jpeg"); eleventyConfig.addPassthroughCopy("assets"); - - eleventyConfig.addCollection('searchIndex', (collectionApi) => { - const result = collectionApi.getFilteredByTag("plugin").map(item => { - return { - title: item.data.projectName, - subtitle: item.data.projectSubtitle || "", - url: item.url - }; - }); - - console.log("Collected " + result.length + " plugins for search index."); - console.log(result); - return result; - }); - - eleventyConfig.on('afterBuild', async (eleventyConfig) => { - lunrIndex = lunr(function () { - this.ref('url'); - this.field('title'); - this.field('subtitle'); - - allPlugins.forEach(function (doc) { - this.add(doc); - }, this); + + eleventyConfig.addCollection('searchIndex', (collectionApi) => { + const result = collectionApi.getFilteredByTag("plugin").map(item => { + return { + title: item.data.projectName, + subtitle: item.data.projectSubtitle || "", + url: item.url + }; }); - - const indexJson = lunrIndex.toJSON(); - fs.writeFileSync('./_site/search_index.json', JSON.stringify(indexJson)); + + allPlugins = result; + return result; + }); + + eleventyConfig.on('afterBuild', () => { + const idx = elasticlunr(function () { + this.setRef('url'); + this.addField('title', { boost: 2 }); + this.addField('subtitle'); + + allPlugins.forEach(doc => this.addDoc(doc)); + }); + + fs.writeFileSync('./_site/search_index.json', JSON.stringify(idx)); }); }; diff --git a/package-lock.json b/package-lock.json index 35592fd..6a403c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "Unlicense", "dependencies": { "@11ty/eleventy": "^3.1.2", - "lunr": "^2.3.9" + "elasticlunr": "^0.9.5" } }, "node_modules/@11ty/dependency-tree": { @@ -410,7 +410,6 @@ "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", "license": "MIT", - "peer": true, "dependencies": { "anymatch": "~3.1.2", "braces": "~3.0.2", @@ -550,6 +549,12 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", "license": "MIT" }, + "node_modules/elasticlunr": { + "version": "0.9.5", + "resolved": "https://registry.npmjs.org/elasticlunr/-/elasticlunr-0.9.5.tgz", + "integrity": "sha512-5YM9LFQgVYfuLNEoqMqVWIBuF2UNCA+xu/jz1TyryLN/wmBcQSb+GNAwvLKvEpGESwgGN8XA1nbLAt6rKlyHYQ==", + "license": "MIT" + }, "node_modules/encodeurl": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", @@ -1032,12 +1037,6 @@ "integrity": "sha512-+dAZZ2mM+/m+vY9ezfoueVvrgnHIGi5FvgSymbIgJOFwiznWyA59mav95L+Mc6xPtL3s9gm5eNTlNtxJLbNM1g==", "license": "MIT" }, - "node_modules/lunr": { - "version": "2.3.9", - "resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.9.tgz", - "integrity": "sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==", - "license": "MIT" - }, "node_modules/luxon": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.7.2.tgz", diff --git a/package.json b/package.json index 1d3cda3..91825c7 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,6 @@ "homepage": "https://github.com/adrianvic/neoBeta#readme", "dependencies": { "@11ty/eleventy": "^3.1.2", - "lunr": "^2.3.9" + "elasticlunr": "^0.9.5" } } diff --git a/search.html b/search.html index f937b21..4a5fb01 100644 --- a/search.html +++ b/search.html @@ -5,32 +5,33 @@ layout: "base.njk" - + \ No newline at end of file