.
This commit is contained in:
parent
6623ee03f6
commit
44c8324063
120 changed files with 22842 additions and 4673 deletions
37
public/js/script.js
Normal file
37
public/js/script.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// Simple Search
|
||||
const searchInput = document.getElementById('search');
|
||||
const results = document.getElementById('results');
|
||||
|
||||
if (searchInput && results) {
|
||||
const posts = [
|
||||
{{ range $index, $page := where site.RegularPages "Type" "in" site.Params.mainSections }}
|
||||
{{ if $index }},{{ end }}
|
||||
{
|
||||
title: "{{ $page.Title | safeJS }}",
|
||||
url: "{{ $page.RelPermalink }}",
|
||||
content: {{ $page.Plain | safeJS | jsonify }}
|
||||
}
|
||||
{{ end }}
|
||||
];
|
||||
|
||||
searchInput.addEventListener('input', (e) => {
|
||||
const query = e.target.value.toLowerCase();
|
||||
results.innerHTML = '';
|
||||
|
||||
if (query.length < 2) return;
|
||||
|
||||
const matches = posts.filter(post => {
|
||||
return post.title.toLowerCase().includes(query) ||
|
||||
post.content.toLowerCase().includes(query);
|
||||
});
|
||||
|
||||
matches.forEach(post => {
|
||||
const li = document.createElement('li');
|
||||
const a = document.createElement('a');
|
||||
a.href = post.url;
|
||||
a.textContent = post.title;
|
||||
li.appendChild(a);
|
||||
results.appendChild(li);
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue