I have built a site using self-hosted headless Ghost as a backend and Eleventy as a static site frontend. I used the (official?) Eleventy Starter Ghost repo that is referenced in Ghosts’s own docs on building a site with Ghost + Eleventy.
I need help with how the eleventy.js
file, which accesses the Ghost Content API constructs the tag collection for Eleventy:
within:
config.addCollection("tags", async function(collection)
this snippet of code populates each tag with all the posts that have that tag as their primary_tag
// Attach posts to their respective tags
collection.map(async tag => {
const taggedPosts = posts.filter(post => {
return post.primary_tag && post.primary_tag.slug === tag.slug;
});
The full code is included and explained in the Jamstack Eleventy + Ghost doc page.
I would like some help to instead populate my Eleventy tag collection such that each tag item has every post with that tag attached to it (not just those with it as their primary_tag
. The javascript here is a bit too dense for me to follow and modify, and I’m not familiar enough with the Ghost Content API JS client in use. I’m hoping for some help and direction on how to change this.
I did quite a bit of searching on this, and there is a github issue with the same question on the eleventy-ghost-starter
repo that was closed by the maintainer who directed such inquiries to this forum. I hope this is the right place. This issue could belong in many different courts, the question is about Eleventy code technically, but I think because it’s about using Ghost in the officially-provided-by-Ghost documentation and starter it belongs here?
I think it would also be useful to others building a site with this stack, since I think it makes intuitive sense to have that collection generated from Ghost content when building a site like this. I’m not sure why primary_tag
is used here.
I had included more links in this topic, but because this is my first post I have to remove several.