feat(home): hide unlisted posts from recent lists
This commit is contained in:
@@ -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 %}
|
||||
|
||||
@@ -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 %}
|
||||
|
||||
@@ -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 %}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 %}
|
||||
|
||||
@@ -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 %}
|
||||
|
||||
@@ -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 %}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user