Add tipue search integration

Integrated tipue search plugin functionality (https://github.com/getpelican/pelican-plugins/tree/master/tipue_search), to use add USE_TIPUE_SEARCH = True to pelicanconf.py and optional search.html page
This commit is contained in:
Fizban 2019-12-12 19:51:42 +11:00
parent bb3ca5f4e1
commit 5ba7257eeb
8 changed files with 1237 additions and 1 deletions

4
static/tipuesearch/jquery.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,299 @@
@import url('https://fonts.googleapis.com/css?family=Merriweather:300,400|Open+Sans|Source+Code+Pro');
/*
Tipue Search 7.1
Copyright (c) 2019 Tipue
Tipue Search is released under the MIT License
http://www.tipue.com/search
*/
/* search box */
#tipue_search_input {
font-family: Source Sans Pro, Roboto, Open Sans, Liberation Sans, DejaVu Sans, Verdana, Helvetica, Arial, sans-serif;
color: #333;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
background-color: #f3f3f3;
border: none;
padding: 9px 0 10px 18px;
border-radius: 3px;
-moz-appearance: none;
-webkit-appearance: none;
box-sizing: border-box;
box-shadow: none;
outline: 0;
margin: 0;
}
#tipue_search_input:-webkit-autofill,
#tipue_search_input:-webkit-autofill:hover,
#tipue_search_input:-webkit-autofill:focus {
-webkit-box-shadow: 0 0 0px 1000px #f3f3f3 inset;
}
.tipue_search_button {
position: relative;
float: left;
width: 49px;
height: 56px;
margin-left: -3px;
background-color: #f3f3f3;
border: none;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
box-sizing: border-box;
cursor: pointer;
outline: 0;
}
.tipue_search_icon {
float: left;
font: 24px/1 'Open Sans', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #333;
transform: rotate(-45deg);
-moz-appearance: none;
-webkit-appearance: none;
box-sizing: border-box;
box-shadow: none;
outline: 0;
margin: -1px 0 0 16px;
}
.tipue_search_group:after {
content: "";
display: table;
clear: both;
}
/* search results */
#tipue_search_content {
max-width: 100%;
margin: 0;
}
.tipue_search_content_title {
font-family: Source Sans Pro, Roboto, Open Sans, Liberation Sans, DejaVu Sans, Verdana, Helvetica, Arial, sans-serif;
font-weight: 300;
line-height: 1.1;
font-size: 2em;
}
.tipue_search_content_title a {
color: #d9411e;
text-decoration: none;
}
.tipue_search_content_title a:hover {
color: #ff5a09
}
.tipue_search_result {
margin: 0 8% 2%;
line-height: 1.2em;
}
#tipue_search_results_count,
.tipue_search_content_debug {
font-family: Source Sans Pro, Roboto, Open Sans, Liberation Sans, DejaVu Sans, Verdana, Helvetica, Arial, sans-serif;
text-transform: uppercase;
color: #999;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
#tipue_search_results_count {
padding-top: 9px;
}
.tipue_search_content_url,
.tipue_search_note,
.tipue_search_related,
#tipue_search_error,
#tipue_search_replace {
font-family: Source Sans Pro, Roboto, Open Sans, Liberation Sans, DejaVu Sans, Verdana, Helvetica, Arial, sans-serif;
color: #666;
padding-top: 7px;
word-wrap: break-word;
hyphens: auto;
}
.tipue_search_content_url a,
.tipue_search_note a,
.tipue_search_related a,
#tipue_search_replace a,
#tipue_search_replace a:hover {
color: #339e41;
text-decoration: none;
}
.tipue_search_content_url a:hover,
.tipue_search_note a:hover,
.tipue_search_related a:hover {
color: #666;
}
#tipue_search_replace,
.tipue_search_related {
margin-top: 7px;
}
#tipue_search_error {
color: #333;
margin-top: 17px;
}
.tipue_search_content_text {
margin: 0;
padding: 0;
background-color: #fff;
color: #242121;
font-family: Source Sans Pro, Roboto, Open Sans, Liberation Sans, DejaVu Sans, Verdana, Helvetica, Arial, sans-serif;
font-size: 1.02em;
line-height: 1.2em
}
.tipue_search_content_bold {
font-weight: 400;
color: #333;
}
.tipue_search_content_debug {
margin: 7px 0 2px 0;
}
/* images */
.tipue_search_image {
padding: 17px 0 6px 0;
}
.tipue_search_img {
width: 100%;
max-width: 330px;
height: auto;
transition: 0.5s;
border-radius: 2px;
}
.tipue_search_img:hover {
opacity: 0.9;
}
#tipue_search_zoom_text {
font: 12px/1.7 'Source Code Pro', monospace;
color: #ccc;
text-transform: uppercase;
letter-spacing: 1px;
padding-top: 9px;
}
#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_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;
font: 22px/1 'Source Code Pro', monospace;
color: #ccc;
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 {
font: 14px 'Source Code Pro', sans-serif;
text-transform: uppercase;
color: #333;
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 {
background-color: #f7f7f7;
color: #666;
padding: 10px 17px 11px 17px;
border-radius: 3px;
margin-right: 7px;
text-decoration: none;
text-align: center;
transition: 0.3s;
}
#tipue_search_foot_boxes li.current {
background: #252525;
color: #ccc;
padding: 10px 17px 11px 17px;
border-radius: 3px;
margin-right: 7px;
text-align: center;
}
#tipue_search_foot_boxes li a:hover {
background: #252525;
color: #ccc;
}
3

