feat: add protected fields to comments and enhance comments aggregation logic

This commit is contained in:
2026-05-17 15:23:48 +00:00
parent 349fb9b2da
commit b0af8ba329
3 changed files with 16 additions and 6 deletions
+12 -5
View File
@@ -24,6 +24,13 @@
const CONTENT_MEDIA_LOOKUP = ["blocks.heroImage.image:medialib", "blocks.image:medialib"].join(",")
const NAVIGATION_CONTENT_LOOKUP = "elements.page:content"
const CONTENT_COMMENTS_AGGREGATE = {
collection: "comments",
foreignField: "contentId",
op: "count",
filter: { active: true },
as: "commentsCount",
}
let { url = "" }: { url?: string } = $props()
@@ -163,13 +170,13 @@
filter: { type: "header", language: lang },
sort: "sort",
limit: 1,
lookup: NAVIGATION_CONTENT_LOOKUP
lookup: NAVIGATION_CONTENT_LOOKUP,
}),
getCachedEntries<"navigation">("navigation", {
filter: { type: "footer", language: lang },
sort: "sort",
limit: 1,
lookup: NAVIGATION_CONTENT_LOOKUP
lookup: NAVIGATION_CONTENT_LOOKUP,
}),
])
headerNav = headerEntries[0] || null
@@ -180,8 +187,8 @@
filter: { lang, path: routePath, active: true },
sort: "sort",
limit: 1,
aggregate: "comments:contentId:count",
lookup: CONTENT_MEDIA_LOOKUP
aggregate: CONTENT_COMMENTS_AGGREGATE,
lookup: CONTENT_MEDIA_LOOKUP,
})
if (contentEntries.length > 0) {
@@ -195,7 +202,7 @@
try {
comments = await getCachedEntries("comments", {
filter: { active: true, contentId: contentEntry.id as string },
sort: "sort"
sort: "sort",
})
} catch (e) {
console.error("Failed to load comments", e)