diff --git a/config.toml b/config.toml
index 8d1696d..4c512d9 100644
--- a/config.toml
+++ b/config.toml
@@ -14,6 +14,9 @@ pygmentsOptions = "linenos=table"
[permalinks]
posts = "/posts/:year/:month/:title"
+[outputs]
+ home = ["HTML", "RSS", "JSON"]
+
[params]
author = "KemoNine"
description = "a confused culinary notebook"
diff --git a/content/search.md b/content/search.md
new file mode 100644
index 0000000..a27c230
--- /dev/null
+++ b/content/search.md
@@ -0,0 +1,10 @@
++++
+title = "Search"
+author = ["KemoNine"]
+draft = false
+layout = "search"
+[sitemap]
+ priority = 0.1
++++
+
+This page was adapted from
No matches found
"; + } + }); +} + +function populateResults(result){ + result.forEach( function (value, key) { + let contents= value.item.contents; + let snippet = ""; + let snippetHighlights=[]; + snippetHighlights.push(searchQuery); + if(snippet.length<1){ + var getSentenceByWordRegex = new RegExp( + `[^.?!]*(?<=[.?\\s!])${searchQuery}(?=[\\s.?!])[^.?!]*[.?!]`, + 'i' + ); + var maxTextLength = summaryInclude*2 + // Index of the matched search term + var indexOfMatch = contents.toLowerCase().indexOf( + searchQuery.toLowerCase() + ); + // Index of the first word of the sentence with the search term in it + var indexOfSentence = contents.indexOf( + getSentenceByWordRegex.exec(contents) + ); + + var start + var cutStart = false + // Is the match in the result? + if(indexOfSentence+maxTextLength < indexOfMatch){ + // Make sure that the match is in the result + start = indexOfMatch + // This bool is used to replace the first part with '...' + cutStart = true + } else { + // Match is in view, even if we show the whole sentence + start = indexOfSentence + } + + // Change end length to the text length if it is longer than + // the text length to prevent problems + var end = start + maxTextLength + if (end > contents.length){ + end = contents.length + } + + if(cutStart){ + // Replace first three characters with '...' + end -= 3; + snippet += "…" + contents.substring(start, end).trim(); + } + else{ + snippet += contents.substring(start, end).trim(); + } + } + snippet += "…"; + + // Lifted from https://stackoverflow.com/posts/3700369/revisions + var elem = document.createElement('textarea'); + elem.innerHTML = snippet; + var decoded = elem.value; + + // Pull template from hugo template definition + let frag = document.getElementById('search-result-template').content.cloneNode(true); + // Replace values + frag.querySelector(".search_summary").setAttribute("id", "summary-" + key); + frag.querySelector(".search_link").setAttribute("href", value.item.permalink); + frag.querySelector(".search_title").textContent = value.item.title; + frag.querySelector(".search_snippet").textContent = decoded; + let tags = value.item.tags; + if (tags) { + frag.querySelector(".search_tags").textContent = tags; + } else { + frag.querySelector(".search_iftags").remove(); + } + snippetHighlights.forEach( function (snipvalue, snipkey) { + let markjs = new Mark(frag); + markjs.mark(snipvalue); + }); + document.getElementById("search-results").appendChild(frag); + }); +} +// @license-end