improve search
This commit is contained in:
parent
792196e7ca
commit
596b077797
4 changed files with 26 additions and 28 deletions
|
@ -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 %>
|
||||
|
|
|
@ -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
23
lib/helpers/search.rb
Normal 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
|
|
@ -12,3 +12,4 @@ include NavigationHelper
|
|||
include DataHelper
|
||||
include FontAwesomeHelper
|
||||
include ProjectsHelper
|
||||
include SearchHelper
|
||||
|
|
Loading…
Reference in a new issue