Browse Source

basic search

master
Clark Wimberly 3 years ago
parent
commit
e101809442
7 changed files with 162 additions and 2 deletions
  1. +2
    -2
      _site/feed.xml
  2. +6
    -0
      _site/plugins/simple-jekyll-search.min.js
  3. +18
    -0
      _site/search.html
  4. +99
    -0
      _site/search.json
  5. +6
    -0
      plugins/simple-jekyll-search.min.js
  6. +18
    -0
      search.html
  7. +13
    -0
      search.json

+ 2
- 2
_site/feed.xml View File

@ -5,8 +5,8 @@
<description>The plain text recipe database for hackers</description>
<link>http://localhost:4000/</link>
<atom:link href="http://localhost:4000/feed.xml" rel="self" type="application/rss+xml"/>
<pubDate>Wed, 22 Aug 2018 20:59:28 -0500</pubDate>
<lastBuildDate>Wed, 22 Aug 2018 20:59:28 -0500</lastBuildDate>
<pubDate>Wed, 22 Aug 2018 21:07:33 -0500</pubDate>
<lastBuildDate>Wed, 22 Aug 2018 21:07:33 -0500</lastBuildDate>
<generator>Jekyll v3.8.3</generator>
<item>


+ 6
- 0
_site/plugins/simple-jekyll-search.min.js View File

