Files
blogs/script.js
rchou 851c773295
All checks were successful
Deploy on push / deploy (push) Has been skipped
post 4
2025-09-19 03:05:21 -07:00

55 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 isnt the humidity, its 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);
});
}
});