Skip to content

Commit

Permalink
Add search feature to main page
Browse files Browse the repository at this point in the history
  • Loading branch information
mrichart committed Mar 31, 2020
1 parent 9de6908 commit f6c399c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
37 changes: 35 additions & 2 deletions _layouts/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ <h1 class="page-heading">{{ page.title }}</h1>

{%- if posts.size > 0 -%}
<h2 class="post-list-heading">Todas las organizaciones</h2>
<ul class="post-list">

<!-- Html Elements for Search -->
<div id="search-container">
<input type="text" id="search-input" placeholder="buscar por nombre, ciudad, barrio o actividad...">
<ul id="results-container"></ul>
</div>

<ul id="list" class="post-list">
{%- assign date_format = site.minima.date_format | default: "%b %-d, %Y" -%}
{%- for post in posts -%}
<li>
Expand Down Expand Up @@ -56,4 +63,30 @@ <h3>

{%- endif -%}

</div>
</div>

<!-- Script pointing to search-script.js -->
<script src="js/search-script.js" type="text/javascript"></script>

<!-- Configuration -->
<script>
SimpleJekyllSearch({
searchInput: document.getElementById('search-input'),
resultsContainer: document.getElementById('results-container'),
searchResultTemplate: '<ul class="post-list"><li><span class="post-meta">{barrio}, {departamento}</span><h3><a class="post-link" href="{{ post.url | relative_url }}">{title}</a></h3></li></ul>',
json: '/search.json'
})
</script>

<script src="js/jquery-3.4.1.min.js"></script>

<script>
$(document).ready(function(){
$("#search-input").keyup(function() {
$("#list").hide();
if (!$('#search-input').val()) {
$("#list").show();
};
});
});
</script>
2 changes: 2 additions & 0 deletions js/jquery-3.4.1.min.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions js/search-script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions search.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
---
[
{% for post in site.organizaciones %}
{

"title" : "{{ post.title | escape }}",
"url" : "{{ site.baseurl }}{{ post.url }}",
"departamento" : "{{ post.departamento }}",
"barrio" : "{{ post.barrio }}",
"actividades" : "{{ post.actividades }}",
"necesidades" : "{{ post.necesidades }}"

} {% unless forloop.last %},{% endunless %}
{% endfor %}
]

0 comments on commit f6c399c

Please sign in to comment.