SEO and metadata defaults for Astro
What the starter puts in every page for search engines and link previews: titles, canonical URLs, sitemap, robots rules, social images and structured data.
Search engines and link previews read the same few tags on every page. This starter writes them from one layout, src/layouts/Layout.astro, so each page supplies a title and a description and the rest follows from your configuration. Nothing here needs a client-side script or an external service: everything is plain HTML and files generated at build time.
Titles and descriptions
Every page passes a title and a description; the build fails if either is missing or blank. The layout adds the site name from src/config.ts after the page title with a hyphen, the delimiter Google's own guidance names, so a page titled About
getsAbout - Your project. The homepage passes home and a short line on what the site does, and the site name comes first instead:Your project: a short line on what it does.
Search results cut long titles short, so put the words that tell a page apart from its neighbours at the start. Write a description of one or two sentences that says what the page gives the reader. Search engines often build their snippet from the page text instead, so the opening paragraph should say the same thing.
Canonical URLs and trailing slashes
Each page links to its own absolute URL with<link rel="canonical">, built from the productionsite and the page path. The configuration setstrailingSlash: 'always', so that URL ends in a slash, which is the form static hosts serve for Astro's directory output. The sitemap and the Open Graph URL use the same form.
Pass canonical to point a duplicate, such as a print view, at the main page; relative values resolve against your project root and fragments are rejected. Pass canonical={false} to leave the link out. During development without a site, the layout omits canonical and social URLs rather than guessing an origin.
Sitemap, robots.txt and noindex
The official @astrojs/sitemap integration writessitemap-index.xml. The starter fills it from the pages the build actually emitted, and only with pages worth indexing: it leaves out pages marked noindex, the 404 page, redirects and pages whose canonical URL points elsewhere. You never maintain a route list.
robots.txt is generated too. It allows crawling and names the absolute sitemap URL, or drops that line when no page qualifies. Crawling stays allowed on purpose: a crawler has to fetch a page to read itsnoindex.
Pass noindex to keep a single page out of search results. For a whole preview deployment, build with SITE_NOINDEX=true: every page gets the robots meta tag while canonical URLs keep pointing at production. The supplied 404 page is noindex, has no canonical link and no social image.
Social images and link previews
When a page has an image, the layout writes the Open Graph type, URL, title, description, site name and image, thentwitter:card set to summary_large_image. By default the build draws a 1200×630 PNG title card for each eligible page, so shared links show the page title instead of a blank box. Passimage with a src to use your own picture, addalt when you want to describe it, or passimage={false} to leave the social tags out. SetsocialImages: false in src/config.ts to stop generating cards across the site.
Structured data
The homepage carries one JSON-LD @graph with aWebSite node: the site name, its URL and the page language. When src/config.ts names an author, it is the publisher: aPerson with the author's name and URL, whose@id is that URL followed by #person. If your own site describes you under that @id, every project you publish points to one description of you. Delete the author and the node names no publisher.
The starter's own homepage also passes sourceCode to the layout, which adds a SoftwareSourceCode node naming the repository, TypeScript and Astro, the licence and the author. That fits a template, whose homepage is about its code. Your copy is most likely a site, so remove sourceCode from the homepage unless the page presents your code; the footer's source link does not depend on it.
Inner pages carry no structured data by default, and there is no genericWebPage node, which search engines do not use. These guides have no publication dates, so they carry no article data either. AddArticle or BreadcrumbList where your content calls for it. FAQ and HowTo markup are not worth adding, because Google no longer shows those results.
What is left for you
Set your production site, your site name and author, and a distinct title and description on every page. After the first deployment, add the site to Google Search Console and Bing Webmaster Tools, submit the sitemap index, and link to the new site from somewhere search engines already crawl. Then give each page enough of its own text to be worth indexing; no tag makes up for a thin page.