Using a headless CMS — Kendi Next.js
Connecting a headless CMS works the same for every Next.js template sold on Framebrick, so this page lists only what is specific to Kendi.
The approach, rich text, images, keeping pages fresh, and step-by-step guides for Sanity, Payload, Strapi and Directus are in Use a headless CMS with a Next.js template.
Collections
Section titled “Collections”Pages read them through src/lib/content.ts: getPosts / getPost, getLatestPosts, getEditorsPicks,
getTrendingPosts, getPostsBySlug, getPostsByCategory, getPostsByAuthor, getRelatedPosts, getCategories /
getCategory, getAuthors / getAuthor, getLegalPages / getLegalPage, getTeam and getInstagram. Mirror
src/content/types.ts in the CMS:
| Collection | In the demo | Fields |
|---|---|---|
Post |
64 | slug, title, excerpt, category (a Category slug), author (an Author slug), date, editorsPick (yes/no), trending (yes/no), image, body (rich text) |
Category |
8 | slug, name, description, image |
Author |
6 | slug, name, role, bio, avatar, socials (a list of { name: "x" | "instagram" | "facebook", href }) |
LegalPage |
2 | slug, title, updated, body (rich text) |
TeamMember (About) |
6 | slug, name, role, bio, photo |
InstagramItem (the footer’s grid) |
4 | image, href |
Every image is { src, alt }.
- Relations. They are by slug, and the mapping in
src/lib/to-ui.tsresolves them: a post’scategorygives its pill, its breadcrumb and its category page; itsauthorthe name and photo of the meta line and the author page. A slug with no item is shown as the slug itself, so a reference field that returns slugs is the simplest mapping. - Order.
getPostssorts bydate, newest first, whatever order the CMS returns (posts of the same day keep the CMS’s order). Every list of posts derives from it: Home’s slideshow (the five newest), the list beside it (5th to 7th), Latest posts (8th to 11th), the sidebar’s Spotlight (the four newest), the newsletter band (the three newest), Related Post (the six newest others of the category), a category’s and an author’s page. Categories, authors, the team and the grid keep the CMS’s order: give them a sort field. The Categories menu and the footer show the first five categories, Explore Topics the first six. - Flags. Editor’s pick shows the first five posts with
editorsPick, Trending the first six withtrending(also the Categories menu’s Spotlight, the first four); model both as yes/no fields. - Inspiration is the newest post of each category, in category order, computed by
getNewestPerCategoryinsrc/lib/content.ts. It followsgetPosts, so it keeps working with a CMS and needs no list of its own. getPost,getRelatedPostsand the other helpers filter the full list, so they keep working whengetPostsfetches from the CMS. The sitemap reads the same functions.- The footer’s legal links (
footer.legalLinksinsrc/content/site.ts) and the newsletter’s consent line are typed, not read from the collection.
Rich text
Section titled “Rich text”Post bodies and legal texts are blocks, not HTML:
{ type: "heading", level: 2 | 3 | 4 | 5 | 6, text: "…" } // the rich-text heading style; a post draws level 3 smaller{ type: "paragraph", text: "…" } // **bold**, _italic_, [text](href){ type: "list", ordered: boolean, items: ["…", "…"] } // each item is a line of text with the same marksThe demo’s posts use level-2 and level-3 headings and paragraphs with bold and italic runs; the legal texts use
level-3 headings, paragraphs and bulleted lists. There are no tables, images or quotes inside the text. Convert your
CMS’s rich text to these blocks in your mapping function, bold as **…**, italics as _…_ and links as
text (how).
Images
Section titled “Images”Every photo sits in a frame and is cropped to fill it, so a photo of other proportions works; upload images at least as large as the layout uses:
| Image | Size |
|---|---|
A post’s image (cards, the hero slides, the cover, the share image) |
1600 × 1067 (3 : 2) |
A category’s image |
400 × 400 |
An author’s avatar |
400 × 400 |
A team member’s photo |
400 × 600 |
A grid photo (InstagramItem) |
400 × 400 |
Photos go through next/image, which needs the CMS’s host in images.remotePatterns of next.config.ts
(Images). Every photo fills a frame of its own shape, so the
components need no width or height from the CMS.