fix: normalize category/tags arrays in isListed and excludeWhereNotes to prevent .map errors
This commit is contained in:
@@ -22,6 +22,15 @@
|
|||||||
|
|
||||||
<ul class="post-list">
|
<ul class="post-list">
|
||||||
{% for post in listedPosts | head(maxItems) %}
|
{% for post in listedPosts | head(maxItems) %}
|
||||||
|
{% set rawVisibility = post.data.visibility or post.data.properties.visibility %}
|
||||||
|
{% set visibility = (rawVisibility is array) ? rawVisibility[0] : rawVisibility %}
|
||||||
|
{% set categories = post.data.category is string ? [post.data.category] : post.data.category or [] %}
|
||||||
|
{% set tags = post.data.tags is string ? [post.data.tags] : post.data.tags or [] %}
|
||||||
|
{% set allTags = (categories + tags) | map('lower') %}
|
||||||
|
{% if visibility == 'private' or allTags.includes('where') or allTags.includes('loc') %}
|
||||||
|
{# Skip private and where/Loc posts #}
|
||||||
|
{% continue %}
|
||||||
|
{% endif %}
|
||||||
{# Detect post type from frontmatter properties #}
|
{# Detect post type from frontmatter properties #}
|
||||||
{% set likedUrl = post.data.likeOf or post.data.like_of %}
|
{% set likedUrl = post.data.likeOf or post.data.like_of %}
|
||||||
{% set bookmarkedUrl = post.data.bookmarkOf or post.data.bookmark_of %}
|
{% set bookmarkedUrl = post.data.bookmarkOf or post.data.bookmark_of %}
|
||||||
|
|||||||
+7
-2
@@ -918,7 +918,10 @@ export default function (eleventyConfig) {
|
|||||||
const data = item?.data || {};
|
const data = item?.data || {};
|
||||||
const rawVisibility = data.visibility ?? data.properties?.visibility;
|
const rawVisibility = data.visibility ?? data.properties?.visibility;
|
||||||
const visibility = Array.isArray(rawVisibility) ? rawVisibility[0] : rawVisibility;
|
const visibility = Array.isArray(rawVisibility) ? rawVisibility[0] : rawVisibility;
|
||||||
const tags = (data.category || data.tags || []).map(t => typeof t === 'string' ? t.toLowerCase() : '');
|
// Normalize category and tags to arrays
|
||||||
|
const categories = Array.isArray(data.category) ? data.category : (data.category ? [data.category] : []);
|
||||||
|
const tagsArr = Array.isArray(data.tags) ? data.tags : (data.tags ? [data.tags] : []);
|
||||||
|
const tags = [...categories, ...tagsArr].map(t => typeof t === 'string' ? t.toLowerCase() : '');
|
||||||
// Exclude unlisted, private, and where/Loc notes
|
// Exclude unlisted, private, and where/Loc notes
|
||||||
if (["unlisted", "private"].includes(String(visibility ?? "").toLowerCase())) return false;
|
if (["unlisted", "private"].includes(String(visibility ?? "").toLowerCase())) return false;
|
||||||
if (tags.includes("where") || tags.includes("loc")) return false;
|
if (tags.includes("where") || tags.includes("loc")) return false;
|
||||||
@@ -930,7 +933,9 @@ export default function (eleventyConfig) {
|
|||||||
if (!Array.isArray(posts)) return [];
|
if (!Array.isArray(posts)) return [];
|
||||||
return posts.filter(item => {
|
return posts.filter(item => {
|
||||||
const data = item?.data || {};
|
const data = item?.data || {};
|
||||||
const tags = (data.category || data.tags || []).map(t => typeof t === 'string' ? t.toLowerCase() : '');
|
const categories = Array.isArray(data.category) ? data.category : (data.category ? [data.category] : []);
|
||||||
|
const tagsArr = Array.isArray(data.tags) ? data.tags : (data.tags ? [data.tags] : []);
|
||||||
|
const tags = [...categories, ...tagsArr].map(t => typeof t === 'string' ? t.toLowerCase() : '');
|
||||||
return !tags.includes("where") && !tags.includes("loc");
|
return !tags.includes("where") && !tags.includes("loc");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user