Using a headless CMS — Compose Digi Astro
Connecting a headless CMS works the same for every Astro template sold on Framebrick, so this page lists only what is specific to Compose.
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.
Collections
Section titled “Collections”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: getServices / getService, getProjects / getProject, getPosts / getPost,
getCareers / getCareer. 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 |
|---|---|---|
services |
8 | slug, name, summary, image (src, alt), offer and benefits (rich text), weekly and monthly (each a price as text and features, a list of lines) |
projects |
8 | slug, title, company, year (text), summary, thumbnail (src, alt), services (service slugs), testimonial (name, role, photo, quote), overview, process and outcome (rich text), mainImage, images (exactly two), finalImage |
posts |
12 | slug, title, excerpt, image (src, alt), category (text), date, body (rich text) |
careers |
12 | slug, title, type (text), summary, responsibilities, requirements, benefits and apply (rich text) |
- Order. Lists keep the order they arrive in, not by date: return entries in the CMS’s order with their
position(src/lib/content.tssorts by it), and give the CMS a sort field. The demo’s posts are newest first, and the CMS order should keep them so: Home shows the first three, Blog lists them in that order, and a post’s Prev / Next are its neighbours in that order. Home’s ticker shows the first four projects and its list the fourth to the eighth (projects.tickerCount,listOffset,listCountinsrc/content/pages/home.json), Home’s rows the first six services, About the first three job openings, and Services the testimonials of the first three projects. - References. A project’s
servicesholds theslugs of services: in the CMS, a reference to the services collection (many), mapped back to slugs. They become the links at the top of the project page; the first one labels the project’s card in the Home hero’s ticker. A slug with no matching service is skipped. - Testimonials are part of each project, not a collection of their own: in the CMS, a group of fields on the project.
- Plans. Each service has exactly two,
weeklyandmonthly; the price is text as it should read (“$1,200”). - Services in the form. The contact form offers one checkbox per service, by
name, in list order; submissions carry the names. The footer’s ticker shows the first eight names. - Ids. Keep each entry’s
idequal to itsslug, assrc/content.config.tsdoes:getService(slug),getProject(slug),getPost(slug)andgetCareer(slug)look entries up by it. - Dates. A post’s
dateis an ISO date ("2024-06-25"), shown as “Jun 25, 2024”. - The team, the client logos, the figures and the process chart are not collections: they are page copy in
src/content/pages/(about.json,services.json). Keep them there or add collections of your own. - The sitemap reads the same functions, so new services, projects, posts and job openings are listed once the site rebuilds.
Rich text
Section titled “Rich text”A service’s offer and benefits, a project’s overview, process and outcome, a post’s body and a job opening’s
four texts are lists of blocks, not HTML:
{ type: "heading", level: 3, text: "…" }{ type: "paragraph", text: "…" } // **bold**, *italic*, [label](href) links, "\n" for a line break{ type: "list", ordered: false, items: [[{ type: "paragraph", text: "…" }], …] } // each item is a list of blocksHeadings take the text style of their level (levels 1 to 3 are drawn as <h2> under the page’s title); lists can be
numbered (ordered: true) and nested. There are no images inside the text. Convert your CMS’s rich text to these blocks
in your mapping, bold as **…**, italics as *…* and links as label
(how). A post’s search description is the start of its first paragraph.
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, and store an alt text for each:
| Image | Size |
|---|---|
A project’s thumbnail (the cards at 535 : 373, the ticker card, the project page’s first image at 1120 × 635) |
2000 × 1333 |
A project’s mainImage and finalImage (the full width at 3 : 2) |
2000 × 1333 |
A project’s images (2 : 1, up to 1080 wide) |
1200 × 600 |
A testimonial’s photo (a 72 px circle) |
150 × 150 |
A service’s image (the service page at 1200 : 680 across the width, the card at 353 : 420) |
2200 × 1460 |
A post’s image (the card at 353 : 420, the post’s cover at 3 : 2) |
2000 × 1333 |
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). The testimonial portraits are shown as decoration (the name is
beside them), so their alt can stay empty.