Skip to content

Commit

Permalink
Merge pull request #418 from sylhare/search
Browse files Browse the repository at this point in the history
Improve search file
  • Loading branch information
sylhare committed Dec 17, 2023
2 parents 0b4900a + 4dbb110 commit 7c6f81f
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 31 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,12 @@ gallery: "assets/img/pexels"

The search feature is based on [Simple-Jekyll-search](https://github.com/christian-fei/Simple-Jekyll-Search)
there is a `search.liquid` file that will create a list of all the site posts, pages and portfolios.
Then there's a script displaying the formatted results in the _search page_.

Then there's a `search.js` displaying the formatted results in the "search" page.

The search page can be hidden with the `hide` option. You can remove the icon by removing `icon`:
To exclude contents from the search add the `exclude: true` option in the markdown header.
By default, all posts, pages, and collections are available in the search.
Hide the search page from the navigation bar with the `hide: true` option.
You can remove the icon by removing `icon`:

```yml

Expand Down
46 changes: 46 additions & 0 deletions _includes/default/search_input.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{% for post in site.posts %}
{
{% unless post.excluded %}
"title" : "{{ post.title | strip_newlines | escape }}",
"category" : "{{ post.category }}",
"tags" : "{{ post.tags | join: ', ' | prepend: " " }}",
"url" : "{{ post.url | relative_url }}",
"date" : "{{ post.date | date: "%B %-d, %Y" }}",
"excerpt" : {{ post.content | strip_html | strip_newlines | strip | escape | truncate: '250' | escape | jsonify }},
"content" : {{ post.content | strip_html | strip_newlines | strip | escape | jsonify }}
{% endunless %}
}{% unless forloop.last %},{% endunless %}
{% endfor %}
{% if site.pages.size > 0 %},{% endif %}
{% for page in site.pages %}
{
{% unless page.excluded or page.title == nil %}
"title" : "{{ page.title | strip_newlines | escape }}",
"category" : "{{ page.category }}",
"tags" : "{{ page.tags | join: ', ' | prepend: " " }}",
"url" : "{{ page.url | relative_url }}",
"date" : "{{ page.date | date: "%B %-d, %Y" | default: "N/A" }}",
"excerpt" : {{ page.content | strip_html | strip_newlines | strip | escape | truncate: '250' | escape | jsonify }},
"content" : {{ page.content | strip_html | strip_newlines | strip | escape | jsonify }}
{% endunless %}
}{% unless forloop.last %},{% endunless %}
{% endfor %}
{% if site.collections.size > 0 %},{% endif %}
{% for collection in site.collections %}
{% for page in site[collection.label] %}
{
{% if page.excluded or page.title != nil %}
"title" : "{{ page.title | strip_newlines | escape }}",
"category" : "{{ page.category }}",
"tags" : "{{ page.tags | join: ', ' | prepend: " " }}",
"url" : "{{ page.url | relative_url }}",
"date" : "{{ page.date | date: "%B %-d, %Y" | default: "N/A" }}",
"excerpt" : {{ page.content | strip_html | strip_newlines | strip | escape | truncate: '250' | jsonify }},
"content" : {{ page.content | strip_html | strip_newlines | strip | escape | jsonify }}
{% endif %}
}{% unless forloop.last %},{% endunless %}
{% endfor %}
{% unless forloop.last %},{% endunless %}
{% endfor %}
]
2 changes: 2 additions & 0 deletions _portfolio/hanoi.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ img: "assets/img/portfolio/toh.png"
date: September 2014
---

The tower of Hanoi...

![image]({{ page.img | relative_url }})

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam,
Expand Down
33 changes: 6 additions & 27 deletions assets/data/search.liquid
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
---
---
[
{% for post in site.posts %}
{
"title" : "{{ post.title | strip_newlines | escape }}",
"category" : "{{ post.category }}",
"tags" : "{{ post.tags | join: ', ' | prepend: " " }}",
"url" : "{{ post.url | relative_url }}",
"date" : "{{ post.date | date: "%B %-d, %Y" }}",
"excerpt" : {{ post.content | strip_html | truncate: '250' | escape | jsonify }},
"content" : {{ post.content | strip_html | escape | jsonify }}
} {% unless forloop.last %},{% endunless %}
{% endfor %}
{% if site.portfolio.size > 0 %},{% endif %}
{% for page in site.portfolio %}
{
{% if page.title != nil %}
"title" : "{{ page.title | strip_newlines | escape }}",
"category" : "{{ page.category }}",
"tags" : "{{ page.tags | join: ', ' | prepend: " " }}",
"url" : "{{ page.url | relative_url }}",
"date" : "{{ page.date | date: "%B %-d, %Y" }}",
"excerpt" : {{ page.content | strip_html | truncate: '250' | jsonify }},
"content" : {{ page.content | strip_html | escape | jsonify }}
{% endif %}
} {% unless forloop.last %},{% endunless %}
{% endfor %}
]
{% comment %}
The json is created in search_input.liquid and included here to be compresed
{% endcomment %}
{% capture _search %}{% include default/search_input.liquid %}{% endcapture %}
{% assign emptyField = '{ },' %}
{{ _search | split: " " | join: " " | remove: emptyField }}
1 change: 1 addition & 0 deletions pages/404.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ layout: page
title: "404 Page not found"
permalink: /404.html
hide: true
excluded: true
---

Sorry, the requested page wasn't found on the server.
1 change: 1 addition & 0 deletions pages/categories.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ layout: categories
title: Categories
permalink: /categories/
hide: true
excluded: true
---
3 changes: 2 additions & 1 deletion pages/gallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ title: Gallery
subtitle: From the pexels folder
permalink: /gallery/
gallery_path: "assets/img/pexels"
excluded: true
position: 3
tags: [Page]
---

This is a photo gallery made from the static files in the `assets/img/pexels` folder.
I wanted to create automatically a simple gallery from a folder without having to create a markdown page as you would for the portfolio.
I wanted to automatically create a simple gallery from a folder without having to create a markdown page as you would for the portfolio.


{% include gallery.html gallery_path=page.gallery_path %}
1 change: 1 addition & 0 deletions pages/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ permalink: /search/
subtitle: "What are you looking for?"
feature-img: "assets/img/pexels/search-map.jpeg"
icon: "fa-search"
excluded: true
position: 5
---

0 comments on commit 7c6f81f

Please sign in to comment.