Skip to content

Commit 885a1b9

Browse files
committed
Copied changes from hmpl/blog
1 parent d3441f7 commit 885a1b9

File tree

7 files changed

+71
-5
lines changed

7 files changed

+71
-5
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ gem "jekyll", "~> 4.3.3"
33
gem "minima", "~> 2.5.2"
44
group :jekyll_plugins do
55
gem "jekyll-feed", "~> 0.12"
6+
gem "jekyll-seo-tag"
67
end
78
platforms :mingw, :x64_mingw, :mswin, :jruby do
89
gem "tzinfo", ">= 1", "< 3"

_config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ author:
33
name: ""
44
email: ""
55
description: >
6-
HMPL - 🐜 Server-oriented customizable
6+
HMPL - 🐜 Server-oriented customizable
77
templating for JavaScript
88
theme: minima
99
plugins:
1010
- jekyll-feed
11+
- jekyll-seo-tag
1112
minima:
1213
social_links:
1314
- { platform: github, user_url: "https://github.com/hmpl-language/hmpl" }

_includes/header.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{%- assign page_paths = site.header_pages | default: default_paths -%}
55
{%- assign titles_size = site.pages | map: 'title' | join: '' | size -%}
66
<a class="site-title" rel="author" href="{{ "/" | relative_url }}">{{ site.title | escape }}</a>
7-
7+
88
<nav class="site-nav">
99
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
1010
<label for="nav-trigger">
@@ -14,10 +14,12 @@
1414
</svg>
1515
</span>
1616
</label>
17-
1817
<div class="trigger">
1918
<a class="page-link" href="https://hmpl-lang.dev">hmpl-lang.dev</a>
2019
</div>
20+
<label for="search-box"><input type="text" id="search-box" placeholder="Search...">
21+
<ul id="results"></ul>
22+
</label>
2123
</nav>
2224
</div>
2325
</header>

_layouts/base.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="{{ page.lang | default: site.lang | default: " en" }}">
33

44
{%- include head.html -%}
5-
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.11/clipboard.min.js"></script>
5+
<script src="https://unpkg.com/clipboard.js"></script>
66
<link rel="stylesheet" href="/css/style.css" />
77

88
<body>
@@ -50,6 +50,9 @@
5050
});
5151
</script>
5252

53+
<script src="https://unpkg.com/lunr.js"></script>
54+
<script src="/assets/search.js"></script>
55+
5356
</body>
5457

55-
</html>
58+
</html>

_layouts/json.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
layout: nil
3+
---
4+
[
5+
{% for post in site.posts %}
6+
{
7+
"title": "{{ post.title | escape | replace: '\u0000', '' }}",
8+
"url": "{{ post.url | relative_url }}",
9+
"datePublished": "{{ post.date | date_to_xmlschema }}",
10+
"dateModified": "{% if post.modified_date %}{{ post.modified_date | date_to_xmlschema }}{% else %}null{% endif %}",
11+
"author": [
12+
{% if post.author %}
13+
{% for author in post.author %}
14+
"{{ author | escape }}"{% if forloop.last == false %},{% endif %}
15+
{% endfor %}
16+
{% endif %}
17+
]
18+
}{% unless forloop.last %},{% endunless %}
19+
{% endfor %}
20+
]

assets/search.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
document.addEventListener("DOMContentLoaded", function () {
2+
const searchBox = document.getElementById("search-box");
3+
const resultsList = document.getElementById("results");
4+
5+
fetch("/search.json")
6+
.then((response) => response.json())
7+
.then((data) => {
8+
searchBox.addEventListener("input", function () {
9+
const query = this.value.toLowerCase();
10+
11+
if (query.trim() === "") {
12+
resultsList.style.display = "none";
13+
} else {
14+
resultsList.style.display = "block";
15+
const results = data.filter((post) => {
16+
const title = post.title ? post.title.toLowerCase() : "";
17+
return title.includes(query);
18+
});
19+
20+
// Display the filtered results
21+
resultsList.innerHTML = results
22+
.map(
23+
(post) => `
24+
<li>
25+
<a href="${post.url}">${post.title}</a>
26+
</li>`
27+
)
28+
.join("");
29+
}
30+
});
31+
})
32+
.catch((error) => {
33+
console.error("Error fetching search.json:", error);
34+
});
35+
});

search.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
layout: json
3+
permalink: /search.json
4+
---

0 commit comments

Comments
 (0)