···11+document.addEventListener("DOMContentLoaded", function() {
22+ // Set up an observer to watch for new posts being added to the DOM
33+ const postContainer = document.querySelector('post-container');
44+55+ if (!postContainer) {
66+ console.warn("Post container not found");
77+ return;
88+ }
99+1010+ // Function to add transition classes to posts
1111+ function setupPostTransitions() {
1212+ // Get all posts that don't have the transition class yet
1313+ const posts = document.querySelectorAll('.post:not(.has-transition)');
1414+1515+ posts.forEach((post, index) => {
1616+ // Mark this post as having transitions
1717+ post.classList.add('has-transition', 'post-transition');
1818+1919+ // Set initial state (invisible)
2020+ post.style.opacity = '0';
2121+ post.style.transform = 'translateY(20px)';
2222+2323+ // Stagger the appearance of posts
2424+ setTimeout(() => {
2525+ post.style.opacity = '1';
2626+ post.style.transform = 'translateY(0)';
2727+ }, 100 * index); // Stagger each post by 100ms
2828+ });
2929+ }
3030+3131+ // Initial setup for any posts that are already in the DOM
3232+ setupPostTransitions();
3333+3434+ // Watch for changes in the post container (new posts being added)
3535+ const observer = new MutationObserver((mutations) => {
3636+ mutations.forEach((mutation) => {
3737+ if (mutation.addedNodes.length > 0) {
3838+ setupPostTransitions();
3939+ }
4040+ });
4141+ });
4242+4343+ // Start observing the post container for added posts
4444+ observer.observe(postContainer, { childList: true, subtree: true });
4545+4646+ // Handle page navigation (when the user navigates between pages)
4747+ window.addEventListener('hashchange', function() {
4848+ // Fade out all existing posts
4949+ const posts = document.querySelectorAll('.post');
5050+ posts.forEach((post, index) => {
5151+ post.style.opacity = '0';
5252+ post.style.transform = 'translateY(20px)';
5353+ });
5454+5555+ // After posts fade out, new ones will be loaded and fade in due to the observer
5656+ setTimeout(setupPostTransitions, 400); // Wait for fade out to complete
5757+ });
5858+5959+ // Handle theme changes to reapply transitions
6060+ const themeToggle = document.getElementById('theme-toggle');
6161+ if (themeToggle) {
6262+ themeToggle.addEventListener('click', function() {
6363+ // Brief delay to allow theme change to process
6464+ setTimeout(setupPostTransitions, 100);
6565+ });
6666+ }
6767+});