You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fluo.apache.org by mw...@apache.org on 2018/05/09 21:42:53 UTC

[fluo-website] branch gh-pages updated: Adding Search functionality to website (#162)

This is an automated email from the ASF dual-hosted git repository.

mwalch pushed a commit to branch gh-pages
in repository https://gitbox.apache.org/repos/asf/fluo-website.git


The following commit(s) were added to refs/heads/gh-pages by this push:
     new 35ac890  Adding Search functionality to website (#162)
35ac890 is described below

commit 35ac890ca477d4e7f4b1de88b97cdcd747360e77
Author: Mike Walch <mw...@apache.org>
AuthorDate: Wed May 9 17:42:51 2018 -0400

    Adding Search functionality to website (#162)
    
    * Implemented using lunar.js
    * Changed ASF dropdown to feather logo
---
 _layouts/default.html |  3 ++-
 js/search.js          | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 pages/search.md       | 30 ++++++++++++++++++++++++++++++
 search_data.json      | 30 ++++++++++++++++++++++++++++++
 4 files changed, 110 insertions(+), 1 deletion(-)

diff --git a/_layouts/default.html b/_layouts/default.html
index 89c754c..b6297f5 100644
--- a/_layouts/default.html
+++ b/_layouts/default.html
@@ -59,10 +59,11 @@
                 <li><a href="{{ site.baseurl }}/release-process/">Release Process</a></li>
               </ul>
             </li>
+            <li><a href="{{ site.baseurl }}/search/">Search</a></li>
           </ul>
           <ul class="navbar-nav nav navbar-right">
             <li class="dropdown">
-              <a class="dropdown-toggle" data-toggle="dropdown" href="#">Apache Software Foundation<span class="caret"></span></a>
+              <a class="dropdown-toggle" data-toggle="dropdown" href="#"><img alt="Apache Software Foundation" src="https://www.apache.org/images/feather-small.png" width="70"/><span class="caret"></span></a>
               <ul class="dropdown-menu">
                 <li><a href="https://www.apache.org">Apache Homepage</a></li>
                 <li><a href="https://www.apache.org/licenses/">License</a></li>
diff --git a/js/search.js b/js/search.js
new file mode 100644
index 0000000..5501f85
--- /dev/null
+++ b/js/search.js
@@ -0,0 +1,48 @@
+jQuery(function() {
+
+  window.idx = lunr(function () {
+    this.field('id');
+    this.field('title');
+    this.field('content', { boost: 10 });
+    this.field('categories');
+  });
+
+  window.data = $.getJSON('/search_data.json');
+
+  window.data.then(function(loaded_data){
+    $.each(loaded_data, function(index, value){
+      window.idx.add($.extend({ "id": index }, value));
+    });
+  });
+
+  $("#site_search").submit(function(event){
+      event.preventDefault();
+      var query = $("#search_box").val();
+      var results = window.idx.search(query);
+      display_search_results(query, results);
+  });
+
+  function display_search_results(query, results) {
+    var $search_status = $("#search_status");
+    var $search_results = $("#search_results");
+
+    window.data.then(function(loaded_data) {
+
+      if (results.length) {
+        $search_status.html('Found ' + results.length + ' results for "' + query + '"');
+        $search_results.empty();
+        results.forEach(function(result) {
+          var item = loaded_data[result.ref];
+          var n = item.content.search(query) - 50
+          if (n < 0) {
+            n = 0;
+          }
+          var appendString = '<tr><td><a href="' + item.url + '">' + item.title + '</a><td>' + item.content.substring(n, n+100) + '</tr>';
+          $search_results.append(appendString);
+        });
+      } else {
+        $search_status.html('No results found!');
+      }
+    });
+  }
+});
diff --git a/pages/search.md b/pages/search.md
new file mode 100644
index 0000000..3e2fdd5
--- /dev/null
+++ b/pages/search.md
@@ -0,0 +1,30 @@
+---
+layout: page
+title: Search
+permalink: /search/
+---
+
+Search results are limited to blog posts, release notes, and documentation (Fluo 1.2 & Fluo Recipes 1.2).
+
+<div class="row">
+  <div class="col-lg-6">
+    <form action="get" id="site_search">
+      <div class="input-group">
+        <input class="form-control" type="text" id="search_box" placeholder="Search for...">
+        <span class="input-group-btn">
+          <button class="btn btn-default" type="submit">Search</button>
+        </span>
+      </div>
+    </form>
+  </div>
+</div>
+
+<br/>
+
+<div id="search_status"></div>
+
+<table class="table table-striped" id="search_results"></table>
+
+<script src="https://cdnjs.cloudflare.com/ajax/libs/lunr.js/1.0.0/lunr.min.js"></script>
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
+<script src="/js/search.js"></script>
diff --git a/search_data.json b/search_data.json
new file mode 100644
index 0000000..25c3c52
--- /dev/null
+++ b/search_data.json
@@ -0,0 +1,30 @@
+---
+layout: null
+---
+{
+  {% for post in site.fluo-1-2 %}
+    "{{ post.url | slugify }}": {
+      "title": "{{ post.title | xml_escape }}",
+      "content"	 : "{{post.content | strip_html | strip_newlines | remove:  "	" | escape | remove: "\"}}",
+      "url": " {{ post.url | xml_escape }}",
+      "categories": "{% for category in post.categories %}{{ category }}{% unless forloop.last %}, {% endunless %}{% endfor %}"
+    },
+  {% endfor %}
+  {% for post in site.recipes-1-2 %}
+    "{{ post.url | slugify }}": {
+      "title": "{{ post.title | xml_escape }}",
+      "content"	 : "{{post.content | strip_html | strip_newlines | remove:  "	" | escape | remove: "\"}}",
+      "url": " {{ post.url | xml_escape }}",
+      "categories": "{% for category in post.categories %}{{ category }}{% unless forloop.last %}, {% endunless %}{% endfor %}"
+    },
+  {% endfor %}
+  {% for post in site.posts %}
+    "{{ post.url | slugify }}": {
+      "title": "{{ post.title | xml_escape }}",
+      "content"	 : "{{post.content | strip_html | strip_newlines | remove:  "	" | escape | remove: "\"}}",
+      "url": " {{ post.url | xml_escape }}",
+      "categories": "{% for category in post.categories %}{{ category }}{% unless forloop.last %}, {% endunless %}{% endfor %}"
+    }
+    {% unless forloop.last %},{% endunless %}
+  {% endfor %}
+}

-- 
To stop receiving notification emails like this one, please contact
mwalch@apache.org.