SEO and social
A page type can give its pages an SEO & Social tab: a title, a description, a social image and a switch to hide the page from search engines. Smoodly turns them into the page's metadata.
Turning it on
Add seo: true to a page type. Every page type in the starter has it:
export const pageSchema = smoodly.schema.page({
name: "page",
title: "Page",
// …
seo: true,
// …
});The tab appears in the inspector when nothing on the canvas is selected, before Settings.
The four fields
TitleUsed in search results and link previews. Empty means the page's own title. The counter turns amber past 60 characters and blocks nothing.DescriptionThe same, past 160 characters.Social imageFrom the media library; 1200 × 630 is recommended.Hide from search enginesA switch. On, the page asks search engines not to index or follow it.The values are content: they are saved as a draft, published with the page, and per language. A description edited on a draft does not reach the live page until the next publish, and an old version shows the description it was published with.
What the site emits
Every page type and entry page view receives head, and the layout hands it to Head from smoodly/astro/components inside <head>:
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Head of={head} fallback="Lorem Co." />
</head>For a page it writes the document title, the description, the Open Graph title, description, image and URL, the canonical link to the page's own address, and noindex when the switch is on. fallback titles a document Smoodly has no title for. A page type without seo: true still gets its page title; seo: true adds the tab and the rest on top.
Every page and entry gets its canonical link. On a multilingual site it also gets the hreflang links to the same page in the other languages. Language switcher and hreflang covers where they come from.
The links are absolute on site in astro.config.ts, which the starter reads from SITE_URL. Without site they are built from each request's own address, and the build warns. Set SITE_URL to your production address where you deploy: Deploying lists it with the other variables.
An entry gets its metadata the same way when its collection turns SEO on, described below. Without it, an entry page gets its canonical link and the language alternates only.
The route file hands metadata to Next through smoodlyMetadata, which the installer wires. The multilingual layout's catch-all route:
export async function generateMetadata({ params }: { params: Params }) {
const { locale, path = [] } = await params;
return smoodlyMetadata(path, { locale });
}For a page it sets the document title, the description, the Open Graph title, description, image and URL, the canonical link to the page's own address, and robots when the switch is on. The Open Graph image is served at 1200 pixels wide from the media bucket. What the tab leaves empty falls through to the defaults in your root layout. A page type without seo: true still gets its page title as the document title; seo: true adds the tab and the rest on top.
Every page and entry gets its canonical link. On a multilingual site it also gets alternates.languages, the hreflang links to the same page in the other languages. Language switcher and hreflang covers where they come from.
The links are absolute when your root layout sets metadataBase. Every starter sets it with metadataBase: siteUrl(), from smoodly: it reads SITE_URL, refuses a value without https:// by name, and falls back to http://localhost:3000 with a warning in production. Set SITE_URL to your production address when you deploy: Deploying lists it with the other variables.
An entry gets its metadata the same way when its collection turns SEO on, described below. Without it, an entry page gets its canonical link and the language alternates only.
SEO for entries
A collection can give its entries the same SEO & Social panel. Add seo to the collection:
import { f, smoodly } from "smoodly";
export const notes = smoodly.collection({
name: "notes",
title: "Notes",
titleField: "title",
path: "notes",
seo: { description: "excerpt", image: "cover" },
fields: {
title: f.text().localized(),
slug: f.slug({ from: "title" }),
excerpt: f.text().localized(),
cover: f.image(),
},
});seo: true adds the panel and falls an empty title back on titleField. The object form also names the fields that fill an empty description and an empty social image, so articles carry real metadata before anyone touches the panel; an editor's value in the panel still wins, and the switch hides one entry from search engines. The panel's hints say what an empty value falls back on.
The values are saved per language, in the draft, like the entry's other fields. Reads return them as seo, the effective values with the fallbacks applied, and the page head uses them.
An entry read with getLiveEntry("articles", { path, locale }) carries them as data.seo, and an entry page's entry.seo.
import { q } from "@/smoodly/server";
export async function articleDescription(id: string, locale: string) {
const article = await q().getEntry("articles", id, { locale });
return article?.seo?.description;
}$seo is reserved: a collection cannot declare a field of that name, and the panel's values never show up in fields.
Next, Collections.