Instantly share code, notes, and snippets.
👨💻
jam stackin'
Front end web developer & designer.
-
Prismic
- Kalmar, Sweden
- https://samuelhorn.com
- @pixelcrook
samuelhorn
/ relatedposts.tsx
Last active
October 24, 2023 08:50
How to fetch content relationships in a slice
This file contains 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 { Heading } from "@/components/ui"; | |
import { Content, isFilled } from "@prismicio/client"; | |
import { BlogPostCard } from "@/components/blog"; | |
import { createClient } from "@/prismicio"; | |
const RelatedPosts = async ({ slice }) => { | |
const client = createClient(); | |
// Return ids of related blog posts | |
const blogIds: string[] = slice.items.map((item) => { |
samuelhorn
/ menu-items-no-slicezone.tsx
Last active
December 6, 2023 08:43
Menu items as Slices without SliceZone, as used in Prismic top level menu
This file contains 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
<ul className="flex flex-col lg:items-center lg:flex-row lg:justify-center"> | |
{layout.data.slices1.map((item, index) => { | |
if (item.variation === "default") { | |
return ( | |
<MenuItem | |
key={index} | |
slice={item} | |
/> | |
); | |
} else { |
samuelhorn
/ menu-items-slicezone.tsx
Last active
December 6, 2023 08:45
Menu items rendered in SliceZone as in Prismic's sub menu within a <MenuItemWithSubmenu />
This file contains 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
<div className="px-0 container lg:px-8 flex flex-col lg:flex-row"> | |
<div | |
className="flex flex-col lg:w-[26.6666666667%] lg:py-12 gap-3 my-6 lg:my-0" | |
> | |
<SliceZone | |
slices="{slice.primary.sub_menu.data.slices}" | |
components="{components}" | |
/> | |
</div> | |
<ColumnSeparator /> |
OlderNewer