Skip to content

Commit

Permalink
Changes to make the search work
Browse files Browse the repository at this point in the history
  • Loading branch information
lab3 committed Nov 25, 2023
1 parent 6bfe50f commit 8780e0c
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 0 deletions.
90 changes: 90 additions & 0 deletions _data/locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# The layout text of site

# ----- Commons label -----

layout:
post: Post
category: Category
tag: Tag

# The tabs of sidebar
tabs:
# format: <filename_without_extension>: <value>
home: Home
categories: Categories
tags: Tags
archives: Archives
about: About

# the text displayed in the search bar & search results
search:
hint: search
cancel: Cancel
no_results: Oops! No results found.

panel:
lastmod: Recently Updated
trending_tags: Trending Tags
toc: Contents

copyright:
# Shown at the bottom of the post
license:
template: All Rights Reserved
name: All Rights Reserved
link: https://en.wikipedia.org/wiki/All_rights_reserved

# Displayed in the footer
brief: All rights reserved.
verbose: >-
Except where otherwise noted all rights are reserved and this content may not be reused without explicit permission from the author.
meta: Using the :THEME theme for :PLATFORM.

not_found:
statment: Sorry, we've misplaced that URL or it's pointing to something that doesn't exist.

notification:
update_found: A new version of content is available.
update: Update

# ----- Posts related labels -----

post:
written_by: By
posted: Posted
updated: Updated
words: words
pageview_measure: views
read_time:
unit: min
prompt: read
relate_posts: Further Reading
share: Share
button:
next: Newer
previous: Older
copy_code:
succeed: Copied!
share_link:
title: Copy link
succeed: Link copied successfully!

# Date time format.
# See: <http://strftime.net/>, <https://day.js.org/docs/en/display/format>
df:
post:
strftime: "%b %e, %Y"
dayjs: "ll"
archives:
strftime: "%b"
dayjs: "MMM"

# categories page
categories:
category_measure:
singular: category
plural: categories
post_measure:
singular: post
plural: posts
46 changes: 46 additions & 0 deletions _includes/search-loader.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!--
Jekyll Simple Search loader
See: <https://github.com/christian-fei/Simple-Jekyll-Search>
-->

{% capture result_elem %}
<div class="pl-1 pr-1 pl-sm-2 pr-sm-2 pl-lg-4 pr-lg-4 pl-xl-0 pr-xl-0">
<a href="{url}" target="_self">{title}</a>
<div class="post-meta d-flex flex-column flex-sm-row text-muted mt-1 mb-1">
<a href="{url}" target="_self"><img src="{imgUrl}" style="width: 75px; image-rendering: pixelated;" title="{title}"></a>
</div>
<p>{content}</p>
</div>
{% endcapture %}

{% capture not_found %}<p class="mt-5">{{ site.data.locales[site.lang].search.no_results }}</p>{% endcapture %}

<script src="{{ site.data.assets[origin].search.js | relative_url }}"></script>

<script>
/* Note: dependent library will be loaded in `js-selector.html` */
SimpleJekyllSearch({
searchInput: document.getElementById('search-input'),
resultsContainer: document.getElementById('search-results'),
json: '{{ '/assets/js/data/search.json' | relative_url }}',
searchResultTemplate: '{{ result_elem | strip_newlines }}',
noResultsText: '{{ not_found }}',
templateMiddleware: function(prop, value, template) {
if (prop === 'categories') {
if (value === '') {
return `${value}`;
} else {
return `<div class="me-sm-4"><i class="far fa-folder fa-fw"></i>${value}</div>`;
}
}

if (prop === 'tags') {
if (value === '') {
return `${value}`;
} else {
return `<div><i class="fa fa-tag fa-fw"></i>${value}</div>`;
}
}
}
});
</script>
6 changes: 6 additions & 0 deletions _includes/search-results.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!-- The Search results -->
<div id="search-result-wrapper" class="d-flex justify-content-center unloaded">
<div class="col-11 content">
<div id="search-results" class="d-flex flex-wrap justify-content-center text-muted mt-3"></div>
</div>
</div>
55 changes: 55 additions & 0 deletions assets/js/data/search.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
layout: compress
swcache: true
---

[
{% for post in site.data.block_data %}
{% assign desc = site.data.block_descriptions[post.id].description %}
{
"title": {{ post.name | jsonify }},
"url": {{ './items/?s=' | append: post.id | append: '#' | append: post.id | relative_url | jsonify }},
"imgUrl": {{ post.path | relative_url | jsonify }},
"content": {{ desc | append: ' ' | jsonify }}
},`
{% endfor %}

{% for post in site.data.item_data %}
{% assign desc = site.data.item_descriptions[post.id].description %}
{
"title": {{ post.name | jsonify }},
"url": {{ './items/?s=' | append: post.id | append: '#' | append: post.id | relative_url | jsonify }},
"imgUrl": {{ post.path | relative_url | jsonify }},
"content": {{ desc | append: ' ' | jsonify }}
},
{% endfor %}

{% for post in site.data.spellbook_data %}
{% assign desc = site.data.spellbook_descriptions[post.id].description %}
{
"title": {{ post.name | jsonify }},
"url": {{ './spellbooks/?s=' | append: post.id | append: '#' | append: post.id | relative_url | jsonify }},
"imgUrl": {{ post.path | relative_url | jsonify }},
"content": {{ post.tooltip | append: ' ' | jsonify }}
},
{% endfor %}

{% for post in site.data.spell_data %}
{
"title": {{ post.name | jsonify }},
"url": {{ './spells/?s=' | append: post.name | append: '#' | append: post.name | relative_url | jsonify }},
"imgUrl": {{ post.icon | relative_url | jsonify }},
"content": {{ post.description | jsonify }}
},
{% endfor %}

{% for post in site.data.armor_data %}
{
"title": {{ post.name | jsonify }},
"url": {{ './armor/?s=' | append: post.id | append: '#' | append: post.id | relative_url | jsonify }},
"imgUrl": {{ post.path | relative_url | jsonify }},
"content": {{ post.tooltip | jsonify }}
}{% unless forloop.last %},{% endunless %}
{% endfor %}

]

0 comments on commit 8780e0c

Please sign in to comment.