Skip to content
Sign inJoin waitlist

Using a headless CMS — Goeboek Astro

Connecting a headless CMS works the same for every Astro template sold on Framebrick, so this page lists only what is specific to Goeboek.

Loaders and schemas, rich text, images, rebuilding on publish, and step-by-step guides for Sanity, Payload, Strapi and Directus are in Use a headless CMS with an Astro template.

src/content.config.ts defines them (each loads a JSON file of src/content/collections/), src/content/schemas.ts checks every entry when the site builds, and pages read them through src/lib/content.ts: getProperties / getProperty / getPropertiesByType / getPropertiesByLocation / getPropertiesByCategory / getPropertiesByAgent, getAgents / getAgent, getLocations / getLocation, getCategories / getCategory, getTestimonials and getPosts / getPost. To fetch a collection from a CMS, replace its loader and keep its schema, or rewrite those functions; pages, sections and components stay unchanged. Mirror the schemas in the CMS:

Collection In the demo Fields
properties (properties.json) 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)
agents (agents.json) 4 slug, name, image (or null), address, phone, mobile, whatsapp, email, bio
locations (locations.json) 6 slug, name
categories (categories.json) 5 slug, name
posts (posts.json) 12 slug, title, category (text), date, author, image, excerpt, body (rich text)
testimonials (testimonials.json) 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, agent and location hold the slug of 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” (the last item of each demo collection; they list nothing and are noindex). A post’s category is 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, by its position (the JSON loader numbers the items of the file; src/lib/content.ts sorts by it): give the collections an order field in the CMS and map it to position. The order matters for properties: Home’s hero slideshow is the first 4 (hero.slideshow.count), Featured Properties the 5th to the 10th (featured.offset 4, count 6, in src/content/pages/home.json), and the post pages’ “Latest Property” the first. There is no “featured” field. getPosts() sorts the posts by date, 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.count in property.json), 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.count in post.json). The open item is left out by its title (properties) or slug (posts).
  • Listings. /property pages every property six at a time (filters.pageSize in sections.json); 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.

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 blocks

The demo uses paragraphs only, with bold words (the property’s name at the start of its texts). Headings, lists and inline code are drawn too. 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).

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

A full URL in src works as it is (isRemote in src/design-system/utils/image.ts); allow the CMS’s domain in image.domains of astro.config.mjs so Astro resizes it like the local files (Images). Every photo fills a frame of its own shape, so the layout needs no width and height from the CMS.