Layout for Astro
Astro document parts for the page shell, head, body, and main content.
Use the Layout parts in a document shell or a template layout. The framed examples show how those parts arrange a page with its own document structure.
Installation
bunx --bun shadcn@latest add @gnostic/layoutnpx shadcn@latest add @gnostic/layoutpnpm dlx shadcn@latest add @gnostic/layoutCopy the files
src/components/ui/layout/index.tssrc/components/ui/layout/layout-body.astrosrc/components/ui/layout/layout-head.astrosrc/components/ui/layout/layout-main.astrosrc/components/ui/layout/layout.astro
Usage
---
import { Layout, LayoutBody, LayoutHead, LayoutMain } from "@/components/ui/layout"
---
<Layout lang="en">
<LayoutHead name="gnostic ui" title="Page title" description="Page description" />
<LayoutBody>
<LayoutMain>
<slot />
</LayoutMain>
</LayoutBody>
</Layout>
Responsive layout
Set containerSize on Layout to change the maximum section content width. For example, <Layout containerSize="64rem"> sets --container to 64rem on the document root. The default is Tailwind’s var(--container-7xl).
LayoutMain uses @container/main to create a responsive layout.
Notes
Layoutowns the root<html>element and global visual baseline.LayoutHeadcentralizes metadata, canonical URLs, and social tags.Seosupplies the same metadata inside an existing<head>. Import it from@/components/ui/layout/seo.astro.LayoutBodyandLayoutMainprovide the default body and page-content wrappers.LayoutMainis a neutral structural wrapper for page content.
API Reference
LayoutHead and Seo share SeoProps from layout/types.ts. Both require a site name (name) and a page title (title). Each value must contain text.
LayoutProps
containerSize?string
The maximum content width. Sets `--container` on the document root.
string"var(--container-7xl)"SeoProps
namestring
The name of the site.
stringtitlestring
The title of the page. Used for the `<title>` tag.
stringdescription?string
The description of the page.
stringimage?{ src?: ImageMetadata | string; alt?: string }
The image of the page. Used for the `<meta property="og:image" content="...">` tag.
{ src?: ImageMetadata | string; alt?: string }noindex?boolean
Whether to add the `noindex` attribute to the `<meta name="robots" content="...">` tag.
booleannofollow?boolean
Whether to add the `nofollow` attribute to the `<meta name="robots" content="...">` tag.
booleancanonical?string
The canonical URL of the page. Used for the `<link rel="canonical" href="...">` tag.
stringgraph?Record<string, unknown> | null
The graph data for the page. Used for the `<script type="application/ld+json">` tag.
Record<string, unknown> | nulltitleTemplate?string
Template for composing the full `<title>`. Use `%s` where the title should be substituted. Defaults to the raw `title`.
stringpreserveQueryParams?boolean
Keep the query string in the default canonical URL. Defaults to `false` (query params are stripped — the SEO-correct behavior for most cases). Has no effect when `canonical` is explicitly set.
booleanogType?'website' | 'article' | 'profile' | 'book'
Open Graph type. Defaults to `'website'`.
'website' | 'article' | 'profile' | 'book'ogImage?string
Absolute URL of the share image.
stringogImageAlt?string
Alt text for the share image.
stringogImageWidth?number
Width of the share image in pixels.
numberogImageHeight?number
Height of the share image in pixels.
numbersiteName?string
Site name shown in OG tags, e.g. `"Joost.blog"`.
stringlocale?string
OG locale. Defaults to `'en_US'`.
stringtwitter?{
/** Twitter handle of the site owner, e.g. `'@jdevalk'`. */
site?: string;
/** Twitter handle of the author. */
creator?: string;
/** Card type. Defaults to `'summary_large_image'`. */
card?: 'summary' | 'summary_large_image' | 'app' | 'player';
/** Override twitter:title. Omit to fall back to og:title. */
title?: string;
/** Override twitter:description. Omit to fall back to og:description. */
description?: string;
/** Override twitter:image. Omit to fall back to og:image. */
image?: string;
/** Override twitter:image:alt. Omit to fall back to og:image:alt. */
imageAlt?: string;
}
Twitter card metadata. Only Twitter-specific tags (card, site, creator) are emitted by default — twitter:title, :description, :image, and :image:alt fall back to their `og:` counterparts automatically. Set `title`, `description`, `image`, or `imageAlt` here only when you want Twitter-specific content that differs from the OG values.
{
/** Twitter handle of the site owner, e.g. `'@jdevalk'`. */
site?: string;
/** Twitter handle of the author. */
creator?: string;
/** Card type. Defaults to `'summary_large_image'`. */
card?: 'summary' | 'summary_large_image' | 'app' | 'player';
/** Override twitter:title. Omit to fall back to og:title. */
title?: string;
/** Override twitter:description. Omit to fall back to og:description. */
description?: string;
/** Override twitter:image. Omit to fall back to og:image. */
image?: string;
/** Override twitter:image:alt. Omit to fall back to og:image:alt. */
imageAlt?: string;
}article?{
publishedTime?: Date | string;
modifiedTime?: Date | string;
expirationTime?: Date | string;
authors?: readonly string[];
tags?: readonly string[];
section?: string;
}
Article-specific OG metadata. Only emitted when `ogType` is `'article'`.
{
publishedTime?: Date | string;
modifiedTime?: Date | string;
expirationTime?: Date | string;
authors?: readonly string[];
tags?: readonly string[];
section?: string;
}articlePublisher?string
Facebook page URL of the publisher. Emitted as `article:publisher` when `ogType` is `'article'`.
stringauthor?string
Author name for the `<meta name="author">` tag. If omitted but `article.authors` is set, the first author is used.
stringextraLinks?ReadonlyArray<Record<string, string>>
Extra `<link>` tags (icons, sitemap, RSS alternate, etc.).
ReadonlyArray<Record<string, string>>extraMeta?ReadonlyArray<Record<string, string>>
Extra `<meta>` tags (author, custom fields).
ReadonlyArray<Record<string, string>>alternates?BuildAlternateLinksInput
hreflang alternate-language annotations. Emits one `<link rel="alternate" hreflang="…" href="…">` per entry, plus an `x-default` entry pointing at the default-locale sibling (or the first entry, if no default match is found). Also emits matching `og:locale:alternate` tags.
BuildAlternateLinksInputRead the installed source for the complete prop types.
When to use Layout
Use Layout parts in the site template that owns the route. Set the document language and provide page metadata in the head. Keep reusable blocks inside the main content rather than making them own the document.
Keyboard and behavior
A page needs one main landmark and a logical heading order. Add a skip link when repeated navigation comes before the main content. These shell parts do not infer titles or canonical URLs from arbitrary content.
Theme and layout
Import the shared stylesheet once in your site layout. LayoutBody applies the preset background, text color, sans font, and font smoothing to the body. Theme and page background choices belong at this level. Avoid a second html or body element inside a reusable block.