Skip to content

Commit

Permalink
adding search capability
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfsilva committed Jul 3, 2022
1 parent dd0549b commit 6432a7e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
26 changes: 22 additions & 4 deletions _includes/search_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,34 @@
json: "/search.json",
searchResultTemplate: `
<a href="{url}">
{category}
<strong>{title}</strong><br/>
<span class="search-desc">{description}</span>
{description}
</a>
<div class="search-cat">{category}</div>
`,
templateMiddleware: function (prop, value, template) {
if (prop == "description") {
return value.substring(0,50) + "...";
if (value.length > 0) {
value = '<span class="search-desc">' + value + '</span>'
if (value.length > 75) {
return value.substring(0, 75) + "...";
}
} else {
return ""
}
}
if (prop == "category") {
let color = "f2b3a2"
if (value == "story") {
color = "D89398"
} else if (value == "event") {
color = "85BCC2"
} else if (value == "job") {
color = "6689BA"
}
return '<span class="search-cat" style="background-color: #' + color + ';">' + value + '</span>'
}
},
noResultsText: '<span style="padding: 1em">No results found</span>'
noResultsText: '<span style="padding: 1em; line-height: 2em">No results found</span>'
})
</script>
3 changes: 3 additions & 0 deletions _includes/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
</a>
</li>
</ul>

{% include search_form.html %}

</section>

<!-- About -->
Expand Down
7 changes: 5 additions & 2 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -5088,9 +5088,12 @@ main a {
}

.search-cat {
position: absolute;
float: right;
top: 0;
right: 0;
z-index: 1000;
color: red;
font-size: 0.7em;
color: #fff;
padding: 0.1em 1em;
border-radius: 0.5em;
}
26 changes: 25 additions & 1 deletion search.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,32 @@
"title" : "{{ system.title }}",
"url" : "{{ site.baseurl }}{{ system.url }}",
"description" : "{{ system.description | strip_html | strip_newlines | escape }}",
"tags" : "{{ system.tags | strip_html | strip_newlines | escape }}",
"tags" : "{{ system.tags | array_to_sentence_string: '' }}",
"category" : "system"
},
{% endfor %}
{% for job in site.jobs %}
{
"title" : "{{ job.title }}",
"url" : "{{ site.baseurl }}{{ job.url }}",
"description" : "{{ job.content | strip_html | strip_newlines | escape }}",
"category" : "job"
},
{% endfor %}
{% for story in site.stories %}
{
"title" : "{{ story.title }}",
"url" : "{{ site.baseurl }}{{ story.url }}",
"description" : "{{ story.content | strip_html | strip_newlines | escape }}",
"category" : "story"
},
{% endfor %}
{% for event in site.data.events %}
{
"title" : "{{ event.series }} ({{ event.type }})",
"url" : "{{ event.url }}",
"description" : "{{ event.name }}",
"category" : "event"
} {% unless forloop.last %},{% endunless %}
{% endfor %}
]

0 comments on commit 6432a7e

Please sign in to comment.