Last active
July 1, 2021 23:16
-
-
Save julientaq/e8f5990102a98864bdab88050c418066 to your computer and use it in GitHub Desktop.
creating an index with json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ collections.allSearch | searchSingle(folder) | dump | safe }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const elasticlunr = require("elasticlunr"); | |
module.exports = function (folder) { | |
// folder gets out undefined | |
console.log(folder); | |
// what fields we'd like our index to consist of | |
var index = elasticlunr(function () { | |
this.addField("title"); | |
this.addField("tags"); | |
this.addField("chapnum"); | |
this.addField("content"); | |
this.setRef("id"); | |
}); | |
// loop through each page and add it to the index | |
collection.forEach((item) => { | |
console.log(`folder`, folder); | |
console.log(`item.data.folder`, item.data.folder) | |
if(item.data.folder == folder) { | |
index.addDoc({ | |
id: item.url, | |
content: item.templateContent, | |
chapnum: item.data.order, | |
title: item.data.title, | |
tags: item.data.tags | |
}); | |
} | |
}); | |
return index.toJSON(); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
folder: modernworldhistory | |
permalink: "/books/{{folder}}/content.json" | |
title: "search in the book" | |
menu: false | |
layout: searchindex.njk | |
--- | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment