Using a headless CMS — Fitbricks Astro
Connecting a headless CMS works the same for every Astro template sold on Framebrick, so this page lists only what is specific to Fitbricks.
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: getPrograms / getProgram, getProgramCategories / getProgramCategory,
getCities / getCity, getClubs / getClub, getFacilities, getTrainers / getTrainer, getPosts / getPost,
getLegalPages / getLegalPage, and getCardRefs (the category and city lookups of the cards). Mirror
src/content/schemas.ts in the CMS:
| Collection | In the demo | Fields |
|---|---|---|
Program |
20 | slug, name, category (a ProgramCategory slug), level (easy, medium or hard), duration (minutes), instructor (text), subtitle, image, video (a YouTube URL), about, benefits, details (rich text), plans (a list of { name, description, price, includes: [text] }) |
ProgramCategory |
5 | slug, name, color (hex), icon (a white SVG), description |
City |
10 | slug, name |
Club |
30 | slug, name, city (a City slug), location, image, gallery (four images), about (rich text: paragraphs), facilities (Facility slugs), programs (Program slugs), address, mapUrl, phone, phoneHref, email, emailHref, hours ({ weekdays, weekends }) |
Facility |
14 | slug, name, description, image |
Trainer |
12 | slug, name, title (the role), summary, image, about (rich text: paragraphs), programs (Program slugs), email, emailHref, phone, phoneHref, socials (a list of { name, label, href }; href may be null) |
Post |
16 | slug, title, category (a name, plain text), date (ISO), excerpt, image, body (rich text) |
LegalPage |
2 | slug, title, updated (ISO date), description (the lead), metaDescription, body (rich text) |
Every image is { src, alt }.
- Relations. They are by slug: a program’s
category, a club’scity,facilitiesandprograms, a trainer’sprograms. The pages resolve them (getCardRefs, and the club and trainer pages): a club’s or trainer’s slug with no item is skipped, a city with no item shows its slug, and a program whose category is missing stops the build. A reference field that returns slugs is the simplest mapping. A post’scategoryis a plain name; posts with the same name are “Related Articles”. - Order. Every collection keeps the order of its entries (
position, from the file’s order), except posts, whichgetPosts()sorts bydate, newest first; give the other collections a sort field. A club’s facilities and classes and a trainer’s programs follow the order of their slugs. - Counts. Home shows the first six clubs, the first six programs and the first six posts (four on phones); the trainers band the first three trainers; the footer the first five programs; Contact the first six clubs; Free trial’s Preferred Class the first ten programs. The counts are page copy (Editing the content).
- Default category.
defaultis the original design’s catch-all: it has a page but no link in the filters (src/components/sections/programs/category-filter.ts). - The helpers filter the full lists, so they keep working when a
get…function fetches from the CMS. The sitemap reads the same functions. - The footer’s Resources column lists every legal page by its title; its other links, and the menu, are typed in
src/content/site.json.
Rich text
Section titled “Rich text”Post bodies, legal texts and a program’s about, benefits and details are blocks, not HTML:
{ type: "heading", level: 3 | 4, text: "…" } // posts and legal pages: Heading 3 and 4, written as h2 and h3{ type: "paragraph", text: "…" } // **bold**, [text](href), \n for a line break{ type: "list", ordered: boolean, items: ["…", "…"] } // each item is a line of text with the same marksThe demo’s posts use level-3 and level-4 headings, paragraphs and lists; the legal texts level-3 headings, paragraphs,
lists, bold runs and links; the programs’ texts paragraphs and bulleted lists; a club’s and a trainer’s about only
paragraphs (other blocks are not shown there). There are no italics, tables, images or quotes inside the text. Convert
your CMS’s rich text to these blocks in your mapping function, bold as **…** and links as text
(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 program’s image (cards, the cover, the share image) |
1920 × 1280 |
A category’s icon |
an SVG, drawn white |
A club’s image |
1200 × 800 |
A club’s gallery |
800 × 533 each |
A facility’s image |
400 × 267 |
A trainer’s image |
800 × 1200 |
A post’s image |
1200 × 800 |
A CMS gives full image URLs: the image component (FillImage in src/design-system/components/media/) and the share
images 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).