Pages and sections — Kendi Astro
A page is a small file that picks sections and hands them content. src/pages/blog.astro is the whole Articles page:
---const [posts, categories, authors, photos] = await Promise.all([getPosts(), getCategories(), getAuthors(), getNewsletterPhotos()]);---
<Layout title={blog.meta.title} description={blog.meta.description}> <BreadcrumbSection items={[{ label: blog.crumb }]} /> <BlogSection posts={toPostCards(posts, categories, authors)} /> <NewsletterSection photos={photos} /></Layout><Layout>(src/layouts/Layout.astro) gives the page its browser title, description, canonical link and share image, and wraps it in the header and the footer.getPosts()reads the collection, newest first (see Editing the content).toPostCardsturns each post into what a card shows, with its category and author (src/lib/to-ui.ts).- The sections render them: the breadcrumb, the title and every post as a card, then the newsletter band.
The pages
Section titled “The pages”11 kinds of page and 86 addresses in the demo. Every address is in src/content/routes.ts; the lists live at
/category and /author, in the singular, so a category is /category/business and an author
/author/olivia-bennett.
| Page | Address | Page file | Copy (src/content/pages/) |
Items it shows |
|---|---|---|---|---|
| Home | / |
src/pages/index.astro |
home.json |
posts, categories, authors |
| About | /about |
src/pages/about.astro |
about.json |
team |
| Articles | /blog |
src/pages/blog.astro |
blog.json |
posts |
| Post | /blog/<slug> |
src/pages/blog/[slug].astro |
post.json |
one post, six of its category |
| Categories | /category |
src/pages/category.astro |
categories.json |
categories, two posts each |
| Category | /category/<slug> |
src/pages/category/[slug].astro |
category.json |
one category, its posts |
| Authors | /author |
src/pages/author.astro |
authors.json |
authors, four posts each |
| Author | /author/<slug> |
src/pages/author/[slug].astro |
author.json |
one author, their posts |
| Contact | /contact |
src/pages/contact.astro |
contact.json |
— |
| Legal page | /legal/<slug> |
src/pages/legal/[slug].astro |
legal.json |
one legal page |
| 404 | any unknown address | src/pages/404.astro |
not-found.json |
— |
To change an address, rename its file in src/pages/ and its entry in routes.ts, and search the content for the old
address: links written as text aren’t checked (removing a page).
The sections you can use
Section titled “The sections you can use”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 | File | Used on |
|---|---|---|
HeroSection (the slideshow, the list beside it, the newsletter box), HomeMainSection (the lists beside the sidebar) |
HeroSection.astro, HomeMainSection.astro |
Home |
AboutMainSection, TeamSection |
AboutMainSection.astro, TeamSection.astro |
About |
BlogSection (with PostGrid and the loader) |
BlogSection.astro, PostGrid.astro |
Articles |
PostMainSection (the article beside the sidebar), RelatedSection |
PostMainSection.astro, RelatedSection.astro |
Post |
CategoryOverview, AuthorOverview |
CategoryOverview.astro, AuthorOverview.astro |
Categories, Authors |
CategoryHead, AuthorHead, ArchiveGrid |
CategoryHead.astro, AuthorHead.astro, ArchiveGrid.astro |
Category, Author |
ContactSection |
ContactSection.astro |
Contact |
LegalSection |
LegalSection.astro |
Legal |
BreadcrumbSection |
BreadcrumbSection.astro |
every page but Home and the 404 |
Sidebar |
Sidebar.astro |
inside HomeMainSection and PostMainSection |
NewsletterSection (the band above the footer) |
NewsletterSection.astro |
every page but the legal pages and the 404 |
Blocks that pages share
Section titled “Blocks that pages share”Some blocks have one copy that several pages read, so changing it once changes it everywhere:
| Block | Copy | Shown on |
|---|---|---|
| The newsletter band: title, text, the form and its consent line, three photos | newsletter in src/content/site.json; the photos are the covers of the three newest posts |
every page but the legal pages and the 404 |
| The sidebar: About, Explore Topics, the newsletter card, Spotlight, the ad | sidebar, newsletter.form and sponsoredAd in site.json; the categories and posts from the collections |
Home, every post |
| The sponsored ad | sponsoredAd in site.json |
Home (wide), the sidebar (tall) |
| The breadcrumb | breadcrumbs in site.json; each page’s last crumb in its page file |
every page but Home and the 404 |
| The Categories menu | categoriesMenu in site.json; categories and trending posts from the collections |
the header of every page |
How the pages link to each other
Section titled “How the pages link to each other”The menu holds Home, Articles, Categories (a menu), About and Authors; the header’s button opens Contact. The other pages are reached like this:
| Page | Linked from |
|---|---|
| A post | Its card everywhere (Home, Articles, a category or author page, Categories, Authors, Related Post, the Spotlights) and the newsletter band’s photos |
| A category | The Categories menu, the sidebar’s Explore Topics, the footer’s Categories column, the pill on every card and the breadcrumb of a post |
| Categories | “More categories” in the menu and the sidebar, “More” in the footer, the breadcrumb of a category page |
| An author | The author’s name on every card and post, and Authors |
| Legal pages | The footer’s legal links and the newsletter’s consent line (footer.legalLinks, newsletter.form.consent in site.json) |
| Contact | The header’s button, About’s “Contact us”, the sponsored ad’s “Learn more” |
Page maps
Section titled “Page maps”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. A section
whose copy is in site.json or that imports its own copy shows no copy line: the text below each map names it. A box
labelled Section is the design system’s <Section> written in the page file itself
(src/design-system/components/layout/Section.astro, not a file in components/sections/), with the components it holds named under it.
Three sections, top to bottom: the hero (the slideshow of the five newest posts, the next three beside it, the eyebrow,
title, lead and the newsletter box); the main column beside the sidebar (Editor’s pick, the wide sponsored ad,
Trending, the Inspiration carousel and Latest posts with “View more”); the newsletter band. The words are in
src/content/pages/home.json, with the rules of every list (Editing the content); the
sidebar and the ad are in site.json.

Four sections: the breadcrumb; the story (the title, the lead, three photos, the statement, two paragraphs and “Contact
us”); “Meet the Team” with every member of team.json; the newsletter band. The words are in
src/content/pages/about.json.

Categories
Section titled “Categories”Three sections: the breadcrumb; every category (its photo, name, description and “View articles”) with its two newest
posts under “From this category”; the newsletter band. The words are in src/content/pages/categories.json, the
categories in categories.json.

Category
Section titled “Category”Three sections: the breadcrumb (Home > Categories > the category); the category’s name, description and photo over every
post of the category, newest first (CategoryHead and ArchiveGrid in a <Section> of the page file); the newsletter
band. Everything about the category is its entry in categories.json; the patterns of its browser title and description
are in src/content/pages/category.json.

Authors
Section titled “Authors”Three sections: the breadcrumb; every author (photo, name, role, bio, social links and “View articles”) with their four
newest posts; the newsletter band. The words are in src/content/pages/authors.json, the authors in authors.json.

Author
Section titled “Author”Three sections: the breadcrumb (Home > Author > “Archives for” the name); the author’s photo, name, role, bio and social
links over every post they wrote, newest first (AuthorHead and ArchiveGrid); the newsletter band. The author is their
entry in authors.json; the words are in src/content/pages/author.json.

Articles
Section titled “Articles”Three sections: the breadcrumb; the title and every post as a card, newest first, in columns (three on desktop, two on
tablets, one on phones); the newsletter band. Six posts show at first, and six more load each time the end of the list
comes into view (list.pageSize in src/content/pages/blog.json). Every post is in the page’s HTML, so search engines
find them all, and visitors without JavaScript see them all at once.

Four sections: the breadcrumb (Home > the category > the title); the article (the title, the excerpt, the author and the cover
across the page, then the category pill, the date and the text beside the sidebar); “Related Post” (the six newest other posts of its
category, four on tablets and phones, and “View more”); the newsletter band. The article is the post in posts.json; the
labels are in src/content/pages/post.json.

Legal page
Section titled “Legal page”Two sections: the breadcrumb, then the title, “Last updated: “ with its date and the text. They are the legal page in
src/content/collections/legal.json; the label is in src/content/pages/legal.json. The legal pages have no newsletter
band. Their texts hold placeholders to fill in (Editing the content).

Contact
Section titled “Contact”Three sections: the breadcrumb; the title, the lead and the details (address, e-mail and phone, business hours, social
links) beside the contact form; the newsletter band. The words and the form are in src/content/pages/contact.json
(Forms); the details are contact and socials in src/content/site.json.

Page not found
Section titled “Page not found”One block, a screen tall: the big “404”, a title, a line and a button back to Home. They are in
src/content/pages/not-found.json; the layout is written in src/pages/404.astro.

Reordering or removing a section
Section titled “Reordering or removing a section”Move the lines in the page file, or delete one. To take the newsletter band off About, delete <NewsletterSection … />
from src/pages/about.astro. Removing a shared block from one page leaves it on the others
(shared blocks).
The blocks of Home’s main column (Editor’s pick, the ad, Trending, Inspiration, Latest posts) are parts of one section:
move or delete them in src/components/sections/HomeMainSection.astro. The sidebar’s blocks (About, Explore Topics,
the newsletter card, Spotlight, the ad) are in src/components/sections/Sidebar.astro.
Adding a page
Section titled “Adding a page”-
Add the URL to
src/content/routes.ts:advertise: "/advertise", -
Add its copy to
src/content/pages/advertise.json, with ameta(title, description):{"meta": {"title": "Advertise With Us","description": "Reach curious readers: sponsored posts, the sidebar ad and newsletter placements on Kendi."},"crumb": "Advertise","title": "Advertise with us","lead": "Put your brand in front of readers who value depth and context."} -
Create
src/pages/advertise.astro:---import BreadcrumbSection from "../components/sections/BreadcrumbSection.astro";import NewsletterSection from "../components/sections/NewsletterSection.astro";import advertise from "../content/pages/advertise.json";import Section from "../design-system/components/layout/Section.astro";import { text } from "../design-system/tokens/text";import { cn } from "../design-system/utils/cn";import Layout from "../layouts/Layout.astro";import { getNewsletterPhotos } from "../lib/sidebar";const photos = await getNewsletterPhotos();---<Layout title={advertise.meta.title} description={advertise.meta.description}><BreadcrumbSection items={[{ label: advertise.crumb }]} /><Section inner="flex flex-col gap-5"><h1 class={text.h3}>{advertise.title}</h1><p class={cn(text.body, "max-w-[700px] text-grey")}>{advertise.lead}</p></Section><NewsletterSection photos={photos} /></Layout>Layoutwrites the head (title, description, canonical link, share card), the header and the footer.The page starts under the header by itself: the header is fixed and keeps a spacer of its height (the header).
-
Link to it: add
{ "label": "Advertise", "href": "/advertise" }tonavigationinsrc/content/site.json(the menu), or to a column offooter.columns. Pointing the sponsored ad’scta.hrefat it makes the ad an “advertise with us” link. -
Add
routes.advertiseto thepathslist insrc/pages/sitemap.xml.ts, next to the other top-level pages.
Removing a page
Section titled “Removing a page”Delete its file under src/pages/, its entry in navigation and the footer’s links (src/content/site.json), its line
in src/pages/sitemap.xml.ts, and the route in routes.ts. npm run build then tells you about anything still using the
route through routes. Links written as text in the content are not checked: the header’s “Contact us”, About’s button
and the ad’s “Learn more” (/contact), the “More categories” links (/category), the “View more” links (/blog) and
the footer’s columns, for example. Search src/content/ for the path.
Pages built from a collection
Section titled “Pages built from a collection”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 cards and its sitemap entry appear on the next
build; a slug that isn’t in the list is a 404. The same pattern builds the category pages, the author pages and the
legal pages. A slug may hold a character such as the typographic ’ (three demo posts do): the address encodes it.
The 404 page
Section titled “The 404 page”src/pages/404.astro, with its copy in src/content/pages/not-found.json. The build writes it as 404.html, which hosts
show for any unknown address (and for a post, category, author or legal slug that doesn’t exist) with a 404 status; it
is noindex, like the style guide.
The header
Section titled “The header”- A white bar fixed at the top of every page, 65 px tall on phones and 82 px from tablets up. A spacer of the same
height sits under it, so pages start below it (
src/components/site/Header.astro). - Desktop: the logo, the menu links and the “Contact us” button. Hovering Categories opens a panel with the first five categories (photo, name, description), “More categories” and the Spotlight (the first four trending posts). Tablet and phone: the logo and a menu button; the menu opens under the bar with the links, the categories in a list that opens under Categories, and the button. It closes when a link is followed or the visitor presses Escape.
- The menu is
navigationinsrc/content/site.json, the buttonheaderAction, the panelcategoriesMenu. On hover a link’s label rolls up.
Search engines
Section titled “Search engines”- Sitemap:
src/pages/sitemap.xml.tsbuildssitemap.xmlfromroutes.tsand the collections: Home, About, Contact, Articles, Categories and every category, Authors and every author, every post and the legal pages — 86 addresses in the demo. The 404 page and the style guide are left out. - Robots:
src/pages/robots.txt.tsbuildsrobots.txt, which allows everything and points at the sitemap. Both usesite.url, so set your domain before publishing. - Per page: every indexable page gets a title, a description, a canonical link, an
og:urland a share image from<Layout>andsrc/lib/meta.ts. The pages with one address write theirs in their page file’smeta. The pages built from a collection fill a pattern from the item: a post its title and excerpt, a category its name and description, an author their profile, a legal page its title. A title that would be longer than 60 characters with| Kendiappended is shown without the suffix. Posts share their own cover, as articles with their date; categories and authors share their photo. - Not indexed: the style guide and the 404 page (
noindex).