Skip to content

Commit

Permalink
Removed raw HTML escape codes from search results 'snippet'. (kaushal…
Browse files Browse the repository at this point in the history
  • Loading branch information
McFateM authored and kaushalmodi committed May 29, 2019
1 parent ae4cb2c commit 84cb14a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,19 @@ function populateResults(result){
snippet += contents.substring(0,summaryInclude*2);
}
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 = snippet;
frag.querySelector(".search_snippet").textContent = decoded;
let tags = value.item.tags;
if (tags) {
frag.querySelector(".search_tags").textContent = tags;
Expand Down

0 comments on commit 84cb14a

Please sign in to comment.