Barebones search working!
This commit is contained in:
parent
26db9488db
commit
205a096654
5 changed files with 58 additions and 64 deletions
|
|
@ -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));
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue