@@ -1,7 +1,7 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
if RUBY_PLATFORM == 'java'
|
||||
gem 'gollum-rjgit_adapter', :git => 'https://github.com/repotag/gollum-lib_rjgit_adapter' # For development purposes
|
||||
gem 'gollum-rjgit_adapter', :git => 'https://github.com/gollum/rjgit_adapter' # For development purposes
|
||||
gem 'warbler'
|
||||
else
|
||||
gem 'gollum-rugged_adapter', :git => 'https://github.com/gollum/rugged_adapter.git' # For development purposes
|
||||
|
||||
+11
-5
@@ -461,11 +461,17 @@ module Precious
|
||||
end
|
||||
|
||||
get '/search' do
|
||||
@query = params[:q] || ''
|
||||
wiki = wiki_new
|
||||
# Sort wiki search results by count (desc) and then by name (asc)
|
||||
@results = wiki.search(@query).sort { |a, b| (a[:count] <=> b[:count]).nonzero? || b[:name] <=> a[:name] }.reverse
|
||||
@name = @query
|
||||
@query = params[:q]
|
||||
@name = @query
|
||||
if @query.empty?
|
||||
@results = []
|
||||
@search_terms = []
|
||||
else
|
||||
@page_num = [params[:page_num].to_i, 1].max
|
||||
@max_count = 10
|
||||
wiki = wiki_new
|
||||
@results, @search_terms = wiki.search(@query)
|
||||
end
|
||||
mustache :search
|
||||
end
|
||||
|
||||
|
||||
@@ -508,36 +508,39 @@ $(document).ready(function() {
|
||||
|
||||
var clickPageNav = function (e) {
|
||||
e.preventDefault();
|
||||
$.ajax({
|
||||
url: $(this).attr('href'),
|
||||
type: 'GET',
|
||||
success: function(data) {
|
||||
var rowDiv = $('#page-history-list', data);
|
||||
var new_pagination = $('#pagination', data);
|
||||
if ( !$(this).hasClass('disabled') ) {
|
||||
$.ajax({
|
||||
url: $(this).attr('href'),
|
||||
type: 'GET',
|
||||
success: function(data) {
|
||||
var rowDiv = $('#page-history-list', data);
|
||||
var new_pagination = $('#pagination', data);
|
||||
|
||||
next = $('#pagination #next');
|
||||
prev = $('#pagination #prev');
|
||||
new_next = new_pagination.find('#next');
|
||||
new_prev = new_pagination.find('#prev');
|
||||
['#next', '#prev'].forEach( function (nav_item) {
|
||||
old_btn = $('#pagination ' + nav_item);
|
||||
new_btn = new_pagination.find(nav_item);
|
||||
old_btn.attr('href', new_btn.attr('href'));
|
||||
if (new_btn.hasClass('disabled')) {
|
||||
old_btn.addClass('disabled');
|
||||
} else {
|
||||
old_btn.removeClass('disabled');
|
||||
}
|
||||
});
|
||||
|
||||
next[0].hidden = new_next[0].hidden;
|
||||
prev[0].hidden = new_prev[0].hidden;
|
||||
$('#page-history-list').replaceWith(rowDiv);
|
||||
|
||||
next.children('a').attr('href', new_next.children('a').attr('href'));
|
||||
prev.children('a').attr('href', new_prev.children('a').attr('href'));
|
||||
|
||||
$('#page-history-list').replaceWith(rowDiv);
|
||||
|
||||
setCheckboxEvents();
|
||||
toggleInputs();
|
||||
},
|
||||
error: function(data, textStatus, errorThrown) {
|
||||
console.log('something went wrong: ' + textStatus + errorThrown)
|
||||
}
|
||||
});
|
||||
setCheckboxEvents();
|
||||
toggleInputs();
|
||||
},
|
||||
error: function(data, textStatus, errorThrown) {
|
||||
console.log('something went wrong: ' + textStatus + errorThrown)
|
||||
}
|
||||
});
|
||||
}
|
||||
this.blur();
|
||||
};
|
||||
|
||||
$("#pagination #next a, #pagination #prev a").each(function(index, element) {
|
||||
$("#pagination #next, #pagination #prev").each(function(index, element) {
|
||||
$(element).on("click", clickPageNav);
|
||||
});
|
||||
}
|
||||
@@ -566,6 +569,30 @@ $(document).ready(function() {
|
||||
$.GollumEditor({ NewFile: true, MarkupType: default_markup, commands: editorHotkeys });
|
||||
}
|
||||
|
||||
if($('#search-results').length ){
|
||||
$('.toggle-context').each(function () {
|
||||
var hiddenContext = $(this).parent().next('div.search-context').find('li:hidden');
|
||||
if ( !hiddenContext.length ) {
|
||||
$(this).toggle();
|
||||
} else {
|
||||
$(this).click(function () {
|
||||
hiddenContext.toggle();
|
||||
$(this).toggle();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var searchQuery = new RegExp(searchTerms.join('|'), 'gi'); //searchTerms provided by the layout template.
|
||||
$('div.search-context li span').each(function () {
|
||||
var curText = $(this).html().replace(/"/g, '"').replace(/'/g, ''');
|
||||
var newText = curText.replace(searchQuery, function (match) {
|
||||
return '<span class="bg-green-light">' + match + '</span>';
|
||||
});
|
||||
|
||||
$(this).html(newText);
|
||||
});
|
||||
}
|
||||
|
||||
if($('.markdown-body').length ){
|
||||
// Set text direction (LTR or RTL)
|
||||
preparePage();
|
||||
|
||||
@@ -650,4 +650,14 @@ a {
|
||||
color: #A31515;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
div.pagination a.disabled {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.search-results {
|
||||
.search-context li:nth-child(n+4) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,10 @@
|
||||
var pageFullPath = '{{escaped_url_path}}';
|
||||
var pageFormat = '{{format}}';
|
||||
{{/page}}
|
||||
{{#has_search_terms}}
|
||||
var searchTerms = [{{#search_terms}}'{{.}}', {{/search_terms}}
|
||||
];
|
||||
{{/has_search_terms}}
|
||||
{{#is_create_page}}
|
||||
var default_markup = '{{default_markup}}';
|
||||
{{/is_create_page}}
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
<div id="pagination" class="pb-2 px-3">
|
||||
<span id="prev" {{^previous_page}}hidden{{/previous_page}}>
|
||||
<a href="?page_num={{previous_page}}">« Previous</a>
|
||||
</span>
|
||||
|
||||
<span> </span>
|
||||
|
||||
<span id="next" class="float-right" {{^next_page}}hidden{{/next_page}}>
|
||||
<a href="?page_num={{next_page}}">Next »</a>
|
||||
</span>
|
||||
</div>
|
||||
<nav class="paginate-container" aria-label="Pagination">
|
||||
<div class="pagination" id="pagination">
|
||||
<a id="prev" href="?page_num={{previous_page}}{{query_string}}" class="previous_page {{^previous_page}}disabled{{/previous_page}}">Previous</span>
|
||||
<a id="next" href="?page_num={{next_page}}{{query_string}}" class="next_page {{^next_page}}disabled{{/next_page}}" rel="next" aria-label="Next Page">Next</a>
|
||||
</div>
|
||||
</nav>
|
||||
@@ -1,26 +1,33 @@
|
||||
<div id="wiki-wrapper" class="results">
|
||||
<div id="head">
|
||||
<h1>Search Results for <strong>{{query}}</strong></h1>
|
||||
<ul class="actions">
|
||||
<li class="minibutton"><a href="{{base_url}}/"
|
||||
class="action-home-page">Home</a></li>
|
||||
<li class="minibutton">
|
||||
{{>searchbar}}
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
<div id="results">
|
||||
<div id="head">
|
||||
{{>navbar}}
|
||||
<h1 class="py-4"><span class="f1-light text-gray-light">Search results for</span> {{name}}</h1>
|
||||
</div>
|
||||
|
||||
{{#has_results}}
|
||||
|
||||
{{>pagination}}
|
||||
|
||||
<div class="Box Box--condensed search-results" id="search-results">
|
||||
<ul>
|
||||
{{#results}}
|
||||
<li>
|
||||
<a href="{{base_url}}/{{name}}">{{name}}</a>
|
||||
<span class="count">({{count}} matches)</span>
|
||||
<div class="Box-header border-bottom p-0"></div>
|
||||
{{#results}}
|
||||
<li class="Box-row Box-row--gray">
|
||||
<span class="Counter Counter--gray tooltipped tooltipped-w" aria-label="{{filename_count}} hits in filename - {{count}} hits in content">{{filename_count}} - {{count}}</span>
|
||||
|
||||
<span class="text-bold"><a href="{{base_url}}/{{name}}">{{name}}</a></span>
|
||||
<button class="btn-link tooltipped tooltipped-w float-right toggle-context" aria-label="Show all {{count}} hits in this page">{{#octicon}}search{{/octicon}}</button>
|
||||
</li>
|
||||
{{/results}}
|
||||
|
||||
<div class="search-context">
|
||||
{{#context}}
|
||||
<li class="Box-row border-0"><span class="text-italic">{{.}}</span></li>
|
||||
{{/context}}
|
||||
</div>
|
||||
|
||||
{{/results}}
|
||||
</ul>
|
||||
</div>
|
||||
{{/has_results}}
|
||||
|
||||
{{#no_results}}
|
||||
@@ -29,11 +36,10 @@
|
||||
</p>
|
||||
{{/no_results}}
|
||||
|
||||
<div id="footer" class="mt-4">
|
||||
<a class="btn" href="#">Back to Top</a>
|
||||
</div>
|
||||
<div id="footer">
|
||||
<ul class="actions">
|
||||
<li class="minibutton"><a href="#">Back to Top</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
module Precious
|
||||
module Pagination
|
||||
module Pagination
|
||||
|
||||
def next_page
|
||||
@versions.length < @max_count ? nil : (@page_num + 1).to_s
|
||||
result_set = @versions || results
|
||||
result_set.length < @max_count ? nil : (@page_num + 1).to_s
|
||||
end
|
||||
|
||||
def previous_page
|
||||
|
||||
@@ -1,12 +1,38 @@
|
||||
module Precious
|
||||
module Views
|
||||
class Search < Layout
|
||||
attr_reader :content, :page, :footer, :results, :query
|
||||
attr_reader :query, :search_terms
|
||||
include Pagination
|
||||
|
||||
def results
|
||||
@results.sort do |a, b|
|
||||
if b.nil?
|
||||
b_filename_count = 0
|
||||
b_count = 0
|
||||
else
|
||||
b_filename_count = b[:filename_count]
|
||||
b_count = b[:count]
|
||||
end
|
||||
[a[:filename_count], a[:count]] <=> [b_filename_count, b_count]
|
||||
end.reverse.slice((@page_num - 1) * @max_count, @max_count)
|
||||
end
|
||||
|
||||
def query_string
|
||||
"&q=#{@query}"
|
||||
end
|
||||
|
||||
def title
|
||||
"Search results for " + @query
|
||||
end
|
||||
|
||||
def search
|
||||
true # View has searchbar
|
||||
end
|
||||
|
||||
def has_search_terms
|
||||
!@search_terms.empty?
|
||||
end
|
||||
|
||||
def has_results
|
||||
!@results.empty?
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user