View file

@ -0,0 +1,611 @@
/*
Tipue Search 7.1
Copyright (c) 2019 Tipue
Tipue Search is released under the MIT License
http://www.tipue.com/search
*/
(function($) {
$.fn.tipuesearch = function(options) {
var set = $.extend( {
'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
}, options);
return this.each(function() {
var tipuesearch_t_c = 0;
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)
{
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(' ');
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++;
}
}
}
if (c != 0)
{
if (set.showTitleCount && tipuesearch_t_c == 0)
{
var title = document.title;
document.title = '(' + c + ') ' + title;
tipuesearch_t_c++;
}
if (c == 1)
{
out += '<div id="tipue_search_results_count">' + tipuesearch_string_4;
}
else
{
var c_c = c.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
out += '<div id="tipue_search_results_count">' + 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 += '</div>';
if (set.showRelated && standard)
{
var ront = '';
f = 0;
for (var i = 0; i < tipuesearch_related.Related.length; i++)
{
if (d == tipuesearch_related.Related[i].search)
{
if (!f)
{
out += '<div class="tipue_search_related">' + tipuesearch_string_10 + ': ';
}
if (show_replace)
{
d_o = d;
}
if (tipuesearch_related.Related[i].include)
{
var r_d = d_o + ' ' + tipuesearch_related.Related[i].related;
}
else
{
var r_d = tipuesearch_related.Related[i].related;
}
ront += '<a class="tipue_search_related_btn" id="' + r_d + '">' + tipuesearch_related.Related[i].related + '</a>, ';
f++;
}
}
if (f)
{
ront = ront.slice(0, -2);
ront += '.</div>';
out += ront;
}
}
if (show_replace)
{
out += '<div id="tipue_search_replace">' + tipuesearch_string_2 + ' ' + d + '. ' + tipuesearch_string_3 + ' <a id="tipue_search_replaced">' + d_r + '</a></div>';
}
found.sort(function(a, b) { return b.score - a.score } );
var l_o = 0;
if (set.imageZoom)
{
out += '<div id="tipue_search_image_modal"><div class="tipue_search_image_close">&#10005;</div><div class="tipue_search_image_block"><a id="tipue_search_zoom_url"><img id="tipue_search_zoom_img"></a><div id="tipue_search_zoom_text"></div></div></div>';
}
for (var i = 0; i < found.length; i++)
{
if (l_o >= start && l_o < set.show + start)
{
out += '<div class="tipue_search_result">';
out += '<div class="tipue_search_content_title"><a href="' + found[i].url + '"' + tipue_search_w + '>' + found[i].title + '</a></div>';
if (set.debug)
{
out += '<div class="tipue_search_content_debug">Score: ' + found[i].score + '</div>';
}
if (set.showURL)
{
var s_u = found[i].url.toLowerCase();
if (s_u.indexOf('http://') == 0)
{
s_u = s_u.slice(7);
}
out += '<div class="tipue_search_content_url"><a href="' + found[i].url + '"' + tipue_search_w + '>' + s_u + '</a></div>';
}
if (found[i].img)
{
if (set.imageZoom)
{
out += '<div class="tipue_search_image"><img class="tipue_search_img tipue_search_image_zoom" src="' + found[i].img + '" alt="' + found[i].title + '" data-url="' + found[i].url + '"></div>';
}
else
{
out += '<div class="tipue_search_image"><a href="' + found[i].url + '"' + tipue_search_w + '><img class="tipue_search_img" src="' + found[i].img + '" alt="' + found[i].title + '"></a></div>';
}
}
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, "<h0011>$1<h0012>");
}
}
}
else if (set.highlightTerms)
{
var patr = new RegExp('(' + d + ')', 'gi');
t = t.replace(patr, "<span class=\"tipue_search_content_bold\">$1</span>");
}
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 += '<div class="tipue_search_content_text">' + t_d + '</div>';
}
if (found[i].note)
{
out += '<div class="tipue_search_note">' + found[i].note + '</div>';
}
out += '</div>';
}
l_o++;
}
if (c > set.show)
{
var pages = Math.ceil(c / set.show);
var page = (start / set.show);
if (set.footerPages < 3)
{
set.footerPages = 3;
}
out += '<div id="tipue_search_foot"><ul id="tipue_search_foot_boxes">';
if (start > 0)
{
out += '<li role="navigation"><a class="tipue_search_foot_box" accesskey="b" id="' + (start - set.show) + '_' + replace + '">' + tipuesearch_string_6 + '</a></li>';
}
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 += '<li class="current" role="navigation">' + (f + 1) + '</li>';
}
else
{
out += '<li role="navigation"><a class="tipue_search_foot_box" id="' + (f * set.show) + '_' + replace + '">' + (f + 1) + '</a></li>';
}
}
}
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 += '<li class="current" role="navigation">' + (f + 1) + '</li>';
}
else
{
out += '<li role="navigation"><a class="tipue_search_foot_box" id="' + (f * set.show) + '_' + replace + '">' + (f + 1) + '</a></li>';
}
}
}
if (page + 1 != pages)
{
out += '<li role="navigation"><a class="tipue_search_foot_box" accesskey="m" id="' + (start + set.show) + '_' + replace + '">' + tipuesearch_string_7 + '</a></li>';
}
out += '</ul></div>';
}
}
else
{
out += '<div id="tipue_search_error">' + tipuesearch_string_8 + '</div>';
}
}
else
{
if (show_stop)
{
out += '<div id="tipue_search_error">' + tipuesearch_string_8 + ' ' + tipuesearch_string_9 + '</div>';
}
else
{
if (set.minimumLength == 1)
{
out += '<div id="tipue_search_error">' + tipuesearch_string_11 + '</div>';
}
else
{
out += '<div id="tipue_search_error">' + tipuesearch_string_12 + ' ' + set.minimumLength + ' ' + tipuesearch_string_13 + '</div>';
}
}
}
$('#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 + '<div class="tipue_search_zoom_options"><a href="' + this.src + '" target="_blank">' + tipuesearch_string_15 + '</a>&nbsp; <a href="' + z_u + '">' + tipuesearch_string_16 + '</a></div>';
$('#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);

181
static/tipuesearch/tipuesearch.min.js vendored Normal file
View file

@ -0,0 +1,181 @@
(function($){$.fn.tipuesearch=function(options){var set=$.extend({'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},options);return this.each(function(){var tipuesearch_t_c=0;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)
{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(' ');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++;}}}
if(c!=0)
{if(set.showTitleCount&&tipuesearch_t_c==0)
{var title=document.title;document.title='('+c+') '+title;tipuesearch_t_c++;}
if(c==1)
{out+='<div id="tipue_search_results_count">'+tipuesearch_string_4;}
else
{var c_c=c.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",");out+='<div id="tipue_search_results_count">'+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+='</div>';if(set.showRelated&&standard)
{var ront='';f=0;for(var i=0;i<tipuesearch_related.Related.length;i++)
{if(d==tipuesearch_related.Related[i].search)
{if(!f)
{out+='<div class="tipue_search_related">'+tipuesearch_string_10+': ';}
if(show_replace)
{d_o=d;}
if(tipuesearch_related.Related[i].include)
{var r_d=d_o+' '+tipuesearch_related.Related[i].related;}
else
{var r_d=tipuesearch_related.Related[i].related;}
ront+='<a class="tipue_search_related_btn" id="'+r_d+'">'+tipuesearch_related.Related[i].related+'</a>, ';f++;}}
if(f)
{ront=ront.slice(0,-2);ront+='.</div>';out+=ront;}}
if(show_replace)
{out+='<div id="tipue_search_replace">'+tipuesearch_string_2+' '+d+'. '+tipuesearch_string_3+' <a id="tipue_search_replaced">'+d_r+'</a></div>';}
found.sort(function(a,b){return b.score-a.score});var l_o=0;if(set.imageZoom)
{out+='<div id="tipue_search_image_modal"><div class="tipue_search_image_close">&#10005;</div><div class="tipue_search_image_block"><a id="tipue_search_zoom_url"><img id="tipue_search_zoom_img"></a><div id="tipue_search_zoom_text"></div></div></div>';}
for(var i=0;i<found.length;i++)
{if(l_o>=start&&l_o<set.show+start)
{out+='<div class="tipue_search_result">';out+='<div class="tipue_search_content_title"><a href="'+found[i].url+'"'+tipue_search_w+'>'+found[i].title+'</a></div>';if(set.debug)
{out+='<div class="tipue_search_content_debug">Score: '+found[i].score+'</div>';}
if(set.showURL)
{var s_u=found[i].url.toLowerCase();if(s_u.indexOf('http://')==0)
{s_u=s_u.slice(7);}
out+='<div class="tipue_search_content_url"><a href="'+found[i].url+'"'+tipue_search_w+'>'+s_u+'</a></div>';}
if(found[i].img)
{if(set.imageZoom)
{out+='<div class="tipue_search_image"><img class="tipue_search_img tipue_search_image_zoom" src="'+found[i].img+'" alt="'+found[i].title+'" data-url="'+found[i].url+'"></div>';}
else
{out+='<div class="tipue_search_image"><a href="'+found[i].url+'"'+tipue_search_w+'><img class="tipue_search_img" src="'+found[i].img+'" alt="'+found[i].title+'"></a></div>';}}
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,"<h0011>$1<h0012>");}}}
else if(set.highlightTerms)
{var patr=new RegExp('('+d+')','gi');t=t.replace(patr,"<span class=\"tipue_search_content_bold\">$1</span>");}
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+='<div class="tipue_search_content_text">'+t_d+'</div>';}
if(found[i].note)
{out+='<div class="tipue_search_note">'+found[i].note+'</div>';}
out+='</div>';}
l_o++;}
if(c>set.show)
{var pages=Math.ceil(c / set.show);var page=(start / set.show);if(set.footerPages<3)
{set.footerPages=3;}
out+='<div id="tipue_search_foot"><ul id="tipue_search_foot_boxes">';if(start>0)
{out+='<li role="navigation"><a class="tipue_search_foot_box" accesskey="b" id="'+(start-set.show)+'_'+replace+'">'+tipuesearch_string_6+'</a></li>';}
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+='<li class="current" role="navigation">'+(f+1)+'</li>';}
else
{out+='<li role="navigation"><a class="tipue_search_foot_box" id="'+(f*set.show)+'_'+replace+'">'+(f+1)+'</a></li>';}}}
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+='<li class="current" role="navigation">'+(f+1)+'</li>';}
else
{out+='<li role="navigation"><a class="tipue_search_foot_box" id="'+(f*set.show)+'_'+replace+'">'+(f+1)+'</a></li>';}}}
if(page+1!=pages)
{out+='<li role="navigation"><a class="tipue_search_foot_box" accesskey="m" id="'+(start+set.show)+'_'+replace+'">'+tipuesearch_string_7+'</a></li>';}
out+='</ul></div>';}}
else
{out+='<div id="tipue_search_error">'+tipuesearch_string_8+'</div>';}}
else
{if(show_stop)
{out+='<div id="tipue_search_error">'+tipuesearch_string_8+' '+tipuesearch_string_9+'</div>';}
else
{if(set.minimumLength==1)
{out+='<div id="tipue_search_error">'+tipuesearch_string_11+'</div>';}
else
{out+='<div id="tipue_search_error">'+tipuesearch_string_12+' '+set.minimumLength+' '+tipuesearch_string_13+'</div>';}}}
$('#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+'<div class="tipue_search_zoom_options"><a href="'+this.src+'" target="_blank">'+tipuesearch_string_15+'</a>&nbsp; <a href="'+z_u+'">'+tipuesearch_string_16+'</a></div>';$('#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);

View file

@ -0,0 +1,17 @@
var tipuesearch = {"pages": [
{"title": "Tipue", "text": "Tipue is a small web development studio based in North London.", "url": "http://www.tipue.com"},
{"title": "Tipue Search", "text": "Tipue Search. A site search jQuery plugin. It's free, open source and fast. Tipue Search only needs a browser that supports jQuery. It doesn't need MySQL or similar, Tipue Search uses a JavaScript object for content.", "tags": "JavaScript", "url": "http://www.tipue.com/search"},
{"title": "Tipue Slide", "text": "Tipue Slide is a sliding panel site search jQuery plugin. It's free, open source and fast.", "url": "http://www.tipue.com/slide"},
{"title": "About Tipue", "text": "Tipue is a small web development studio based in North London, founded in 2001. We design innovative and original JavaScript and jQuery plugins, which we connect to servers and MySQL databases with fast, heavy-duty Perl.", "url": "http://www.tipue.com/is"},
{"title": "Tipr", "text": "Tipr. A small and simple jQuery tooltip plugin. It's free and open source. Small, simple, flat, cool. Tipr is a jQuery tooltip plugin. It works on almost any element, and reacts to the size of the viewport. Tipr is free and open source.", "tags": "JavaScript", "url": "http://www.tipue.com/tipr"},
{"title": "Tipue Support", "text": "Tipue support. We offer a range of flexible support plans for our products, services and jQuery plugins, including free.", "url": "http://www.tipue.com/support"},
{"title": "Playing with CSS Sticky Positioning", "text": "While the fixed and sticky position elements seems rather similar, the sticky element maintains its position only within its containing block. Sticky is relative, which allows all sorts of potential creativity.", "img": "http://www.tipue.com/img/sony.jpg", "tags": "Tipue Blog", "note": "<a href='http://www.tipue.com/blog/'>More articles</a>", "url": "http://www.tipue.com/blog/css-sticky"},
{"title": "The Complete Guide to Centering a Div", "text": "Every developer inevitably finds that centering a div isn't as obvious as you'd expect. Centering what's inside a div horizontally is easy but then things tend to get a bit sticky. When you get to centering a div vertically, you can end up in a world of CSS hurt.", "tags": "Tipue Blog", "note": "<a href='http://www.tipue.com/blog/'>More articles</a>", "url": "http://www.tipue.com/blog/center-a-div"},
{"title": "Cool CSS Radio Buttons and Checkboxes", "text": "Hip and easy radio button and checkbox form elements styled with CSS.", "tags": "Tipue Blog", "note": "<a href='http://www.tipue.com/blog/'>More articles</a>", "url": "http://www.tipue.com/blog/radio-checkbox"},
{"title": "Hacking CSS Writing Mode", "text": "The writing-mode CSS property sets horizontal and vertical text direction. While meant for multilingual purposes, it can be exploited for design.", "img": "http://www.tipue.com/img/tran.jpg", "tags": "Tipue Blog", "note": "<a href='http://www.tipue.com/blog/'>More articles</a>", "url": "http://www.tipue.com/blog/css-writing-mode"},
{"title": "Using Vw and Vh", "text": "Viewport width (vw) and viewport height (vh) are viewport-percentage values introduced in CSS3. Given how powerful they are, and with almost complete browser support, they should be everywhere.", "tags": "Tipue Blog", "note": "<a href='http://www.tipue.com/blog/'>More articles</a>", "url": "http://www.tipue.com/blog/css3-vw-vh"},
{"title": "Using CSS Feature Queries", "text": "CSS feature queries are now supported everywhere. They allow you to use cutting edge CSS with subtle and precise feature detection.", "tags": "Tipue Blog", "note": "<a href='http://www.tipue.com/blog/'>More articles</a>", "url": "http://www.tipue.com/blog/feature-queries"},
{"title": "A Very Simple CSS Background Zoom", "text": "A really easy method of creating a CSS background image zoom. Not only is this simple, it comes with wide browser support.", "tags": "Tipue Blog", "note": "<a href='http://www.tipue.com/blog/'>More articles</a>", "url": "http://www.tipue.com/blog/css-background-zoom"},
{"title": "Using Z-index", "text": "The CSS z-index property often trips up both new and experienced developers. The aim of this article is to boil down a somewhat-complex specification to three major points, which should ease most z-index pain.", "tags": "Tipue Blog", "note": "<a href='http://www.tipue.com/blog/'>More articles</a>", "url": "http://www.tipue.com/blog/z-index"}
]};

View file

@ -0,0 +1,84 @@
/*
Tipue Search 7.1
Copyright (c) 2019 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': 'Blog'},
{'search': 'tipue', 'related': 'Support'},
{'search': 'tipue search', 'related': 'Demo', '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 should be one character or more.';
var tipuesearch_string_12 = 'Search 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();

View file

@ -28,6 +28,15 @@
<link rel="stylesheet" type="text/css" href="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/stylesheet/style.min.css"> <link rel="stylesheet" type="text/css" href="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/stylesheet/style.min.css">
{% endif %} {% endif %}
{% if USE_TIPUE_SEARCH %}
<script src="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/tipuesearch/jquery.min.js"></script>
<script src="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/tipuesearch/tipuesearch.min.js"></script>
<script src="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/tipuesearch/tipuesearch.js"></script>
<script src="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/tipuesearch/tipuesearch_set.js"></script>
<link rel="stylesheet" href="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/tipuesearch/tipuesearch.css" />
<script src="{{ SITEURL }}/tipuesearch_content.js"></script>
{% endif %}
<link rel="stylesheet" type="text/css" href="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/pygments/{{ PYGMENTS_STYLE|default('github') }}.min.css"> <link rel="stylesheet" type="text/css" href="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/pygments/{{ PYGMENTS_STYLE|default('github') }}.min.css">
<link rel="stylesheet" type="text/css" href="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/font-awesome/css/fontawesome.css"> <link rel="stylesheet" type="text/css" href="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/font-awesome/css/fontawesome.css">
<link rel="stylesheet" type="text/css" href="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/font-awesome/css/brands.css"> <link rel="stylesheet" type="text/css" href="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/font-awesome/css/brands.css">
@ -103,7 +112,11 @@
<h1><a href="{{ SITEURL }}">{{ SITETITLE }}</a></h1> <h1><a href="{{ SITEURL }}">{{ SITETITLE }}</a></h1>
{% if SITESUBTITLE %}<p>{{ SITESUBTITLE }}</p>{% endif %} {% if SITESUBTITLE %}<p>{{ SITESUBTITLE }}</p>{% endif %}
{% if USE_TIPUE_SEARCH %}
<form class="navbar-search" action="/search.html" role="search">
<input type="text" name="q" id="tipue_search_input" placeholder="Search..">
</form>
{% endif %}
{% if pages or LINKS %} {% if pages or LINKS %}
<nav> <nav>
<ul class="list"> <ul class="list">
@ -218,5 +231,13 @@
{% if GITHUB_CORNER_URL %} {% if GITHUB_CORNER_URL %}
{% include 'partial/github.html' %} {% include 'partial/github.html' %}
{% endif %} {% endif %}
{% if USE_TIPUE_SEARCH %}
<script>
$(document).ready(function() {
$('#tipue_search_input').tipuesearch();
});
</script>
{% endif %}
</body> </body>
</html> </html>

19
templates/search.html Normal file
View file

@ -0,0 +1,19 @@
{% if 'search' in DIRECT_TEMPLATES and USE_TIPUE_SEARCH %} {% extends 'base.html' %} {% block title %} Search - {{ SITENAME|striptags }} {% endblock title %} {% block content %}
<script>
$(document).ready(function() {
$('#tipue_search_input').tipuesearch({
'show': 10,
'mode': 'json',
'contentLocation': '{{ SITEURL }}/tipuesearch_content.js'
});
});
</script>
<article class="single">
<header>
<h1 id="categories">{{ _('Search Results') }}</h1>
</header>
<div id="tipue_search_content"></div>
</article>
{% endblock content %} {% endif %}