diff --git a/src/components/blog/BlogPost.astro b/src/components/blog/BlogPost.astro index d4d3886..837a594 100644 --- a/src/components/blog/BlogPost.astro +++ b/src/components/blog/BlogPost.astro @@ -1,5 +1,5 @@ --- -const { title, url, date, image, tags = [], languages = [] } = Astro.props; +const { title, url, date, image, tags = [], languages = [], hidden = true } = Astro.props; import Tag from "../ui/Tag.astro"; import ReadMore from "../ui/ReadMore.astro"; diff --git a/src/components/blog/LastPost.astro b/src/components/blog/LastPost.astro index 527c235..549d4c3 100644 --- a/src/components/blog/LastPost.astro +++ b/src/components/blog/LastPost.astro @@ -10,7 +10,7 @@ import DatePub from "./DatePub.astro"; const latestPost = allPosts.reduce((latest, current) => { const latestDate = new Date(latest.frontmatter.pubDate).getTime(); const currentDate = new Date(current.frontmatter.pubDate).getTime(); - return currentDate > latestDate ? current : latest; + return (currentDate > latestDate && !current.frontmatter.hidden) ? current : latest; }); const tags = [...new Set(latestPost.frontmatter.tags ?? [])]; diff --git a/src/components/blog/ListPosts.astro b/src/components/blog/ListPosts.astro index b051f5b..db2634f 100644 --- a/src/components/blog/ListPosts.astro +++ b/src/components/blog/ListPosts.astro @@ -22,6 +22,11 @@ allPosts.sort((a, b) => { // Filter posts according to props let postsToShow = allPosts; +postsToShow = postsToShow.filter((post) => { + if (post.frontmatter.hidden) return false; // Exclude hidden posts + return true; // Keep all other posts +}); + if (currentPostUrl) { // Exclude current post if its URL is provided postsToShow = postsToShow.filter((post) => { @@ -38,6 +43,13 @@ if (currentPostUrl) { // Limit to 4 posts if all is false if (!all) { + postsToShow = postsToShow.filter((post) => { + if (!post.url) return false; // If no URL, keep the post + // Normalize URLs for comparison + const normalizedPostUrl = post.url.replace(/\/$/, ""); // Remove trailing slash if exists + const normalizedCurrentUrl = currentPostUrl.replace(/\/$/, ""); // Remove trailing slash if exists + return normalizedPostUrl !== normalizedCurrentUrl; + }); postsToShow = postsToShow.slice(0, 4); } --- @@ -63,6 +75,7 @@ if (!all) { tags={post.frontmatter.tags} languages={post.frontmatter.languages} image={post.frontmatter.image} + hidden={post.frontmatter.hidden} /> )) } diff --git a/src/components/layout/NavigationArticles.astro b/src/components/layout/NavigationArticles.astro index 164afd2..22696b3 100644 --- a/src/components/layout/NavigationArticles.astro +++ b/src/components/layout/NavigationArticles.astro @@ -5,6 +5,7 @@ const allPosts = await Astro.glob("../../pages/blog/posts/*.md"); // Ensure posts have a date before sorting them const sortedPosts = allPosts .filter(post => post.frontmatter.pubDate) + .filter(post => !post.frontmatter.hidden) // Exclude hidden posts .sort((a, b) => new Date(b.frontmatter.pubDate).getTime() - new Date(a.frontmatter.pubDate).getTime()); const currentSlug = Astro.url.pathname.split("/").filter(Boolean).pop(); @@ -13,8 +14,6 @@ const currentIndex = sortedPosts.findIndex((post) => ); const nextPost = currentIndex > 0 ? sortedPosts[currentIndex - 1] : null; const prevPost = currentIndex < sortedPosts.length - 1 ? sortedPosts[currentIndex + 1] : null; - -console.log({ prevPost, nextPost }); ---