Using a headless CMS — Goeboek 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 Goeboek.
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 and the sitemap read them through src/lib/content.ts: getProperties / getProperty / getPropertiesByType /
getPropertiesByLocation / getPropertiesByCategory / getPropertiesByAgent, getAgents / getAgent,
getLocations / getLocation, getCategories / getCategory, getTestimonials and getPosts / getPost. Each is
wrapped in React’s cache, so a page and its metadata asking for the same entry fetch it once. Rewrite them to fetch
from the CMS and return the types in src/content/types.ts; pages, sections and components stay unchanged. Mirror the
types in the CMS:
| Collection | In the demo | Fields |
|---|---|---|
Property (properties.ts) |
21 | slug, title, propertyId, for (rent or sell), category, agent and location (slugs), address, price (number), duration (text, “/month” or empty), image, gallery (images), excerpt, description (rich text), features (rich text), video (YouTube link, optional), details (size, bedrooms, bathrooms, floor, additionalSpace, furnishing, ceilingHeight, constructionYear, renovation), utility (heating, airCondition, fireplace, elevator, ventilation, intercom, windowType, cableTv, wifi) |
Agent (agents.ts) |
4 | slug, name, image (or null), address, phone, mobile, whatsapp, email, bio |
Place (locations.ts) |
6 | slug, name |
Place (categories.ts) |
5 | slug, name |
Post (posts.ts) |
12 | slug, title, category (text), date, author, image, excerpt, body (rich text) |
Testimonial (testimonials.ts) |
12 | slug, name, photo, rating (number or null), quote |
An image is an object, { src, alt }: the path or address and its description. Dates are ISO dates ("2024-05-16");
size is in square metres and ceilingHeight in metres.
- References. A property’s
category,agentandlocationhold theslugof an item in those collections. In a CMS, make them reference fields and map each to its slug. When a slug matches nothing, the cards fall back to the defaults “Uncategory”, “No Name” and “No Location” (src/lib/to-ui.ts; the last item of each demo collection — they list nothing and arenoindex). A post’scategoryis plain text, not a reference: the related posts match it exactly, so keep one spelling per category (a select field in the CMS). - Order. Every collection keeps the order it arrives in: give the collections an order field in the CMS and sort by
it in your query. The order matters for properties: Home’s hero slideshow is the first 4 (
hero.slideshow.count), Featured Properties the 5th to the 10th (featured.offset4,count6, insrc/content/pages/home.ts), and the post pages’ “Latest Property” the first. There is no “featured” field.getPosts()sorts the posts bydate, newest first, whatever order the CMS returns; Home shows the 4 newest, a post’s “Recent posts” the 3 newest. Home’s hero shows the first 5 testimonials. - Related items. On a property page, “More in
” lists the first two other properties of the same location ( more.countinproperty.ts), and “Related properties” the other properties of the same category and type (for): three from 1200 px, four below (related.count). A post’s related posts are up to four others of the same category, newest first (related.countinpost.ts). The open item is left out by its title (properties) or slug (posts). - Listings.
/propertypages every property six at a time (filters.pageSizeinsections.ts); the Type, Location, Category and Agent pages show all theirs at once. The filter lists every location, category and agent but the three defaults. - Every property, agent, location, category and post has a page.
/property/<slug>,/agent/<slug>,/location/<slug>,/property-category/<slug>and/blog/<slug>are built from the collections, and the sitemap reads the same functions.
Rich text
Section titled “Rich text”A property’s description and features and a post’s body are blocks, not HTML:
{ type: "paragraph", text: "…" } // **bold** and `code` inline{ type: "heading", level: 3, text: "…" } // levels 2–6{ type: "list", ordered: false, items: ["…", "…"] } // an item is a string …{ type: "list", ordered: true, items: [{ text: "…", ordered: false, items: ["…"] }] } // … a string with a nested list …{ type: "list", ordered: true, items: [{ text: "…", blocks: [/* paragraphs and lists */] }] } // … or a string followed by blocksThe demo uses paragraphs only, with bold words (the property’s name at the start of its texts), and
RichTextBlock in src/content/types.ts allows paragraphs only. The RichText component draws headings, lists and
inline code too: to accept them from the CMS, use the RichTextBlock type exported by @/design-system in
types.ts. There are no italics, links or images inside the text. Convert your CMS’s rich text to these blocks in your
mapping function, bold as **…** and code as `…` (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 property’s image (1.536 : 1 on the cards; about 16 : 9 and up to 940 px wide on its page; up to 680 px tall in Home’s slideshow) |
1400 × 788 or larger |
A property’s gallery (16 : 9 tiles, two per row; the card’s frame on hover) |
1200 wide |
An agent’s image (round, 82 px) |
400 × 504 |
A post’s image (0.84 : 1 on the cards; 1.46 : 1 and up to 940 px wide on its page) |
1400 wide |
A testimonial’s photo (24 px round) |
100 × 100 |
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 layout needs
no width and height from the CMS.