added post template
This commit is contained in:
53
script.js
Normal file
53
script.js
Normal file
@@ -0,0 +1,53 @@
|
||||
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: "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);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user