This commit is contained in:
ryfrd 2025-08-14 15:16:21 +01:00
parent c4dcb6e38b
commit 531029a18f
129 changed files with 7765 additions and 6938 deletions

46
public/js/search.js Normal file
View file

@ -0,0 +1,46 @@
document.addEventListener("DOMContentLoaded", function () {
let index = [];
// Load JSON index
fetch("/index.json")
.then((res) => res.json())
.then((data) => {
index = data;
console.log("Index loaded:", index.length, "posts");
})
.catch((err) => console.error("Error loading index.json", err));
const searchInput = document.getElementById("search");
const resultsList = document.getElementById("results");
function runSearch() {
const query = searchInput.value.trim().toLowerCase();
resultsList.innerHTML = "";
if (!query) return;
// filter out posts that don't match
const matches = index.filter(
(post) =>
post.title.toLowerCase().includes(query) ||
post.content.toLowerCase().includes(query),
);
if (matches.length === 0) {
resultsList.innerHTML = "<li>No results found.</li>";
return;
}
// Render matching posts
matches.forEach((post) => {
const li = document.createElement("li");
const link = document.createElement("a");
link.href = post.url;
link.textContent = post.title;
li.appendChild(link);
resultsList.appendChild(li);
});
}
searchInput.addEventListener("input", runSearch);
});

43
public/js/toggle.js Normal file
View file

@ -0,0 +1,43 @@
function toggleTheme() {
var stylesheet = document.getElementById('stylesheet');
if (stylesheet.getAttribute('href') === '/css/dark.css') {
// update stylesheet and store
stylesheet.setAttribute('href', '/css/light.css');
localStorage.setItem('stylesheet', '/css/light.css');
// update button emoji and store
button = document.getElementById('toggle-button').innerText = '🌚'
localStorage.setItem('button-emoji', '🌚');
} else {
// update stylesheet and store
stylesheet.setAttribute('href', '/css/dark.css');
localStorage.setItem('stylesheet', '/css/dark.css');
// update button emoji and store
button = document.getElementById('toggle-button').innerText = '🌞'
localStorage.setItem('button-emoji', '🌞');
}
}
window.addEventListener('load', function() {
// get stored style
var storedStyle = localStorage.getItem('stylesheet');
var stylesheet = document.getElementById('stylesheet');
// get stored emoji
var storedEmoji = localStorage.getItem('button-emoji');
var button = document.getElementById('toggle-button')
// set stored style it exists
if (storedStyle) {
stylesheet.setAttribute('href', storedStyle);
}
// set stored emoji it exists
if (storedEmoji) {
button.innerText = storedEmoji;
}
});