feat(home): hide unlisted posts from recent lists

This commit is contained in:
svemagie
2026-03-08 16:31:53 +01:00
parent 08cdbcea31
commit 13b223ce2a
8 changed files with 40 additions and 12 deletions

View File

@@ -7,15 +7,16 @@
{% set sectionConfig = section.config or {} %}
{% set maxItems = sectionConfig.maxItems or 5 %}
{% set showSummary = sectionConfig.showSummary if sectionConfig.showSummary is defined else true %}
{% set listedPosts = collections.posts | excludeUnlistedPosts %}
{% if collections.posts and collections.posts.length %}
{% if listedPosts and listedPosts.length %}
<section class="mb-8 sm:mb-12">
<h2 class="text-xl sm:text-2xl font-bold text-surface-900 dark:text-surface-100 mb-4 sm:mb-6">
{{ sectionConfig.title or "Recent Posts" }}
</h2>
<div class="space-y-4">
{% for post in collections.posts | head(maxItems) %}
{% for post in listedPosts | head(maxItems) %}
{# Detect post type from frontmatter properties #}
{% set likedUrl = post.data.likeOf or post.data.like_of %}
{% set bookmarkedUrl = post.data.bookmarkOf or post.data.bookmark_of %}

View File

@@ -1,11 +1,12 @@
{# Recent Posts Widget — type-aware, for blog/post sidebars #}
{# Uses collections.posts directly (all post types, not just recentPosts collection) #}
{% if collections.posts %}
{% set listedPosts = collections.posts | excludeUnlistedPosts %}
{% if listedPosts and listedPosts.length %}
<is-land on:visible>
<div class="widget">
<h3 class="widget-title">Recent Posts</h3>
<ul class="space-y-3">
{% for post in collections.posts | head(5) %}
{% for post in listedPosts | head(5) %}
{% if post.url != page.url %}
<li>
{% set _likedUrl = post.data.likeOf or post.data.like_of %}

View File

@@ -1,11 +1,12 @@
{# Recent Posts Widget (sidebar) - compact type-aware list #}
{% set recentPosts = recentPosts or collections.recentPosts %}
{% if recentPosts and recentPosts.length %}
{% set listedRecentPosts = recentPosts | excludeUnlistedPosts %}
{% if listedRecentPosts and listedRecentPosts.length %}
<is-land on:visible>
<div class="widget">
<h3 class="widget-title">Recent Posts</h3>
<ul class="space-y-3">
{% for post in recentPosts | head(5) %}
{% for post in listedRecentPosts | head(5) %}
<li>
{# Detect post type #}
{% set likedUrl = post.data.likeOf or post.data.like_of %}

View File

@@ -876,6 +876,17 @@ export default function (eleventyConfig) {
};
});
// Exclude unlisted posts from UI slices like homepage/sidebar recent-post lists.
eleventyConfig.addFilter("excludeUnlistedPosts", (posts) => {
if (!Array.isArray(posts)) return [];
return posts.filter((post) => {
const data = post?.data || {};
const rawVisibility = data.visibility ?? data.properties?.visibility;
const visibility = Array.isArray(rawVisibility) ? rawVisibility[0] : rawVisibility;
return String(visibility ?? "").toLowerCase() !== "unlisted";
});
});
// Helper: exclude drafts from collections
const isPublished = (item) => !item.data.draft;

View File

@@ -7,15 +7,16 @@
{% set sectionConfig = section.config or {} %}
{% set maxItems = sectionConfig.maxItems or 5 %}
{% set showSummary = sectionConfig.showSummary if sectionConfig.showSummary is defined else true %}
{% set listedPosts = collections.posts | excludeUnlistedPosts %}
{% if collections.posts and collections.posts.length %}
{% if listedPosts and listedPosts.length %}
<section class="mb-8 sm:mb-12">
<h2 class="text-xl sm:text-2xl font-bold text-surface-900 dark:text-surface-100 mb-4 sm:mb-6">
{{ sectionConfig.title or "Recent Posts" }}
</h2>
<div class="space-y-4">
{% for post in collections.posts | head(maxItems) %}
{% for post in listedPosts | head(maxItems) %}
{# Detect post type from frontmatter properties #}
{% set likedUrl = post.data.likeOf or post.data.like_of %}
{% set bookmarkedUrl = post.data.bookmarkOf or post.data.bookmark_of %}

View File

@@ -1,11 +1,12 @@
{# Recent Posts Widget — type-aware, for blog/post sidebars #}
{# Uses collections.posts directly (all post types, not just recentPosts collection) #}
{% if collections.posts %}
{% set listedPosts = collections.posts | excludeUnlistedPosts %}
{% if listedPosts and listedPosts.length %}
<is-land on:visible>
<div class="widget">
<h3 class="widget-title">Recent Posts</h3>
<ul class="space-y-3">
{% for post in collections.posts | head(5) %}
{% for post in listedPosts | head(5) %}
{% if post.url != page.url %}
<li>
{% set _likedUrl = post.data.likeOf or post.data.like_of %}

View File

@@ -1,11 +1,12 @@
{# Recent Posts Widget (sidebar) - compact type-aware list #}
{% set recentPosts = recentPosts or collections.recentPosts %}
{% if recentPosts and recentPosts.length %}
{% set listedRecentPosts = recentPosts | excludeUnlistedPosts %}
{% if listedRecentPosts and listedRecentPosts.length %}
<is-land on:visible>
<div class="widget">
<h3 class="widget-title">Recent Posts</h3>
<ul class="space-y-3">
{% for post in recentPosts | head(5) %}
{% for post in listedRecentPosts | head(5) %}
<li>
{# Detect post type #}
{% set likedUrl = post.data.likeOf or post.data.like_of %}

View File

@@ -818,6 +818,17 @@ export default function (eleventyConfig) {
};
});
// Exclude unlisted posts from UI slices like homepage/sidebar recent-post lists.
eleventyConfig.addFilter("excludeUnlistedPosts", (posts) => {
if (!Array.isArray(posts)) return [];
return posts.filter((post) => {
const data = post?.data || {};
const rawVisibility = data.visibility ?? data.properties?.visibility;
const visibility = Array.isArray(rawVisibility) ? rawVisibility[0] : rawVisibility;
return String(visibility ?? "").toLowerCase() !== "unlisted";
});
});
// Helper: exclude drafts from collections
const isPublished = (item) => !item.data.draft;