Skip to content
Sign inJoin waitlist

Using a headless CMS — Lookis Astro

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

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, getServices / getService / getOtherServices. 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
portfolio 16 slug, title, summary, date, service (a service’s slug), details (rich text), image (src, alt), gallery (images: src, alt)
services 4 slug, name, summary, price (text), image (src, alt), content (rich text), perfectFor (up to four lines), included (up to five lines)
  • References. A project points to its service by the service’s slug (service: "weddings-elopements"). In the CMS make it a reference to a service and return the slug in your mapping. The service decides the project’s filter tab on Portfolio, the “Service” line of its page (the service’s name, read with getService) and its “Related Projects”: up to three other projects with the same service, in list order. A slug that matches no service leaves the line out and the project only under “All”.
  • 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 projects are newest first, and the CMS order should keep them so: Home shows the first six (projects.count in src/content/pages/home.json) and Portfolio lists them in that order, four at a time as the visitor scrolls. The services’ order is the order of Home’s rows, the Services cards and Portfolio’s tabs; getOtherServices returns the first three others, in list order.
  • Ids. Keep each entry’s id equal to its slug, as src/content.config.ts does: getProject(slug) and getService(slug) look entries up by it.
  • Dates. A project’s date is an ISO date ("2024-04-14"), shown as “Apr 14, 2024”.
  • Lists. perfectFor and included are plain strings, numbered 01, 02, … on the page; an empty string leaves its row out without renumbering.
  • The testimonials are not a collection: they are page copy in src/content/pages/shared.json (Editing the content). Keep them there or add a collection of your own.
  • The sitemap reads the same functions, so new entries are listed once the site rebuilds.

A project’s details and a service’s content are lists of paragraph blocks, not HTML:

{ type: "paragraph", text: "…" } // **bold** and *italic* between asterisks, "\n" for a line break

There are no headings, lists or links inside the text: the schema accepts paragraphs only (the RichText component could draw headings and lists, see Editing the content). Convert your CMS’s rich text to these blocks in your mapping, bold as **…** and italics as *…* (how). The demo starts each service’s content with a short lead in italics, and a page’s search description uses the second paragraph of a service’s content and the first of a project’s details when the summary is short.

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, and store an alt for each:

Image Size
A project’s image (the card at 565 : 600, the tall photo of its page) 1440 × 1440
A project’s gallery (one under the other at 0.74 : 1) 1440 px wide, portrait
A service’s image (the tall photo of its page, Home’s row) 1200 × 1500, portrait (the demo’s are 1200 × 800)

A CMS gives full image URLs: the image component (FillImage in src/design-system/components/media/) takes 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).