Add search API and update frontend
The frontend has been updated to use the new search API.
This commit is contained in:
@@ -130,8 +130,8 @@ module Precious
|
||||
|
||||
get '/search' do
|
||||
@query = params[:q]
|
||||
@search_command = "cd #{$path} && git grep -c '#{@query}' master"
|
||||
@results = `#{@search_command}`
|
||||
wiki = Gollum::Wiki.new($path)
|
||||
@results = wiki.search @query
|
||||
mustache :search
|
||||
end
|
||||
|
||||
|
||||
@@ -1,26 +1,12 @@
|
||||
module Precious
|
||||
module Views
|
||||
class Search < Layout
|
||||
attr_reader :content, :page, :footer, :query
|
||||
attr_reader :content, :page, :footer, :results, :query
|
||||
|
||||
def has_results
|
||||
!results.empty?
|
||||
!@results.empty?
|
||||
end
|
||||
|
||||
def results
|
||||
ret = []
|
||||
@results.each_line do |line|
|
||||
result = line.split(":")
|
||||
file = result[1]
|
||||
count = result[2].to_i
|
||||
name = file.split(".")[0]
|
||||
ret << {
|
||||
:name => name,
|
||||
:count => count
|
||||
}
|
||||
end
|
||||
ret
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user