improve search

This commit is contained in:
Lorin Werthen 2016-10-08 18:52:46 +02:00
parent 792196e7ca
commit 596b077797
4 changed files with 26 additions and 28 deletions

View file

@ -1,14 +1 @@
{ "pages": [
<% articles.each_with_index do |e, i| %>
{
"title": "<%= e[:title] %>",
"url": "<%= url_for(e) %>",
"text": "<%= excerptize(e.reps[:text].compiled_content, length: 200).gsub(/\n/, ' ') %>",
"tags": ""
<% if i < articles.size - 1 %>
},
<% else %>
}
<% end %>
<% end %>
]}
<%= blog_search_json %>

View file

@ -1,14 +1 @@
{ "pages": [
<% all_events.each_with_index do |e, i| %>
{
"title": "<%= e[:title] %>",
"url": "<%= url_for(e) %>",
"text": "<%= excerptize(e.reps[:text].compiled_content, length: 200).gsub(/\n/, ' ') %>",
"tags": ""
<% if i < articles.size %>
},
<% else %>
}
<% end %>
<% end %>
]}
<%= event_search_json %>

23
lib/helpers/search.rb Normal file
View file

@ -0,0 +1,23 @@
module SearchHelper
def blog_search_json
jsonify articles
end
def event_search_json
jsonify all_events
end
private
def jsonify(collection)
elems = collection.map do |e|
{
title: e[:title],
url: url_for(e),
text: excerptize(e.reps[:text].compiled_content, length: 200).tr("\n", ' '),
tags: ''
}
end
{ pages: elems }.to_json
end
end

View file

@ -12,3 +12,4 @@ include NavigationHelper
include DataHelper
include FontAwesomeHelper
include ProjectsHelper
include SearchHelper