55 lines
2.1 KiB
JavaScript
55 lines
2.1 KiB
JavaScript
document.addEventListener("DOMContentLoaded", function () {
|
||
let lastScrollY = window.scrollY;
|
||
const header = document.querySelector("header");
|
||
|
||
window.addEventListener("scroll", () => {
|
||
if (window.scrollY > lastScrollY) {
|
||
// Scrolling down
|
||
header.classList.add("hide-header");
|
||
} else {
|
||
// Scrolling up
|
||
header.classList.remove("hide-header");
|
||
}
|
||
lastScrollY = window.scrollY;
|
||
});
|
||
|
||
// Dynamically load posts on the home page
|
||
if (document.getElementById("post-list")) {
|
||
const posts = [
|
||
{ title: "Home is a Moving Target.", date: "Sep 18, 2025", excerpt: "The first thing I notice when I land in Taipei isn’t the humidity, it’s the English.", file: "post4.md" },
|
||
{ title: "Hemming", date: "Jul 28, 2025", excerpt: "Everything I create lives on screens", file: "post3.md" },
|
||
{ title: "Scars, Sadness, and Soulmates", date: "Jan 26, 2025", excerpt: "Healing isn't a prerequisite for love, being human is.", file: "post2.md" },
|
||
{ title: "Meaningful Action", date: "Jan 23, 2025", excerpt: "wow this is barely comprehensible", file: "post1.md" },
|
||
];
|
||
|
||
const postList = document.getElementById("post-list");
|
||
posts.forEach(post => {
|
||
const postElement = document.createElement("div");
|
||
postElement.classList.add("post-card");
|
||
postElement.innerHTML = `
|
||
<h4>${post.title}</h4>
|
||
<h3>${post.date}</h3>
|
||
<p>${post.excerpt}</p>
|
||
`;
|
||
|
||
postElement.addEventListener("click", () => {
|
||
window.location.href = `post.html?file=posts/${post.file}`;
|
||
});
|
||
|
||
postList.appendChild(postElement);
|
||
});
|
||
}
|
||
|
||
// Load specific post content on the post page
|
||
const urlParams = new URLSearchParams(window.location.search);
|
||
const postFile = urlParams.get("file");
|
||
if (postFile) {
|
||
fetch(postFile)
|
||
.then(response => response.text())
|
||
.then(text => {
|
||
document.getElementById("post").innerHTML = marked.parse(text);
|
||
});
|
||
}
|
||
});
|
||
|