From 06072fd883acfe7d2e7317715fee9fc7069557e2 Mon Sep 17 00:00:00 2001 From: Lorin Werthen Date: Thu, 5 Jul 2018 11:36:11 +0200 Subject: [PATCH] update searching a bit --- Gemfile | 1 + Gemfile.lock | 2 + Rules | 6 + content/about/about.erb | 2 +- content/assets/scripts/tipuesearch.js | 1185 +++++++++-------- content/assets/scripts/tipuesearch_set.js | 84 ++ .../assets/stylesheets/includes/search.scss | 4 + .../stylesheets/tipuesearch/tipuesearch.css | 337 +++++ content/search.erb | 13 +- layouts/default.erb | 4 - lib/helpers/search.rb | 2 +- 11 files changed, 1045 insertions(+), 595 deletions(-) create mode 100644 content/assets/scripts/tipuesearch_set.js create mode 100755 content/assets/stylesheets/tipuesearch/tipuesearch.css diff --git a/Gemfile b/Gemfile index cc2eb1e..db7a7b4 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ gem 'uglifier', '>= 4.0.0' gem 'coffee-script' gem 'icalendar' # ical files gem 'kramdown' +gem 'rainpress' gem 'sass' gem 'typogruby' diff --git a/Gemfile.lock b/Gemfile.lock index 14fbc24..1482cb5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -78,6 +78,7 @@ GEM method_source (~> 0.9.0) public_suffix (3.0.2) rack (2.0.5) + rainpress (1.0.1) rb-fsevent (0.10.3) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) @@ -122,6 +123,7 @@ DEPENDENCIES kramdown nanoc pandoc-ruby + rainpress sass terminal-notifier terminal-notifier-guard diff --git a/Rules b/Rules index 0b7b3f9..4ccdc5e 100644 --- a/Rules +++ b/Rules @@ -182,6 +182,12 @@ compile '/assets/stylesheets/**/*.scss' do write ext: 'css' end +compile '/assets/stylesheets/**/*.css' do + filter :rainpress + filter :autoprefixer if production? + write ext: 'css' +end + # # # ROUTES diff --git a/content/about/about.erb b/content/about/about.erb index 782b112..7be0910 100644 --- a/content/about/about.erb +++ b/content/about/about.erb @@ -27,7 +27,7 @@ narrow_page: true

The board

The board is the oil in the machine and is the driving force behind the organization of events and projects. - The Zeus WPI board for the <%= pretty_year @config[:academic_year] %> academic year is: + The Zeus WPI board in <%= pretty_year @config[:academic_year] %> is:

