Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve search file #418

Merged
merged 6 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link

@EverettYou EverettYou Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend reverting this commit. This makes all the hidden pages not searchable. But they are just hidden from the navigation bar, not meant to be hidden from the search. Or maybe introduce another page property like searchable to indicate if a page should appear in the search.

Copy link
Owner Author

@sylhare sylhare Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed that was the intent, hidden would mean both from search and navigation bar. Let me think for a solution to have a page hidden from the navigation bar but shown in the search 🤔 (I'd rather have a property to hide it from the search result then)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EverettYou I added an excluded option, instead of using hide. Should be better 👍

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
---
Loading