@ -0,0 +1,6 @@
/*!
* Simple-Jekyll-Search v1.6.3 (https://github.com/christian-fei/Simple-Jekyll-Search)
* Copyright 2015-2018, Christian Fei
* Licensed under the MIT License.
*/
!function(){"use strict";var s={load:function(e,t){var n=window.XMLHttpRequest?new window.XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");n.open("GET",e,!0),n.onreadystatechange=(r=n,i=t,function(){if(4===r.readyState&&200===r.status)try{i(null,JSON.parse(r.responseText))}catch(e){i(e,null)}}),n.send();var r,i}};var n=function(e,t){var n=t.length,r=e.length;if(n<r)return!1;if(r===n)return e===t;e:for(var i=0,o=0;i<r;i++){for(var a=e.charCodeAt(i);o<n;)if(t.charCodeAt(o++)===a)continue e;return!1}return!0},t=new function(){this.matches=function(e,t){return n(t.toLowerCase(),e.toLowerCase())}};var r=new function(){this.matches=function(e,t){return"string"==typeof e&&0<=(e=e.trim()).toLowerCase().indexOf(t.toLowerCase())}};var f={put:function(e){if(l(e))return c(e);if(t=e,Boolean(t)&&"[object Array]"===Object.prototype.toString.call(t))return function(e){var t=[];u();for(var n=0,r=e.length;n<r;n++)l(e[n])&&t.push(c(e[n]));return t}(e);var t;return undefined},clear:u,search:function(e){if(!e)return[];return function(e,t,n,r){for(var i=[],o=0;o<e.length&&i.length<r.limit;o++){var a=p(e[o],t,n,r);a&&i.push(a)}return i}(o,e,a.searchStrategy,a).sort(a.sort)},setOptions:function(e){(a=e||{}).fuzzy=e.fuzzy||!1,a.limit=e.limit||10,a.searchStrategy=e.fuzzy?t:r,a.sort=e.sort||i}};function i(){return 0}var o=[],a={};function u(){return o.length=0,o}function l(e){return Boolean(e)&&"[object Object]"===Object.prototype.toString.call(e)}function c(e){return o.push(e),o}function p(e,t,n,r){for(var i in e)if(!d(e[i],r.exclude)&&n.matches(e[i],t))return e}function d(e,t){for(var n=!1,r=0,i=(t=t||[]).length;r<i;r++){var o=t[r];!n&&new RegExp(e).test(o)&&(n=!0)}return n}a.fuzzy=!1,a.limit=10,a.searchStrategy=a.fuzzy?t:r,a.sort=i;var h={compile:function(r){return m.template.replace(m.pattern,function(e,t){var n=m.middleware(t,r[t],m.template);return void 0!==n?n:r[t]||e})},setOptions:function(e){m.pattern=e.pattern||m.pattern,m.template=e.template||m.template,"function"==typeof e.middleware&&(m.middleware=e.middleware)}},m={};m.pattern=/\{(.*?)\}/g,m.template="",m.middleware=function(){};var y={merge:function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r],"undefined"!=typeof t[r]&&(n[r]=t[r]));return n},isJSON:function(e){try{return!!(e instanceof Object&&JSON.parse(JSON.stringify(e)))}catch(t){return!1}}};!function(t){var r={searchInput:null,resultsContainer:null,json:[],success:Function.prototype,searchResultTemplate:'<li><a href="{url}" title="{desc}">{title}</a></li>',templateMiddleware:Function.prototype,sortMiddleware:function(){return 0},noResultsText:"No results found",limit:10,fuzzy:!1,exclude:[]},i=["searchInput","resultsContainer","json"],o=function e(t){if(n=t,!(n&&"undefined"!=typeof n.required&&n.required instanceof Array))throw new Error("-- OptionsValidator: required options missing");var n;if(!(this instanceof e))return new e(t);var r=t.required;this.getRequiredOptions=function(){return r},this.validate=function(t){var n=[];return r.forEach(function(e){"undefined"==typeof t[e]&&n.push(e)}),n}}({required:i});function a(e){r.success(e),f.put(e),r.searchInput.addEventListener("keyup",function(e){var t;t=e.which,-1===[13,16,20,37,38,39,40,91].indexOf(t)&&(n(),l(e.target.value))})}function n(){r.resultsContainer.innerHTML=""}function u(e){r.resultsContainer.innerHTML+=e}function l(e){var t;(t=e)&&0<t.length&&(n(),function(e){var t=e.length;if(0===t)return u(r.noResultsText);for(var n=0;n<t;n++)u(h.compile(e[n]))}(f.search(e)))}function c(e){throw new Error("SimpleJekyllSearch --- "+e)}t.SimpleJekyllSearch=function(e){var n;return 0<o.validate(e).length&&c("You must specify the following required options: "+i),r=y.merge(r,e),h.setOptions({template:r.searchResultTemplate,middleware:r.templateMiddleware}),f.setOptions({fuzzy:r.fuzzy,limit:r.limit,sort:r.sortMiddleware}),y.isJSON(r.json)?a(r.json):(n=r.json,s.load(n,function(e,t){e&&c("failed to get JSON ("+n+")"),a(t)})),{search:l}},t.SimpleJekyllSearch.init=t.SimpleJekyllSearch,"function"==typeof t.SimpleJekyllSearchInit&&t.SimpleJekyllSearchInit.call(this,t.SimpleJekyllSearch)}(window)}();

+ 18
- 0
_site/search.html View File

@ -0,0 +1,18 @@
<!-- Html Elements for Search -->
<div id="search-container">
<input type="text" id="search-input" placeholder="search...">
<ul id="results-container"></ul>
</div>
<!-- Script pointing to search-script.js -->
<script src="/plugins/simple-jekyll-search.min.js" type="text/javascript"></script>
<!-- Configuration -->
<script>
SimpleJekyllSearch({
searchInput: document.getElementById('search-input'),
resultsContainer: document.getElementById('results-container'),
json: '/search.json',
searchResultTemplate: '<div><a href="{url}"><h1>{title}</h1></a><span>{date}</span></div>'
})
</script>

+ 99
- 0
_site/search.json View File

@ -0,0 +1,99 @@
[
{
"title" : "Broccoli Beer Cheese Soup",
"url" : "/recipes/broccoli-cheese-soup.html",
"date" : "2018-08-22 21:07:33 -0500"
} ,
{
"title" : "Crockpot Buffalo Chicken",
"url" : "/recipes/crockpot-buffalo-chicken.html",
"date" : "2018-08-22 21:07:33 -0500"
} ,
{
"title" : "Green Chile Stew",
"url" : "/recipes/green-chile-stew.html",
"date" : "2018-08-22 21:07:33 -0500"
} ,
{
"title" : "Mongolian Beef",
"url" : "/recipes/mongolian-beef.html",
"date" : "2018-08-22 21:07:33 -0500"
} ,
{
"title" : "New York Strip",
"url" : "/recipes/new-york-strip.html",
"date" : "2018-08-22 21:07:33 -0500"
} ,
{
"title" : "One Minute Muffin",
"url" : "/recipes/one-minute-muffin.html",
"date" : "2018-08-22 21:07:33 -0500"
} ,
{
"title" : "Pork Steaks",
"url" : "/recipes/pork-steaks.html",
"date" : "2018-08-22 21:07:33 -0500"
} ,
{
"title" : "Red Berry Tart",
"url" : "/recipes/red-berry-tart.html",
"date" : "2018-08-22 21:07:33 -0500"
} ,
{
"title" : "Roasted Brussels Sprouts",
"url" : "/recipes/roasted-brussels-sprouts.html",
"date" : "2018-08-22 21:07:33 -0500"
} ,
{
"title" : "Roasted Okra",
"url" : "/recipes/roasted-okra.html",
"date" : "2018-08-22 21:07:33 -0500"
} ,
{
"title" : "Smashed Carrots",
"url" : "/recipes/smashed-carrots.html",
"date" : "2018-08-22 21:07:33 -0500"
} ,
{
"title" : "Stuffed Peppers",
"url" : "/recipes/stuffed-peppers.html",
"date" : "2018-08-22 21:07:33 -0500"
}
]

+ 6
- 0
plugins/simple-jekyll-search.min.js View File

@ -0,0 +1,6 @@
/*!
* Simple-Jekyll-Search v1.6.3 (https://github.com/christian-fei/Simple-Jekyll-Search)
* Copyright 2015-2018, Christian Fei
* Licensed under the MIT License.
*/
!function(){"use strict";var s={load:function(e,t){var n=window.XMLHttpRequest?new window.XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");n.open("GET",e,!0),n.onreadystatechange=(r=n,i=t,function(){if(4===r.readyState&&200===r.status)try{i(null,JSON.parse(r.responseText))}catch(e){i(e,null)}}),n.send();var r,i}};var n=function(e,t){var n=t.length,r=e.length;if(n<r)return!1;if(r===n)return e===t;e:for(var i=0,o=0;i<r;i++){for(var a=e.charCodeAt(i);o<n;)if(t.charCodeAt(o++)===a)continue e;return!1}return!0},t=new function(){this.matches=function(e,t){return n(t.toLowerCase(),e.toLowerCase())}};var r=new function(){this.matches=function(e,t){return"string"==typeof e&&0<=(e=e.trim()).toLowerCase().indexOf(t.toLowerCase())}};var f={put:function(e){if(l(e))return c(e);if(t=e,Boolean(t)&&"[object Array]"===Object.prototype.toString.call(t))return function(e){var t=[];u();for(var n=0,r=e.length;n<r;n++)l(e[n])&&t.push(c(e[n]));return t}(e);var t;return undefined},clear:u,search:function(e){if(!e)return[];return function(e,t,n,r){for(var i=[],o=0;o<e.length&&i.length<r.limit;o++){var a=p(e[o],t,n,r);a&&i.push(a)}return i}(o,e,a.searchStrategy,a).sort(a.sort)},setOptions:function(e){(a=e||{}).fuzzy=e.fuzzy||!1,a.limit=e.limit||10,a.searchStrategy=e.fuzzy?t:r,a.sort=e.sort||i}};function i(){return 0}var o=[],a={};function u(){return o.length=0,o}function l(e){return Boolean(e)&&"[object Object]"===Object.prototype.toString.call(e)}function c(e){return o.push(e),o}function p(e,t,n,r){for(var i in e)if(!d(e[i],r.exclude)&&n.matches(e[i],t))return e}function d(e,t){for(var n=!1,r=0,i=(t=t||[]).length;r<i;r++){var o=t[r];!n&&new RegExp(e).test(o)&&(n=!0)}return n}a.fuzzy=!1,a.limit=10,a.searchStrategy=a.fuzzy?t:r,a.sort=i;var h={compile:function(r){return m.template.replace(m.pattern,function(e,t){var n=m.middleware(t,r[t],m.template);return void 0!==n?n:r[t]||e})},setOptions:function(e){m.pattern=e.pattern||m.pattern,m.template=e.template||m.template,"function"==typeof e.middleware&&(m.middleware=e.middleware)}},m={};m.pattern=/\{(.*?)\}/g,m.template="",m.middleware=function(){};var y={merge:function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r],"undefined"!=typeof t[r]&&(n[r]=t[r]));return n},isJSON:function(e){try{return!!(e instanceof Object&&JSON.parse(JSON.stringify(e)))}catch(t){return!1}}};!function(t){var r={searchInput:null,resultsContainer:null,json:[],success:Function.prototype,searchResultTemplate:'<li><a href="{url}" title="{desc}">{title}</a></li>',templateMiddleware:Function.prototype,sortMiddleware:function(){return 0},noResultsText:"No results found",limit:10,fuzzy:!1,exclude:[]},i=["searchInput","resultsContainer","json"],o=function e(t){if(n=t,!(n&&"undefined"!=typeof n.required&&n.required instanceof Array))throw new Error("-- OptionsValidator: required options missing");var n;if(!(this instanceof e))return new e(t);var r=t.required;this.getRequiredOptions=function(){return r},this.validate=function(t){var n=[];return r.forEach(function(e){"undefined"==typeof t[e]&&n.push(e)}),n}}({required:i});function a(e){r.success(e),f.put(e),r.searchInput.addEventListener("keyup",function(e){var t;t=e.which,-1===[13,16,20,37,38,39,40,91].indexOf(t)&&(n(),l(e.target.value))})}function n(){r.resultsContainer.innerHTML=""}function u(e){r.resultsContainer.innerHTML+=e}function l(e){var t;(t=e)&&0<t.length&&(n(),function(e){var t=e.length;if(0===t)return u(r.noResultsText);for(var n=0;n<t;n++)u(h.compile(e[n]))}(f.search(e)))}function c(e){throw new Error("SimpleJekyllSearch --- "+e)}t.SimpleJekyllSearch=function(e){var n;return 0<o.validate(e).length&&c("You must specify the following required options: "+i),r=y.merge(r,e),h.setOptions({template:r.searchResultTemplate,middleware:r.templateMiddleware}),f.setOptions({fuzzy:r.fuzzy,limit:r.limit,sort:r.sortMiddleware}),y.isJSON(r.json)?a(r.json):(n=r.json,s.load(n,function(e,t){e&&c("failed to get JSON ("+n+")"),a(t)})),{search:l}},t.SimpleJekyllSearch.init=t.SimpleJekyllSearch,"function"==typeof t.SimpleJekyllSearchInit&&t.SimpleJekyllSearchInit.call(this,t.SimpleJekyllSearch)}(window)}();

+ 18
- 0
search.html View File

@ -0,0 +1,18 @@
<!-- Html Elements for Search -->
<div id="search-container">
<input type="text" id="search-input" placeholder="search...">
<ul id="results-container"></ul>
</div>
<!-- Script pointing to search-script.js -->
<script src="/plugins/simple-jekyll-search.min.js" type="text/javascript"></script>
<!-- Configuration -->
<script>
SimpleJekyllSearch({
searchInput: document.getElementById('search-input'),
resultsContainer: document.getElementById('results-container'),
json: '/search.json',
searchResultTemplate: '<div><a href="{url}"><h1>{title}</h1></a><span>{date}</span></div>'
})
</script>

+ 13
- 0
search.json View File

@ -0,0 +1,13 @@
---
---
[
{% for post in site.recipes %}
{
"title" : "{{ post.title | escape }}",
"url" : "{{ site.baseurl }}{{ post.url }}",
"date" : "{{ post.date }}"
} {% unless forloop.last %},{% endunless %}
{% endfor %}
]

Loading…
Cancel
Save