diff --git a/content/assets/scripts/tipuesearch.js b/content/assets/scripts/tipuesearch.js index 7a63b2a..50541f5 100644 --- a/content/assets/scripts/tipuesearch.js +++ b/content/assets/scripts/tipuesearch.js @@ -1,606 +1,619 @@ /* -Tipue Search 6.0 -Copyright (c) 2017 Tipue -Tipue Search is released under the MIT License -http://www.tipue.com/search + Tipue Search 7.0 + Copyright (c) 2018 Tipue + Tipue Search is released under the MIT License + http://www.tipue.com/search */ (function($) { - $.fn.tipuesearch = function(options) { + $.fn.tipuesearch = function(options) { - var set = $.extend( { + var set = $.extend( { + + 'contentLocation' : 'tipuesearch/tipuesearch_content.json', + 'contextBuffer' : 60, + 'contextLength' : 60, + 'contextStart' : 90, + 'debug' : false, + 'descriptiveWords' : 25, + 'footerPages' : 3, + 'highlightTerms' : true, + 'imageZoom' : true, + 'minimumLength' : 3, + 'newWindow' : false, + 'show' : 10, + 'showContext' : true, + 'showRelated' : true, + 'showTime' : true, + 'showTitleCount' : true, + 'showURL' : true, + 'wholeWords' : true, + 'tipue_search_content' : '#tipue_search_content' + + }, options); + + return this.each(function() { + var tipuesearch = null; - 'contentLocation' : 'tipuesearch/tipuesearch_content.json', - 'contextBuffer' : 60, - 'contextLength' : 60, - 'contextStart' : 90, - 'debug' : false, - 'descriptiveWords' : 25, - 'highlightTerms' : true, - 'liveContent' : '*', - 'liveDescription' : '*', - 'minimumLength' : 3, - 'mode' : 'static', - 'newWindow' : false, - 'show' : 9, - 'showContext' : true, - 'showRelated' : false, - 'showTime' : false, - 'showTitleCount' : true, - 'showURL' : true, - 'wholeWords' : true, - 'tipue_search_content' : '#tipue_search_content' + $.ajaxSetup({ + async: false + }); + $.getJSON(set.contentLocation).done(function(json) {tipuesearch = $.extend({}, json);}); + + var tipuesearch_t_c = 0; + + var tipue_search_w = ''; + if (set.newWindow) + { + tipue_search_w = ' target="_blank"'; + } - }, options); + function getURLP(name) + { + var locSearch = location.search; + var splitted = (new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(locSearch)||[,""]); + var searchString = splitted[1].replace(/\+/g, '%20'); + try + { + searchString = decodeURIComponent(searchString); + } + catch(e) + { + searchString = unescape(searchString); + } + return searchString || null; + } + + if (getURLP('q')) + { + $('#tipue_search_input').val(getURLP('q')); + getTipueSearch(0, true); + } + + $(this).keyup(function(event) + { + if(event.keyCode == '13') + { + getTipueSearch(0, true); + } + }); + - return this.each(function() { + function getTipueSearch(start, replace) + { + window.scrollTo(0, 0); + + var out = ''; + var show_replace = false; + var show_stop = false; + var standard = true; + var c = 0; + var found = []; + + var d_o = $('#tipue_search_input').val(); + d_o = d_o.replace(/\+/g, ' ').replace(/\s\s+/g, ' '); + + d_o = $.trim(d_o); + var d = d_o.toLowerCase(); + + if ((d.match("^\"") && d.match("\"$")) || (d.match("^'") && d.match("'$"))) + { + standard = false; + } + + var d_w = d.split(' '); + + if (standard) + { + d = ''; + for (var i = 0; i < d_w.length; i++) + { + var a_w = true; + for (var f = 0; f < tipuesearch_stop_words.length; f++) + { + if (d_w[i] == tipuesearch_stop_words[f]) + { + a_w = false; + show_stop = true; + } + } + if (a_w) + { + d = d + ' ' + d_w[i]; + } + } + d = $.trim(d); + d_w = d.split(' '); + } + else + { + d = d.substring(1, d.length - 1); + } + + if (d.length >= set.minimumLength) + { + if (standard) + { + if (replace) + { + var d_r = d; + for (var i = 0; i < d_w.length; i++) + { + for (var f = 0; f < tipuesearch_replace.words.length; f++) + { + if (d_w[i] == tipuesearch_replace.words[f].word) + { + d = d.replace(d_w[i], tipuesearch_replace.words[f].replace_with); + show_replace = true; + } + } + } + d_w = d.split(' '); + } + + var d_t = d; + for (var i = 0; i < d_w.length; i++) + { + for (var f = 0; f < tipuesearch_stem.words.length; f++) + { + if (d_w[i] == tipuesearch_stem.words[f].word) + { + d_t = d_t + ' ' + tipuesearch_stem.words[f].stem; + } + } + } + d_w = d_t.split(' '); - var tipuesearch_in = { - pages: [] - }; - $.ajaxSetup({ - async: false - }); - var tipuesearch_t_c = 0; + for (var i = 0; i < tipuesearch.pages.length; i++) + { + var score = 0; + var s_t = tipuesearch.pages[i].text; + for (var f = 0; f < d_w.length; f++) + { + if (set.wholeWords) + { + var pat = new RegExp('\\b' + d_w[f] + '\\b', 'gi'); + } + else + { + var pat = new RegExp(d_w[f], 'gi'); + } + if (tipuesearch.pages[i].title.search(pat) != -1) + { + var m_c = tipuesearch.pages[i].title.match(pat).length; + score += (20 * m_c); + } + if (tipuesearch.pages[i].text.search(pat) != -1) + { + var m_c = tipuesearch.pages[i].text.match(pat).length; + score += (20 * m_c); + } + if (tipuesearch.pages[i].tags) + { + if (tipuesearch.pages[i].tags.search(pat) != -1) + { + var m_c = tipuesearch.pages[i].tags.match(pat).length; + score += (10 * m_c); + } + } + if (tipuesearch.pages[i].url.search(pat) != -1) + { + score += 20; + } + + if (score != 0) + { + for (var e = 0; e < tipuesearch_weight.weight.length; e++) + { + if (tipuesearch.pages[i].url == tipuesearch_weight.weight[e].url) + { + score += tipuesearch_weight.weight[e].score; + } + } + } + + if (d_w[f].match('^-')) + { + pat = new RegExp(d_w[f].substring(1), 'i'); + if (tipuesearch.pages[i].title.search(pat) != -1 || tipuesearch.pages[i].text.search(pat) != -1 || tipuesearch.pages[i].tags.search(pat) != -1) + { + score = 0; + } + } + } + + if (score != 0) + { + found.push( + { + "score": score, + "title": tipuesearch.pages[i].title, + "desc": s_t, + "img": tipuesearch.pages[i].img, + "url": tipuesearch.pages[i].url, + "note": tipuesearch.pages[i].note + }); + c++; + } + } + } + else + { + for (var i = 0; i < tipuesearch.pages.length; i++) + { + var score = 0; + var s_t = tipuesearch.pages[i].text; + var pat = new RegExp(d, 'gi'); + if (tipuesearch.pages[i].title.search(pat) != -1) + { + var m_c = tipuesearch.pages[i].title.match(pat).length; + score += (20 * m_c); + } + if (tipuesearch.pages[i].text.search(pat) != -1) + { + var m_c = tipuesearch.pages[i].text.match(pat).length; + score += (20 * m_c); + } + if (tipuesearch.pages[i].tags) + { + if (tipuesearch.pages[i].tags.search(pat) != -1) + { + var m_c = tipuesearch.pages[i].tags.match(pat).length; + score += (10 * m_c); + } + } + if (tipuesearch.pages[i].url.search(pat) != -1) + { + score += 20; + } + + if (score != 0) + { + for (var e = 0; e < tipuesearch_weight.weight.length; e++) + { + if (tipuesearch.pages[i].url == tipuesearch_weight.weight[e].url) + { + score += tipuesearch_weight.weight[e].score; + } + } + } + + if (score != 0) + { + found.push( + { + "score": score, + "title": tipuesearch.pages[i].title, + "desc": s_t, + "img": tipuesearch.pages[i].img, + "url": tipuesearch.pages[i].url, + "note": tipuesearch.pages[i].note + }); + c++; + } - $(set.tipue_search_content).hide().html('
').show(); + } + } + + if (c !== 0) + { + if (set.showTitleCount && tipuesearch_t_c === 0) + { + var title = document.title; + document.title = '(' + c + ') ' + title; + tipuesearch_t_c++; + } - if (set.mode == 'live') - { - for (var i = 0; i < tipuesearch_pages.length; i++) - { - $.get(tipuesearch_pages[i]).done(function(html) - { - var cont = $(set.liveContent, html).text(); - cont = cont.replace(/\s+/g, ' '); - var desc = $(set.liveDescription, html).text(); - desc = desc.replace(/\s+/g, ' '); + if (c === 1) + { + out += '
' + tipuesearch_string_4; + } + else + { + var c_c = c.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); + out += '
' + c_c + ' ' + tipuesearch_string_5; + } + if (set.showTime) + { + var endTimer = new Date().getTime(); + var time = (endTimer - startTimer) / 1000; + out += ' (' + time.toFixed(2) + ' ' + tipuesearch_string_14 + ')'; + set.showTime = false; + } + out += '
'; - var t_1 = html.toLowerCase().indexOf(''); - var t_2 = html.toLowerCase().indexOf('', t_1 + 7); - if (t_1 != -1 && t_2 != -1) - { - var tit = html.slice(t_1 + 7, t_2); - } - else - { - var tit = tipuesearch_string_1; - } + + if (set.showRelated && standard) + { + f = 0; + for (var i = 0; i < tipuesearch_related.Related.length; i++) + { + if (d == tipuesearch_related.Related[i].search) + { + if (!f) + { + out += ''; + } + } - tipuesearch_in.pages.push( - { - "title": tit, - "text": desc, - "tags": cont, - "url": tipuesearch_pages[i] - }); - }); - } - } + if (show_replace) + { + out += '
' + tipuesearch_string_2 + ' ' + d + '. ' + tipuesearch_string_3 + ' ' + d_r + '
'; + } + + found.sort(function(a, b) { return b.score - a.score } ); + + var l_o = 0; + + if (set.imageZoom) + { + out += '
'; + } + + for (var i = 0; i < found.length; i++) + { + if (l_o >= start && l_o < set.show + start) + { + out += '
'; + + out += ''; + + if (set.debug) + { + out += '
Score: ' + found[i].score + '
'; + } + + if (set.showURL) + { + var s_u = found[i].url.toLowerCase(); + if (s_u.indexOf('http://') == 0) + { + s_u = s_u.slice(7); + } + out += ''; + } + + if (found[i].img) + { + if (set.imageZoom) + { + out += '
' + found[i].title + '
'; + } + else + { + out += '
' + found[i].title + '
'; + } + } + + if (found[i].desc) + { + var t = found[i].desc; - if (set.mode == 'json') - { - $.getJSON(set.contentLocation).done(function(json) - { - tipuesearch_in = $.extend({}, json); - }); - } + if (set.showContext) + { + d_w = d.split(' '); + var s_1 = found[i].desc.toLowerCase().indexOf(d_w[0]); + if (s_1 > set.contextStart) + { + var t_1 = t.substr(s_1 - set.contextBuffer); + var s_2 = t_1.indexOf(' '); + t_1 = t.substr(s_1 - set.contextBuffer + s_2); + t_1 = $.trim(t_1); + + if (t_1.length > set.contextLength) + { + t = '... ' + t_1; + } + } + } + + if (standard) + { + d_w = d.split(' '); + for (var f = 0; f < d_w.length; f++) + { + if (set.highlightTerms) + { + var patr = new RegExp('(' + d_w[f] + ')', 'gi'); + t = t.replace(patr, "$1"); + } + } + } + else if (set.highlightTerms) + { + var patr = new RegExp('(' + d + ')', 'gi'); + t = t.replace(patr, "$1"); + } + + var t_d = ''; + var t_w = t.split(' '); + if (t_w.length < set.descriptiveWords) + { + t_d = t; + } + else + { + for (var f = 0; f < set.descriptiveWords; f++) + { + t_d += t_w[f] + ' '; + } + } + t_d = $.trim(t_d); + if (t_d.charAt(t_d.length - 1) != '.') + { + t_d += ' ...'; + } + + t_d = t_d.replace(/h0011/g, 'span class=\"tipue_search_content_bold\"'); + t_d = t_d.replace(/h0012/g, '/span'); + + out += '
' + t_d + '
'; + } + + if (found[i].note) + { + out += '
' + found[i].note + '
'; + } + + out += '
'; + } + l_o++; + } - if (set.mode == 'static') - { - tipuesearch_in = $.extend({}, tipuesearch); - } - - var tipue_search_w = ''; - if (set.newWindow) - { - tipue_search_w = ' target="_blank"'; - } - - function getURLP(name) - { - var _locSearch = location.search; - var _splitted = (new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(_locSearch)||[,""]); - var searchString = _splitted[1].replace(/\+/g, '%20'); - try - { - searchString = decodeURIComponent(searchString); - } - catch(e) - { - searchString = unescape(searchString); - } - return searchString || null; - } - - if (getURLP('q')) - { - $('#tipue_search_input').val(getURLP('q')); - getTipueSearch(0, true); - } - - $(this).keyup(function(event) - { - if(event.keyCode == '13') - { - getTipueSearch(0, true); - } - }); - - - function getTipueSearch(start, replace) - { - var out = ''; - var results = ''; - var show_replace = false; - var show_stop = false; - var standard = true; - var c = 0; - found = []; - - var d_o = $('#tipue_search_input').val(); - var d = d_o.toLowerCase(); - d = $.trim(d); - - if ((d.match("^\"") && d.match("\"$")) || (d.match("^'") && d.match("'$"))) - { - standard = false; - } - - var d_w = d.split(' '); - - if (standard) - { - d = ''; - for (var i = 0; i < d_w.length; i++) - { - var a_w = true; - for (var f = 0; f < tipuesearch_stop_words.length; f++) - { - if (d_w[i] == tipuesearch_stop_words[f]) - { - a_w = false; - show_stop = true; - } - } - if (a_w) - { - d = d + ' ' + d_w[i]; - } - } - d = $.trim(d); - d_w = d.split(' '); - } - else - { - d = d.substring(1, d.length - 1); - } - - if (d.length >= set.minimumLength) - { - if (standard) - { - if (replace) - { - var d_r = d; - for (var i = 0; i < d_w.length; i++) - { - for (var f = 0; f < tipuesearch_replace.words.length; f++) - { - if (d_w[i] == tipuesearch_replace.words[f].word) - { - d = d.replace(d_w[i], tipuesearch_replace.words[f].replace_with); - show_replace = true; - } - } - } - d_w = d.split(' '); - } - - var d_t = d; - for (var i = 0; i < d_w.length; i++) - { - for (var f = 0; f < tipuesearch_stem.words.length; f++) - { - if (d_w[i] == tipuesearch_stem.words[f].word) - { - d_t = d_t + ' ' + tipuesearch_stem.words[f].stem; - } - } - } - d_w = d_t.split(' '); - - for (var i = 0; i < tipuesearch_in.pages.length; i++) - { - var score = 0; - var s_t = tipuesearch_in.pages[i].text; - for (var f = 0; f < d_w.length; f++) - { - if (set.wholeWords) - { - var pat = new RegExp('\\b' + d_w[f] + '\\b', 'gi'); - } - else - { - var pat = new RegExp(d_w[f], 'gi'); - } - if (tipuesearch_in.pages[i].title.search(pat) != -1) - { - var m_c = tipuesearch_in.pages[i].title.match(pat).length; - score += (20 * m_c); - } - if (tipuesearch_in.pages[i].text.search(pat) != -1) - { - var m_c = tipuesearch_in.pages[i].text.match(pat).length; - score += (20 * m_c); - } - - if (tipuesearch_in.pages[i].tags.search(pat) != -1) - { - var m_c = tipuesearch_in.pages[i].tags.match(pat).length; - score += (10 * m_c); - } - - if (tipuesearch_in.pages[i].url.search(pat) != -1) - { - score += 20; - } - - if (score != 0) - { - for (var e = 0; e < tipuesearch_weight.weight.length; e++) - { - if (tipuesearch_in.pages[i].url == tipuesearch_weight.weight[e].url) - { - score += tipuesearch_weight.weight[e].score; - } - } - } - - if (d_w[f].match('^-')) - { - pat = new RegExp(d_w[f].substring(1), 'i'); - if (tipuesearch_in.pages[i].title.search(pat) != -1 || tipuesearch_in.pages[i].text.search(pat) != -1 || tipuesearch_in.pages[i].tags.search(pat) != -1) - { - score = 0; - } - } - } - - if (score != 0) - { - found.push( - { - "score": score, - "title": tipuesearch_in.pages[i].title, - "desc": s_t, - "url": tipuesearch_in.pages[i].url - }); - c++; - } - } - } - else - { - for (var i = 0; i < tipuesearch_in.pages.length; i++) - { - var score = 0; - var s_t = tipuesearch_in.pages[i].text; - var pat = new RegExp(d, 'gi'); - if (tipuesearch_in.pages[i].title.search(pat) != -1) - { - var m_c = tipuesearch_in.pages[i].title.match(pat).length; - score += (20 * m_c); - } - if (tipuesearch_in.pages[i].text.search(pat) != -1) - { - var m_c = tipuesearch_in.pages[i].text.match(pat).length; - score += (20 * m_c); - } - - if (tipuesearch_in.pages[i].tags.search(pat) != -1) - { - var m_c = tipuesearch_in.pages[i].tags.match(pat).length; - score += (10 * m_c); - } - - if (tipuesearch_in.pages[i].url.search(pat) != -1) - { - score += 20; - } - - if (score != 0) - { - for (var e = 0; e < tipuesearch_weight.weight.length; e++) - { - if (tipuesearch_in.pages[i].url == tipuesearch_weight.weight[e].url) - { - score += tipuesearch_weight.weight[e].score; - } - } - } - - if (score != 0) - { - found.push( - { - "score": score, - "title": tipuesearch_in.pages[i].title, - "desc": s_t, - "url": tipuesearch_in.pages[i].url - }); - c++; - } - } - } - - if (c != 0) - { - if (set.showTitleCount && tipuesearch_t_c == 0) - { - var title = document.title; - document.title = '(' + c + ') ' + title; - tipuesearch_t_c++; - } - - if (show_replace) - { - out += '
' + tipuesearch_string_2 + ' ' + d + '. ' + tipuesearch_string_3 + ' ' + d_r + '
'; - } - if (c == 1) - { - out += '
' + tipuesearch_string_4; - } - else - { - c_c = c.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); - out += '
' + c_c + ' ' + tipuesearch_string_5; - } - if (set.showTime) - { - var endTimer = new Date().getTime(); - var time = (endTimer - startTimer) / 1000; - out += ' (' + time.toFixed(2) + ' ' + tipuesearch_string_14 + ')'; - set.showTime = false; - } - out += '
'; - - found.sort(function(a, b) { return b.score - a.score } ); - - var l_o = 0; - for (var i = 0; i < found.length; i++) - { - if (l_o >= start && l_o < set.show + start) - { - out += ''; - - if (set.debug) - { - out += '
Score: ' + found[i].score + '
'; - } - - if (set.showURL) - { - var s_u = found[i].url.toLowerCase(); - if (s_u.indexOf('http://') == 0) - { - s_u = s_u.slice(7); - } - out += ''; - } - - if (found[i].desc) - { - var t = found[i].desc; - - if (set.showContext) - { - d_w = d.split(' '); - var s_1 = found[i].desc.toLowerCase().indexOf(d_w[0]); - if (s_1 > set.contextStart) - { - var t_1 = t.substr(s_1 - set.contextBuffer); - var s_2 = t_1.indexOf(' '); - t_1 = t.substr(s_1 - set.contextBuffer + s_2); - t_1 = $.trim(t_1); - - if (t_1.length > set.contextLength) - { - t = '... ' + t_1; - } - } - } - - if (standard) - { - d_w = d.split(' '); - for (var f = 0; f < d_w.length; f++) - { - if (set.highlightTerms) - { - var patr = new RegExp('(' + d_w[f] + ')', 'gi'); - t = t.replace(patr, "$1"); - } - } - } - else if (set.highlightTerms) - { - var patr = new RegExp('(' + d + ')', 'gi'); - t = t.replace(patr, "$1"); - } - - var t_d = ''; - var t_w = t.split(' '); - if (t_w.length < set.descriptiveWords) - { - t_d = t; - } - else - { - for (var f = 0; f < set.descriptiveWords; f++) - { - t_d += t_w[f] + ' '; - } - } - t_d = $.trim(t_d); - if (t_d.charAt(t_d.length - 1) != '.') - { - t_d += ' ...'; - } - - t_d = t_d.replace(/h0011/g, 'tipue_search_content_bold'); - - out += '
' + t_d + '
'; - } - } - l_o++; - } - - if (set.showRelated && standard) - { - f = 0; - for (var i = 0; i < tipuesearch_related.searches.length; i++) - { - if (d == tipuesearch_related.searches[i].search) - { - if (show_replace) - { - d_o = d; - } - if (!f) - { - out += ''; - } - } - - if (c > set.show) - { - var pages = Math.ceil(c / set.show); - var page = (start / set.show); - out += ''; - } - } - else - { - out += '
' + tipuesearch_string_8 + '
'; - } - } - else - { - if (show_stop) - { - out += '
' + tipuesearch_string_8 + '. ' + tipuesearch_string_9 + '
'; - } - else - { - out += '
' + tipuesearch_string_10 + '
'; - if (set.minimumLength == 1) - { - out += '
' + tipuesearch_string_11 + '
'; - } - else - { - out += '
' + tipuesearch_string_12 + ' ' + set.minimumLength + ' ' + tipuesearch_string_13 + '
'; - } - } - } - - $(set.tipue_search_content).hide().html(out).slideDown(200); - - $('#tipue_search_replaced').click(function() - { - getTipueSearch(0, false); - }); - - $('.tipue_search_related').click(function() - { - $('#tipue_search_input').val($(this).attr('id')); - getTipueSearch(0, true); - }); - - $('.tipue_search_foot_box').click(function() - { - var id_v = $(this).attr('id'); - var id_a = id_v.split('_'); - - getTipueSearch(parseInt(id_a[0]), id_a[1]); - }); - } - - }); - }; + if (c > set.show) + { + var pages = Math.ceil(c / set.show); + var page = (start / set.show); + if (set.footerPages < 3) + { + set.footerPages = 3; + } + + out += '
    '; + + if (start > 0) + { + out += '
  • ' + tipuesearch_string_6 + '
  • '; + } + + if (page <= 2) + { + var p_b = pages; + if (pages > set.footerPages) + { + p_b = set.footerPages; + } + for (var f = 0; f < p_b; f++) + { + if (f == page) + { + out += ''; + } + else + { + out += '
  • ' + (f + 1) + '
  • '; + } + } + } + else + { + var p_b = page + set.footerPages - 1; + if (p_b > pages) + { + p_b = pages; + } + for (var f = page - 1; f < p_b; f++) + { + if (f == page) + { + out += ''; + } + else + { + out += '
  • ' + (f + 1) + '
  • '; + } + } + } + + if (page + 1 != pages) + { + out += '
  • ' + tipuesearch_string_7 + '
  • '; + } + + out += '
'; + } + } + else + { + out += '
' + tipuesearch_string_8 + '
'; + } + } + else + { + if (show_stop) + { + out += '
' + tipuesearch_string_8 + ' ' + tipuesearch_string_9 + '
'; + } + else + { + if (set.minimumLength == 1) + { + out += '
' + tipuesearch_string_11 + '
'; + } + else + { + out += '
' + tipuesearch_string_12 + ' ' + set.minimumLength + ' ' + tipuesearch_string_13 + '
'; + } + } + } + + $(set.tipue_search_content).hide().html(out).slideDown(200); + + $('#tipue_search_replaced').click(function() + { + getTipueSearch(0, false); + }); + + $('.tipue_search_related_btn').click(function() + { + $('#tipue_search_input').val($(this).attr('id')); + getTipueSearch(0, true); + }); + + $('.tipue_search_image_zoom').click(function() + { + $('#tipue_search_image_modal').fadeIn(300); + $('#tipue_search_zoom_img').attr('src', this.src); + + var z_u = $(this).attr('data-url'); + $('#tipue_search_zoom_url').attr('href', z_u); + + var z_o = this.alt + ''; + + $('#tipue_search_zoom_text').html(z_o); + }); + + $('.tipue_search_image_close').click(function() + { + $('#tipue_search_image_modal').fadeOut(300); + }); + + $('.tipue_search_foot_box').click(function() + { + var id_v = $(this).attr('id'); + var id_a = id_v.split('_'); + + getTipueSearch(parseInt(id_a[0]), id_a[1]); + }); + } + + }); + }; + })(jQuery); diff --git a/content/assets/scripts/tipuesearch_set.js b/content/assets/scripts/tipuesearch_set.js new file mode 100644 index 0000000..e3e51e0 --- /dev/null +++ b/content/assets/scripts/tipuesearch_set.js @@ -0,0 +1,84 @@ + +/* +Tipue Search 7.0 +Copyright (c) 2018 Tipue +Tipue Search is released under the MIT License +http://www.tipue.com/search +*/ + + +/* +Stop words +Stop words list from http://www.ranks.nl/stopwords +*/ + +var tipuesearch_stop_words = ["a", "above", "after", "again", "against", "all", "am", "an", "and", "any", "are", "aren't", "as", "at", "be", "because", "been", "before", "being", "below", "between", "both", "but", "by", "can't", "cannot", "could", "couldn't", "did", "didn't", "do", "does", "doesn't", "doing", "don't", "down", "during", "each", "few", "for", "from", "further", "had", "hadn't", "has", "hasn't", "have", "haven't", "having", "he", "he'd", "he'll", "he's", "her", "here", "here's", "hers", "herself", "him", "himself", "his", "how", "how's", "i", "i'd", "i'll", "i'm", "i've", "if", "in", "into", "is", "isn't", "it", "it's", "its", "itself", "let's", "me", "more", "most", "mustn't", "my", "myself", "no", "nor", "not", "of", "off", "on", "once", "only", "or", "other", "ought", "our", "ours", "ourselves", "out", "over", "own", "same", "shan't", "she", "she'd", "she'll", "she's", "should", "shouldn't", "so", "some", "such", "than", "that", "that's", "the", "their", "theirs", "them", "themselves", "then", "there", "there's", "these", "they", "they'd", "they'll", "they're", "they've", "this", "those", "through", "to", "too", "under", "until", "up", "very", "was", "wasn't", "we", "we'd", "we'll", "we're", "we've", "were", "weren't", "what", "what's", "when", "when's", "where", "where's", "which", "while", "who", "who's", "whom", "why", "why's", "with", "won't", "would", "wouldn't", "you", "you'd", "you'll", "you're", "you've", "your", "yours", "yourself", "yourselves"]; + + +// Word replace + +var tipuesearch_replace = {'words': [ + {'word': 'tip', 'replace_with': 'tipue'}, + {'word': 'javscript', 'replace_with': 'javascript'}, + {'word': 'jqeury', 'replace_with': 'jquery'} +]}; + + +// Weighting + +var tipuesearch_weight = {'weight': [ + {'url': 'http://www.tipue.com', 'score': 60}, + {'url': 'http://www.tipue.com/search', 'score': 60}, + {'url': 'http://www.tipue.com/tipr', 'score': 30}, + {'url': 'http://www.tipue.com/support', 'score': 20} +]}; + + +// Illogical stemming + +var tipuesearch_stem = {'words': [ + {'word': 'e-mail', 'stem': 'email'}, + {'word': 'javascript', 'stem': 'jquery'}, + {'word': 'javascript', 'stem': 'js'} +]}; + + +// Related + +var tipuesearch_related = {'Related': [ + {'search': 'tipue', 'related': 'Search', 'include': 1}, + {'search': 'tipue', 'related': 'jQuery'}, + {'search': 'tipue', 'related': 'Features'}, + {'search': 'tipue', 'related': 'Support'}, + {'search': 'tipue search', 'related': 'Help', 'include': 1}, + {'search': 'tipue search', 'related': 'Support'} +]}; + + +// Internal strings + +var tipuesearch_string_1 = 'No title'; +var tipuesearch_string_2 = 'Showing results for'; +var tipuesearch_string_3 = 'Search instead for'; +var tipuesearch_string_4 = '1 result'; +var tipuesearch_string_5 = 'results'; +var tipuesearch_string_6 = '<'; +var tipuesearch_string_7 = '>'; +var tipuesearch_string_8 = 'Nothing found.'; +var tipuesearch_string_9 = 'Common words are largely ignored.'; +var tipuesearch_string_10 = 'Related'; +var tipuesearch_string_11 = 'Search too short. Should be one character or more.'; +var tipuesearch_string_12 = 'Search too short. Should be'; +var tipuesearch_string_13 = 'characters or more.'; +var tipuesearch_string_14 = 'seconds'; +var tipuesearch_string_15 = 'Open Image'; +var tipuesearch_string_16 = 'Goto Page'; + + +// Internals + + +// Timer for showTime + +var startTimer = new Date().getTime(); + diff --git a/content/assets/stylesheets/includes/search.scss b/content/assets/stylesheets/includes/search.scss index 8cfbdb2..6761e6f 100644 --- a/content/assets/stylesheets/includes/search.scss +++ b/content/assets/stylesheets/includes/search.scss @@ -4,6 +4,10 @@ font: inherit; color: inherit; + // For border + border: 1px solid #e2e2e2; + border-color: transparent; + width: 40px; border-color: rgba(0, 0, 0, 0); diff --git a/content/assets/stylesheets/tipuesearch/tipuesearch.css b/content/assets/stylesheets/tipuesearch/tipuesearch.css new file mode 100755 index 0000000..763c7f0 --- /dev/null +++ b/content/assets/stylesheets/tipuesearch/tipuesearch.css @@ -0,0 +1,337 @@ +/* +Tipue Search 7.0 +Copyright (c) 2018 Tipue +Tipue Search is released under the MIT License +http://www.tipue.com/search +*/ + + +/* basics */ + + +.tipue_search_group:after +{ + content: ""; + display: table; + clear: both; +} + + +/* fonts, colors */ + + +.tipue_search_icon +{ + font: 300 24px/1 sans-serif; + color: #777; +} +#tipue_search_results_count, .tipue_search_related, .tipue_search_note +{ + font: 12px/1.3 monospace; + text-transform: uppercase; + color: #999; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} +#tipue_search_replace, #tipue_search_error, .tipue_search_content_text +{ + font: 300 16px/1.6 sans-serif; + color: #666; +} +#tipue_search_replace a +{ + color: #339e41; + text-decoration: none; +} +#tipue_search_replace a:hover +{ + color: #666; +} +.tipue_search_related_btn +{ + font: 11px/1 monospace; + color: #666; + text-transform: uppercase; + letter-spacing: 1px; + background-color: #f7f7f7; +} +.tipue_search_content_title +{ + font: 300 30px/1.2 sans-serif; + color: #333; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} +.tipue_search_content_title a +{ + color: #333; + text-decoration: none; +} +.tipue_search_content_url, .tipue_search_content_debug +{ + font: 300 15px/1.7 sans-serif; + color: #333; +} +.tipue_search_content_url a +{ + color: #339e41; + text-decoration: none; +} +.tipue_search_content_url a:hover +{ + color: #666; +} +.tipue_search_content_bold +{ + font-weight: 400; + color: #333; +} +.tipue_search_note a +{ + color: #999; + text-decoration: none; +} +.tipue_search_image_close +{ + font: 22px/1 monospace; + color: #ccc; +} +#tipue_search_zoom_text +{ + font: 11px/1.7 monospace; + color: #ccc; + text-transform: uppercase; + letter-spacing: 1px; +} +#tipue_search_zoom_text a +{ + color: #ccc; + text-decoration: none; + border-bottom: 2px solid #f7f7f7; +} +#tipue_search_zoom_text a:hover +{ + border: 0; +} +#tipue_search_foot_boxes +{ + font: 13px/1 sans-serif; + text-transform: uppercase; + color: #333; +} +#tipue_search_foot_boxes li a +{ + background-color: #f7f7f7; + color: #666; +} +#tipue_search_foot_boxes li.current +{ + background: #252525; + color: #ccc; +} +#tipue_search_foot_boxes li a:hover, .tipue_search_related_btn:hover +{ + background: #252525; + color: #ccc; +} + + +/* search box */ + + +.tipue_search_button +{ + position: relative; + float: left; + width: 47px; + height: 56px; + margin-left: -3px; + background-color: #f3f3f3; + border: none; + border-radius: 3px; + box-sizing: border-box; + cursor: pointer; + outline: 0; +} +.tipue_search_icon +{ + float: left; + transform: rotate(-45deg); + -moz-appearance: none; + -webkit-appearance: none; + box-sizing: border-box; + box-shadow: none; + outline: 0; + margin: -1px 0 0 8px; +} + + +/* search results */ + + +#tipue_search_content +{ + max-width: 100%; + margin: 0; +} +.tipue_search_result +{ + padding-top: 21px; +} +#tipue_search_results_count +{ + padding-top: 9px; +} +.tipue_search_related +{ + padding-top: 13px; +} +.tipue_search_related_block +{ + padding-bottom: 6px; +} +#tipue_search_warning +{ + padding-top: 10px; +} +.tipue_search_related_btn +{ + display: inline-block; + padding: 9px 10px; + text-decoration: none; + text-align: center; + border-radius: 3px; + margin: 9px 9px 0 0; + outline: 0; + transition: 0.2s; + cursor: pointer; +} +#tipue_search_replace +{ + padding-top: 13px; +} +#tipue_search_error +{ + padding-top: 13px; +} +.tipue_search_content_url +{ + padding-top: 3px; + word-wrap: break-word; + hyphens: auto; +} +.tipue_search_content_text +{ + word-wrap: break-word; + hyphens: auto; + margin-top: 1px; +} +.tipue_search_note +{ + padding-top: 5px; +} +.tipue_search_content_debug +{ + margin: 5px 0; +} + + +/* images */ + + +.tipue_search_image +{ + padding: 9px 0 6px 0; +} +.tipue_search_img +{ + width: 200px; + max-width: 100%; + height: auto; + transition: 0.5s; + border-radius: 1px; +} +.tipue_search_img:hover +{ + opacity: 0.7; +} +.tipue_search_image_zoom +{ + cursor: pointer; +} +#tipue_search_image_modal +{ + display: none; + position: fixed; + z-index: 1000; + left: 0; + top: 0; + width: 100%; + height: 100%; + overflow: auto; + background-color: rgba(0, 0, 0, 0.9); +} +.tipue_search_image_close +{ + position: absolute; + top: 0; + right: 0; + padding: 25px 30px; + cursor: pointer; +} +.tipue_search_image_block +{ + margin: 0 auto; + max-width: 900px; + padding: 73px 30px 30px 30px; + box-sizing: border-box; + color: #fff; +} +#tipue_search_zoom_img +{ + max-width: 100%; + height: auto; +} +#tipue_search_zoom_text, .tipue_search_zoom_options +{ + padding-top: 9px; +} + + +/* footer */ + + +#tipue_search_foot +{ + margin: 51px 0 21px 0; +} +#tipue_search_foot_boxes +{ + padding: 0; + margin: 0; + cursor: pointer; +} +#tipue_search_foot_boxes li +{ + display: inline; + list-style: none; + margin: 0; + padding: 0; +} +#tipue_search_foot_boxes li a +{ + padding: 10px 17px 11px 17px; + border-radius: 3px; + margin-right: 7px; + text-decoration: none; + text-align: center; + transition: 0.2s; +} +#tipue_search_foot_boxes li.current +{ + padding: 10px 17px 11px 17px; + border-radius: 3px; + margin-right: 7px; + text-align: center; +} + diff --git a/content/search.erb b/content/search.erb index 75cc144..d557d6b 100644 --- a/content/search.erb +++ b/content/search.erb @@ -17,19 +17,26 @@ title: Search
+<% content_for :head do %> + + + +<% end %> + <% content_for :scripts do %> - + +<%= asset :js, :tipuesearch_set %> <%= asset :js, :tipuesearch %> - - - - <%= asset :css, :main %> diff --git a/lib/helpers/search.rb b/lib/helpers/search.rb index 0778fed..971413c 100644 --- a/lib/helpers/search.rb +++ b/lib/helpers/search.rb @@ -14,7 +14,7 @@ module SearchHelper { title: e[:title], url: url_for(e), - text: excerptize(e.reps[:text].compiled_content, length: 200).tr("\n", ' '), + text: "#{e[:title]} #{e.reps[:text].compiled_content}", tags: '' } end