Created
September 9, 2022 13:55
-
-
Save timbenniks/3b47d63a49c04fcdf30bc9809b13e1e8 to your computer and use it in GitHub Desktop.
Query Contentful items by tags with Uniform Enhancers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { enhance, EnhancerBuilder } from "@uniformdev/canvas"; | |
import { createClient } from "contentful" | |
const contentfulTutorialListByTagsEnhancer = async ({ component }) => { | |
const { tags, limit } = component.parameters | |
const client = createClient({ | |
space: process.env.CONTENTFUL_SPACE_ID, | |
environment: process.env.CONTENTFUL_ENVIRONMENT, | |
accessToken: process.env.CONTENTFUL_ACCESS_TOKEN | |
}); | |
const tutorialListByTags = await client.getEntries({ | |
content_type: "turboTutorial", | |
"metadata.tags.sys.id[all]": tags.value, | |
order: "-sys.createdAt", | |
limit: limit.value, | |
}); | |
return tutorialListByTags.items | |
} | |
await enhance({ | |
composition, | |
enhancers: new EnhancerBuilder() | |
.component("tutoriallistbytags", (tutoriallistbytags) => | |
tutoriallistbytags.data("entry", contentfulTutorialListByTagsEnhancer) | |
), | |
context: {}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment