Skip to content
Sign inJoin waitlist

Pages and sections — Compose Digi Astro

A page is a small file that picks sections and hands them content. src/pages/projects.astro is the whole Projects page:

---
import PageHeroSection from "../components/sections/PageHeroSection.astro";
import ProjectsListSection from "../components/sections/ProjectsListSection.astro";
import projectsPage from "../content/pages/projects.json";
import siteContent from "../content/site.json";
import Layout from "../layouts/Layout.astro";
import { getProjects } from "../lib/content";
import { toProjectCard } from "../lib/to-ui";
const projects = await getProjects();
const { cursorLabels } = siteContent;
---
<Layout title={projectsPage.meta.title} description={projectsPage.meta.description}>
<PageHeroSection hero={projectsPage.hero} />
<ProjectsListSection list={projectsPage.list} projects={projects.map(toProjectCard)} cursor={cursorLabels.project} />
</Layout>
  • Layout (src/layouts/Layout.astro) gives the page its browser title, description, canonical link, share image and icons, the header, the footer and the custom cursor.
  • PageHeroSection is the page header (the label, the title, the lead, the social buttons and “Scroll to Explore”), read from projects.json.
  • ProjectsListSection gets every project from the collection, through src/lib/content.ts (getProjects()), turned into what a card shows by src/lib/to-ui.ts, with “Load More”.

12 kinds of page and 47 addresses in the sitemap of the demo. Every address is in src/content/routes.ts.

Page Address Page file Copy (src/content/pages/) Items it shows
Home / src/pages/index.astro home.json the first four projects in the ticker, the fourth to the eighth in the list, the first six services, the first three posts
About /about src/pages/about.astro about.json the first three job openings
Services /services src/pages/services.astro services.json every service; the testimonials of the first three projects
Service /services/<slug> src/pages/services/[slug].astro service.json one service and its plans, four other services
Projects /projects src/pages/projects.astro projects.json every project
Project /projects/<slug> src/pages/projects/[slug].astro project.json one project, its services, three other projects
Careers /careers src/pages/careers.astro careers.json (careers) every job opening
Job /careers/<slug> src/pages/careers/[slug].astro careers.json (job) one job opening
Blog /blog src/pages/blog.astro blog.json every post
Post /blog/<slug> src/pages/blog/[slug].astro post.json one post, its neighbours, three other posts
Contact /contact src/pages/contact.astro contact.json every service as a checkbox
404 any unknown address src/pages/404.astro not-found.json —

Pages are built as files (about.html, services/branding-and-strategy.html), which hosts serve at /about and /services/branding-and-strategy (Going live). To change an address (/projects to /work, say), rename its file in src/pages/ (and its folder, for the pages built from a collection) and its entry in routes.ts, and search the content for the old address: links written as text aren’t checked (removing a page).

In src/components/sections/, one file per section. Each takes its copy from a page file (or site.json) and its items from a collection.

Section Used on
HomeHeroSection, HomeAboutSection, QuoteSection, HomeServiceSection, HomeProjectSection, BlogSection Home
PageHeroSection About, Services, every service, Projects, Blog
AboutIntroSection, AboutVideoSection, AboutTeamSection About
ServicesListSection, ProcessSection, ServicesCtaSection, TestimonialSection Services
ServiceImageSection, ServiceDetailsSection, OtherServicesSection Service
ProjectsListSection Projects
ProjectHeroSection, ProjectDetailsSection (Overview, Process, Outcome), ProjectParallaxImageSection (twice), ProjectSlideImageSection, ProjectGrowImageSection, ProjectTestimonialSection, MoreProjectsSection Project
CareersSection Careers
JobSection Job
BlogListSection Blog
PostMainSection, MoreBlogSection Post
ContactSection Contact

ProjectsCta.astro is a part, not a section: the dark invitation box (“If you are ready for a change…”) at the end of HomeProjectSection and MoreProjectsSection. The thin lines between some sections are <Divider /> (src/design-system/components/layout/Divider.astro), written in the page files. The 404 page is written in src/pages/404.astro itself.

A few blocks come from one place, so changing them there changes every page that shows them:

Block Field Shown on
The menu and “Contact Us” navigation, contactLink in site.json the header and the phone menu (and “Contact Us” in the footer)
The footer: the services ticker, the call to action, the link columns, the contact details footer, contact in site.json; the services collection every page
The words around a service, a project, a job opening or a post service.json, project.json, careers.json (job), post.json every page of that kind
A project’s testimonial testimonial of the project in projects.json the project’s page, its card on Home, the Services slider

Other blocks are written in each page’s file, so a page can say something different; to change one everywhere, change it in every file that has it:

Block Field Shown on
The page header’s social buttons and “Scroll to Explore” hero.socials, hero.scroll in about.json, services.json, service.json, projects.json, blog.json About, Services, every service, Projects, Blog
The invitation box and its buttons projects.more in home.json, more in project.json Home, every project
“Who are we?”: its photos and paragraphs about in home.json, intro in about.json Home, About
“More Details” services.detailsLabel in home.json, list.detailsLabel in services.json, others.detailsLabel in service.json, positions.detailsLabel in about.json, careers.detailsLabel in careers.json the service rows and cards, the job rows
“Load More” loadMoreLabel in projects.json, blog.json, careers.json Projects, Blog, Careers

The menu holds Home, Services, Projects, About and Blog; the logo leads Home. The other pages are reached like this:

Page Linked from
Contact “Contact Us” and the round arrow button in the header (desktops) and the phone menu, the footer’s round button and Support column, and the buttons of the copy (“Contact us”, “Get in touch”, “Drop us a line”, “Book an intro call”)
A service Its row on Home, its card on Services and under another service, the tags at the top of a project page
A project Its card in the Home hero’s ticker, Home’s list, Projects and under another project
A post Its card (Home’s “Latest Blog”, Blog, “More Blog” under another post), Prev / Next
Careers The footer’s Support column, “See all positions” on About, “Back to Career page” on a job opening
A job opening “More Details” on Careers and About’s “Open Positions”
Home, About, Services, Projects, Blog Also the footer’s Links and Support columns (footer.columns in site.json, written separately from the menu)

Every page type with each section outlined and labelled: the component that renders it, the file to edit, and where its copy (src/content/pages/*.json, src/content/site.json) and items (src/content/collections/*.json) come from. Header and footer take their links and details from src/content/site.json. Photos are the placeholders of the download.

The hero (the title, the rating, the lead, “Book a call” and “Our Services”, then the first four projects running in a ticker); “Who are we?” with two photos, two paragraphs and two buttons; the founder’s quote over a photo; “Our services”, the first six services as rows that open one at a time, and “More Services”; a line; “Our Projects”, five projects in two staggered columns with their testimonials, and the invitation box; “Latest Blog”, the first three posts. Their words are in src/content/pages/home.json.

Home: sections and the files behind them

The page header; a line; “WHO WE ARE?” with two photos, the statement and two buttons; a line; the video card, the four figures and the client logos running in a row; “Our Team”, six members with their social buttons, and “Open Positions”, the first three job openings with “See all positions”. The words are in src/content/pages/about.json.

About: sections and the files behind them

The page header; a line; every service as a card; a line; “How we work?” with the process chart; the call to action over a photo (“Drop us a line”); “Testimonials”, the slider with the first three projects’ testimonials. The words are in src/content/pages/services.json.

Services: sections and the files behind them

The page header with the service’s name and summary; the service’s photo across the width; “What We Offer”, “Key Benefits” and the plan card with its Weekly / Monthly switch; a line; “Other Services”, the first four other services, and “All Services”. The service is the item in services.json, the words around it src/content/pages/service.json.

Service: sections and the files behind them

The page header; every project as a card, three per row on desktops (two on tablets, one on phones), five at first (four on tablets, three on phones) and as many more with each press of “Load More”. The words are in src/content/pages/projects.json, the projects in projects.json.

Projects: sections and the files behind them

The services, the title, the summary and the cover photo; “Overview” with the year and the client; the main photo; “Process”; two 2 : 1 photos sliding and growing into place; the client’s testimonial; a line; “Outcome”; the last photo; a line; “More Projects”, the first three other projects, and the invitation box. Everything but the headings is the project in projects.json; the headings and “More Projects” are src/content/pages/project.json.

Project: sections and the files behind them

One section: “Join Our Team” beside the lead, then every job opening as a row (the title, the type, the summary and “More Details”), four at a time with “Load More”. The words are in src/content/pages/careers.json, the openings in careers.json.

Careers: sections and the files behind them

One section: the title and the type, then “Key Responsibilities”, “Requirements”, “Perks and Benefits” and “How to Apply”, and “Back to Career page”. Everything but the headings and the button (job in src/content/pages/careers.json) is the opening in careers.json.

Job: sections and the files behind them

The page header; every post as a card, three per row on desktops, five at first (four on tablets, three on phones) and as many more with each press of “Load More”. The words are in src/content/pages/blog.json, the posts in posts.json.

Blog: sections and the files behind them

The post: the title, “Posted on” with the date and “Posted in” with the category, the cover photo, the body, then Prev and Next (the older and the newer post in the order of the file); “More Blog”, the first three other posts. Everything in the first section but its labels is the post in posts.json; the labels and “More Blog” are src/content/pages/post.json.

Post: sections and the files behind them

One section: the title, the lead and the contact form (“Send message”). The words and the form are in src/content/pages/contact.json; the services’ checkboxes are the names in services.json.

Contact: sections and the files behind them

One section: “404”, “We lost this page”, two lines of text, “Back to homepage” and “See our Works”, centred, one screen tall on desktops. They are in src/content/pages/not-found.json.

Page not found: sections and the files behind them

Move the lines in the page file, or delete one (and its import). To take the testimonials off Services, delete <TestimonialSection … /> from src/pages/services.astro; to leave the founder’s quote off Home, delete <QuoteSection … /> from src/pages/index.astro. Delete a <Divider /> with the section it separates when two lines would meet.

A few blocks are parts of a bigger section, so they go inside its file: the invitation box is <ProjectsCta … /> at the end of HomeProjectSection.astro and MoreProjectsSection.astro; “Open Positions” is part of AboutTeamSection.astro; the video card, the figures and the client logos are AboutVideoSection.astro; the plan card is part of ServiceDetailsSection.astro.

“Scroll to Explore” in a page header leads to the block whose id is start (intro.id in about.json, list.id in services.json, projects.json and blog.json, imageId in service.json). If you remove or move that block, give the id to the block that now follows the header, or change hero.scroll.href.

  1. Add the URL to src/content/routes.ts:

    pricing: "/pricing",
  2. Add its copy to src/content/pages/pricing.json, with a meta (title, description):

    {
    "meta": {
    "title": "Pricing",
    "description": "Our monthly retainers for strategy, content, ads and analytics: what each one includes and how to start working with us."
    },
    "hero": {
    "eyebrow": "Pricing",
    "title": "Plans That Grow With Your Brand",
    "lead": "Pick a monthly retainer, or ask us for a plan made for you.",
    "socials": [{ "label": "Instagram", "href": "https://instagram.com", "network": "instagram" }],
    "scroll": { "label": "Scroll to Explore", "href": "#start" }
    },
    "intro": {
    "eyebrow": "Our plans",
    "title": "One Monthly Fee, No Surprises",
    "lead": "Every retainer includes a strategy call, a monthly report and a team that knows your brand."
    },
    "cta": {
    "eyebrow": "Not sure yet?",
    "title": "Tell Us About Your Goals.",
    "lead": "We reply within one working day.",
    "action": { "label": "Drop us a line", "href": "/contact" },
    "image": { "src": "/images/services-cta.jpg", "alt": "A developer typing at a desk with code on a large monitor" }
    }
    }
  3. Create src/pages/pricing.astro:

    ---
    import PageHeroSection from "../components/sections/PageHeroSection.astro";
    import ServicesCtaSection from "../components/sections/ServicesCtaSection.astro";
    import pricing from "../content/pages/pricing.json";
    import Divider from "../design-system/components/layout/Divider.astro";
    import Section from "../design-system/components/layout/Section.astro";
    import SectionTitle from "../design-system/components/patterns/SectionTitle.astro";
    import { text } from "../design-system/tokens/text";
    import { cn } from "../design-system/utils/cn";
    import Layout from "../layouts/Layout.astro";
    ---
    <Layout title={pricing.meta.title} description={pricing.meta.description}>
    <PageHeroSection hero={pricing.hero} />
    <Divider />
    <Section id="start" gap="gap-2.5">
    <SectionTitle eyebrow={pricing.intro.eyebrow} title={pricing.intro.title} />
    <p class={cn(text.paragraph, "max-w-[650px] text-grey")}>{pricing.intro.lead}</p>
    </Section>
    <ServicesCtaSection cta={pricing.cta} />
    </Layout>

    PageHeroSection holds the page’s <h1> (every page has one). A page without it starts right under the header: begin it with a plain <Section> and give its title an <h1> in the text.h1 style. ServicesCtaSection reads the same fields as the cta of services.json, so the new page reuses it as it is.

  4. Link to it: add { "label": "Pricing", "href": "/pricing" } to navigation in src/content/site.json (the menu), and to a column of footer.columns if you want it there. Keep the menu short: the links sit in one pill on tablets. The phone menu opens to a fixed height that fits five links: for a sixth, raise 386px in src/components/site/header.ts by 38 px per link.

  5. Add routes.pricing to the paths list in src/pages/sitemap.xml.ts, next to the other top-level pages.

Delete its file under src/pages/ (for Blog, Projects, Services or Careers, also the folder of their items), its entry in navigation and footer.columns (src/content/site.json), its line in src/pages/sitemap.xml.ts, and the route in routes.ts. npm run check then tells you about anything still using the route through routes. Links written as text in the content are not checked: the /contact, /projects and /services of the buttons (hero.links, about.secondaryAction, projects.more in home.json, intro.secondaryAction in about.json, others.action in service.json, primaryAction and secondaryAction in not-found.json, contactLink…), for example. Search src/content/ for the path.

src/pages/blog/[slug].astro builds one page per post:

export const getStaticPaths = (async () => {
return (await getPosts()).map((post) => ({ params: { slug: post.slug }, props: { post } }));
}) satisfies GetStaticPaths;

Add a post to src/content/collections/posts.json, and its page, its card and its sitemap entry appear on the next build; any other address under /blog/ is a 404. The same pattern builds the services (src/pages/services/[slug].astro), the projects (src/pages/projects/[slug].astro) and the job openings (src/pages/careers/[slug].astro).

src/pages/404.astro, with its copy in src/content/pages/not-found.json. It is built as 404.html, which hosts serve for any unknown address, with a 404 status; it is noindex, like the style guide.

  • Sticky. The header stays at the top of every page, on the page colour, 68 px tall on phones, 104 px on tablets and 112 px on desktops. It is part of the page, so every page starts under it, and it doesn’t change as you scroll.
  • Desktop and tablet: a light bar with round ends holding the logo, the pill of the menu links and, on desktops, “Contact Us” and the round lime arrow button (both to /contact). A link fills with grey under the pointer while its label rolls.
  • Phone: the logo and a menu button. A press turns its lines into a cross and grows the header over the page, with the links in a column and the two buttons under them. It closes when a link, the logo row or the buttons are pressed, on Escape and when the window grows to tablet width. src/components/site/header.ts runs it.
  • The menu is navigation in src/content/site.json. The link of the current page is lime and screen readers hear it as the current page: Home on / only, the others on their page and the pages under it (a project lights Projects, a post Blog). Careers, a job opening and Contact light none.
  • Sitemap: src/pages/sitemap.xml.ts builds sitemap.xml from routes.ts and the collections: the seven main pages (Home, About, Services, Projects, Careers, Blog, Contact), then every service, project, post and job opening: 47 addresses in the demo. The 404 page and the style guide are left out.
  • Robots: src/pages/robots.txt.ts builds robots.txt, which allows everything and points at the sitemap. Both use site.url, so set your domain before publishing.
  • Per page: every indexable page gets a title, a description, a canonical link, an og:url and a share image from src/layouts/Layout.astro (with src/lib/meta.ts). The pages with a file in src/content/pages/ write theirs in its meta (careers.meta in careers.json); Home uses site.title and its own meta.description. A service and a project take their name or title and their summary, a post its title and the start of its first paragraph, a job opening its title and summary. A title that would be longer than 60 characters with | Compose appended is shown without the suffix. Every page shares public/opengraph-image.png.
  • Not indexed: the style guide and the 404 page (noindex).