Skip to content

Instantly share code, notes, and snippets.

@timbenniks
Created September 9, 2022 13:55
Show Gist options
  • Save timbenniks/3b47d63a49c04fcdf30bc9809b13e1e8 to your computer and use it in GitHub Desktop.
Save timbenniks/3b47d63a49c04fcdf30bc9809b13e1e8 to your computer and use it in GitHub Desktop.
Query Contentful items by tags with Uniform Enhancers
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