Skip to content
Sign inJoin waitlist

Using a headless CMS — Marai Neesu Astro

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

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, src/content/schemas.ts checks every entry when the site builds, and pages read them through src/lib/content.ts: getProjects / getProject / getOtherProjects, getProducts / getProduct / getOtherProducts, getPosts / getPost / getRelatedPosts, getServices, getTestimonials, getExperiences, getTools and getSocials. 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
projects 6 slug, title, summary, service, date, client, image, description (rich text), highlights (rich text), gallery (three images, or none)
products 6 slug, title, tagline, price, category, buyUrl, demoUrl, image, screenshots (two images), specification, overview (rich text)
posts 12 slug, title, image, category, date, body (rich text)
services 4 slug, title, description, price, url, images (four in the demo)
testimonials 8 name, role, photo, quote, rating (a number, 1 to 5)
experiences 4 slug, title, company, period, url, description
tools 9 slug, title, category, url, logo, description
socials 4 label, short, href, icon

Every image is an object, { src, alt }, except a social profile’s icon, which is a path or URL.

  • Relations. No collection refers to another by key; the links are by value:
    • a project’s service is a service’s title, as text: the badge of the project page links to the url of the service with that title, and to the Services page when none matches. A choice field holding the service titles works in the CMS;
    • related posts share a category: getRelatedPosts returns up to three other posts with the same category, in list order, and the section is left out when there are none. The demo uses Product Design, UX/UI and Web Design;
    • getOtherProjects returns the first two other projects and getOtherProducts the first four other products, in list order;
    • the contact form’s “I’m interested in” choices are the services’ titles, read through getServices.
  • Order. Lists keep the order they arrive in, not by date: return entries in the CMS’s order with their position (src/lib/content.ts sorts by it), and give the CMS a sort field. The demo’s posts are newest first. Home shows the first four projects, every service and testimonial, the first six products and the first three posts; the CV the first four projects, jobs and posts; the Blog six posts before “Load More”. Those numbers are count and its siblings in src/content/pages/home.json, cv.json and blog.json.
  • Ids. Keep each entry’s id equal to its slug (a profile’s to its label, a testimonial’s to its name), as src/content.config.ts does: getProject(slug), getProduct(slug) and getPost(slug) look entries up by it.
  • Counts. A project needs three gallery images, or none; a product two screenshots (Editing the content).
  • Dates. A post’s date is an ISO date ("2024-07-08"); a project’s date is its month, as an ISO date on the first day ("2024-06-01"). A job’s period is plain text.
  • Not shown. A product’s category and a tool’s description are kept with the item but not shown on the site.
  • getOtherProjects, getOtherProducts and getRelatedPosts filter the full list, so they keep working when the loaders fetch from the CMS. The sitemap reads the same functions.

Post bodies, a project’s overview and highlights and a product’s overview are blocks, not HTML:

{ type: "heading", level: 2 | 3 | 4 | 5 | 6, text: "…" } // the posts use 3, the products 5
{ type: "paragraph", text: "…" } // **bold**, `code`, "\n" for a line break
{ type: "list", ordered?: true, items: [[ …blocks ], [ …blocks ]] } // each item is a list of blocks

There are no links and no italics inside the text. The demo’s posts use headings, paragraphs, bold words, bulleted and numbered lists and two code words; the projects use paragraphs, bold words and lists; the products headings, paragraphs and lists. Convert your CMS’s rich text to these blocks in your mapping, bold 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 project’s image and the first two gallery images 1440 × 1080 (4 : 3)
A project’s third gallery image (the wide one) 2240 × 1680 (4 : 3)
A product’s image and screenshots 1200 × 814
A post’s image 1600 px wide, landscape or portrait (the card is 4 : 3, the cover 300 to 400 px tall)
A service’s images 400 px wide, any height (shown 100 × 150)
A testimonial’s photo 150 × 150 (shown round, 50 px)
A tool’s logo 100 × 100, square (shown 50 px)
A profile’s icon An SVG, shown 26 px

A CMS gives full image URLs: the image components (FillImage and SizedImage in src/design-system/components/media/) take either a /images/<file> path or a URL (isRemote() and imageUrl() in src/design-system/utils/image.ts). Allow the CMS’s image host in astro.config.mjs (image.domains) so Astro resizes its photos too (Images). Every frame has a fixed size or proportion, so no image needs its width and height from the CMS.