Page titles and SEO metadata
A merchant sets how their pages are titled and shared in Studio (Content → Theme and source, the Search and sharing (SEO) card): a title pattern and description for the whole site, per-context patterns for product, collection and category pages, a default share image and a Twitter handle. A page, or a route template, can override its own title and description, pick its own share image, set a canonical URL and opt out of search engines (noindex). @eldrajs/theme-nuxt reads the setting at build time and useEldraSeo writes the head.
Using it
// app/pages/[...slug].vue (the starter's version builds this input in app/utils/seoInput.ts)
useEldraSeo(
'catalog:product',
() => ({
'page.title': product.title,
'product.name': product.title,
'product.price': money.format(product.price),
}),
() => ({
entry: product.seo,
template: templateEntry.data.seo,
contentImage: product.images[0]?.url,
})
);A product, category, collection or brand carries the merchant's own seo value in the same shape a page does (contract 6.6.0: title, description, canonicalUrl, ogTitle, ogDescription, imageUrl, noindex). Pass it as entry: it then wins over the route template's value field by field, exactly as a page's own does. Only the page reads carry it, never a product card.
useEldraSeo(context, data, options?) takes refs or getters, so the tags follow the route. It sets <title>, description, <link rel="canonical">, og:title, og:description, og:type, og:site_name, og:locale, og:url, og:image, twitter:card, twitter:title, twitter:description, twitter:image, twitter:site and, for a page that must stay out of search, robots: noindex. It returns the resolved values. A tag whose value is empty is not written, and a canonical, og:url or og:image is written only when it is an absolute URL.
| Context | Variables the theme supplies (besides site.*) |
|---|---|
page | page.title, page.slug |
home | page.title |
catalog:product | product.name, product.price (formatted by the theme in the store's currency and locale), product.sku, product.shortDescription, product.category |
catalog:collection | collection.name, collection.description, collection.productCount |
catalog:category | category.name, category.description, category.productCount |
site.name, site.url and site.locale are filled in for every context. The registry is code-owned in Core (GET /seo/variables); a variable the theme does not supply renders empty.
Precedence
Per field, the first that is set wins: the page's own seo value, the route template's seo value, the site's pattern for this context, the site's pattern, then the page's own title (and the site name when even that is empty). The default title pattern is {{page.title}} · {{site.name}}, and the home page's is the site name alone. A page's own seo.title is a full override: variables work in it, but the site pattern does not wrap it. The share image falls back from the entry's own image to the content's own first image to the site's default. Every field of a locale map falls back from the exact locale to the same language to the site's default locale.
Substitution
Patterns are {{dot.path}} over strings and numbers ("syntax": 1). Substitution is one pass: a value is never scanned again, so a product named {{site.name}} shows those characters. An unknown or empty variable becomes empty, never literal braces. A title is then tidied: whitespace is collapsed and a separator (·, |, –, —, - standing alone between spaces) left leading, trailing or doubled by an empty variable is dropped, so {{page.title}} · {{site.name}} with no site name is just the page title, and a hyphen inside a word is untouched. This differs on purpose from the email renderer, which keeps unknown paths and swallows nearby whitespace and punctuation.
packages/theme-core/src/__tests__/fixtures/seo-vectors.json holds the pattern, data and expected title of every rule above. Core and Studio test against the same file; change a rule by changing the vectors first.
A page's or template's own seo value may also carry ogTitle and ogDescription (used for og:* and twitter:* only; each falls back to the page's title and description) and a share image: Core serves the resolved imageUrl beside imageAssetId in the entry read, and the kit reads the URL.
Which builds are indexed
A preview build is always noindex: anything built with ELDRA_BUILD_TARGET=preview (the module option buildTarget), nuxi dev, and any page framed by Studio. A build is production unless it says otherwise: an unset or empty ELDRA_BUILD_TARGET is production, and a value other than production or preview is warned about and counts as production. A production build writes robots only for a page that opts out. Set ELDRA_SITE_URL (the module option siteUrl) to the public origin: without it there is no canonical or og:url, because both must be absolute and a guessed host is worse than none. A relative image or canonical is resolved against it. When ELDRA_SITE_URL is unset, a production build reads the site's production URL from the platform (GET /site/v1/crawl, below).
Behaviour change. The default flipped: a build is production unless
ELDRA_BUILD_TARGET=preview(it used to be a preview unlessELDRA_BUILD_TARGET=production). A pipeline that only runsnuxi generatenow produces an indexable site, so a build that must not be indexed (a throwaway or staging build served on a host the edge router does not cover) setsELDRA_BUILD_TARGET=preview.nuxi devneeds nothing: it is always a preview. SetELDRA_SITE_URLfor the canonical,og:urland sitemap origin.
The preview host is protected by the edge router
A deployment is one static artifact, which the platform serves on the stable preview host (<org>.previews.eldra.dev, and the previews-staging / previews-dev equivalents) and, later, on the site's own domain. A build flag cannot be right for both, so the kit does not try: the preview host is protected by the edge router (site-deploy-worker's preview router), which sends X-Robots-Tag: noindex, nofollow and serves a disallow-all robots.txt for those hosts only. The kit writes no host rule of its own (the earlier _headers rule and the previewHosts module option are gone). The build target keeps deciding the page's own robots tag, canonical, robots.txt and sitemap, which is what nuxi dev and a local preview build rely on.
sitemap.xml, robots.txt and hreflang
nuxi generate writes robots.txt and sitemap.xml into the static output from the routes it prerendered, so neither can list a page that does not exist:
- Preview build (
ELDRA_BUILD_TARGET=preview):robots.txtisUser-agent: */Disallow: /and there is no sitemap, whatever the platform says about the site's URL. - Production build (the default):
robots.txtisUser-agent: */Allow: /, then the merchant's own lines (the platform'srobotsExtra, set in Studio), thenSitemap: <origin>/sitemap.xml.sitemap.xmllists every prerendered content path once per locale, each withxhtml:link rel="alternate" hreflangfor every locale andx-default(the unprefixed one), and<lastmod>where the entry or catalog record has anupdatedAt. - A page whose
seo.noindexis set is left out. Itsseo.canonicalUrlbecomes thelocwhen it is a plain URL on the site's own origin; a canonical on another host, or one that still holds a{(a{{pattern}}, or a{fieldId}template Studio stored unresolved), is ignored and the path-derived URL is used. Core serves a multi-locale entry'sseoalready merged to one locale, so the sitemap's canonicals (a plain string counts only on a single-locale site) and itsnoindexapply to the build locale's read: on a multi-locale site, setnoindexand canonicals per page in every locale or treat the sitemap as path-derived.useEldraSeostill writes each page's own canonical in its head. A catalog route uses the record's ownseofrom the list read, then the route template's: a category's and a collection's whole value, and a product card's two crawl members (noindexandcanonicalUrl), so a product hidden from search engines is left out. - Past 50,000 URLs or 50 MiB per file,
sitemap.xmlbecomes asitemapindexoversitemap-1.xml,sitemap-2.xml, ... (the module optionsitemap: { maxUrls, maxBytes }lowers the limits;sitemap: falseturns the sitemap off). Every locale counts, so a store's URL count is its page count times its locales. - The origin is
ELDRA_SITE_URL(the module optionsiteUrl), else the production URL the platform publishes. With neither, a production build writes neither file and prints one line saying so: a sitemap of relative URLs is invalid. - A
public/robots.txtorpublic/sitemap.xmlof the theme's own is never replaced; the build prints[eldra] <file> generation skipped: theme ships its owninstead. Do not ship either in a theme that should follow the merchant's settings.
The same origin makes the <link rel="alternate" hreflang> set in every page's head absolute (relative paths without it). Reading the crawl settings is a fail-soft platform read like the others: one warning, and the build goes on with no merchant lines.
Canonical URLs
seo.canonicalUrl is a {{variable}} pattern or a URL. A value that still contains a { or } after substitution (the single-brace {fieldId} form Studio's field editor lets an author type) is not a URL and counts as no canonical: the page's own path stands in. Shared vector: resolveSeo in packages/theme-core/src/__tests__/seo.spec.ts ("treats a stored {fieldId} canonical template as no canonical").
Structured data (JSON-LD)
Pages also carry schema.org JSON-LD, so a search engine can show a product as a product and a trail as a trail. The builders are framework-free and live in @eldrajs/theme-core (buildProductLd, buildBreadcrumbLd, buildItemListLd, buildOrganizationLd, buildWebSiteLd, and serializeLd); @eldrajs/theme-nuxt writes them into the head with useStructuredData, and the starter's usePageStructuredData says which nodes each page type gets:
| Page | Nodes |
|---|---|
| Home | Organization, WebSite (with a SearchAction to /search) |
| Product | BreadcrumbList, Product |
| Category, collection | BreadcrumbList, ItemList of the products shown (first page) |
| Any other page | BreadcrumbList |
Not found, any noindex page | nothing |
- Same data as the page. The
Productis built from the product the buy box renders: the variants' prices in the store's currency (rounded to that currency's own fraction digits, so ISK has none), each variant's stock state asavailability, and the compare-at price as a list price. One variant, or several at one price, is anOffer; different prices are anAggregateOfferwith oneOfferper variant. A sold-out product keeps its offer, markedOutOfStock. - Nothing made up. A value that is unset is left out, never written empty.
gtinis written only when the barcode is a valid GTIN-8/12/13/14 (check digit included). There is noAggregateRatinguntil real review data exists.priceValidUntilis not written until the platform has a sale schedule to give it.Product.brandis the shop's name: products carry no brand of their own. - Static HTML is a snapshot. The markup is in the prerendered file, so
availabilityis the stock at build time; it is not rewritten in the browser. Search engines re-crawl. - The shop's profile.
Organizationtakes its name, logo, social profile links (sameAs), contact and registered company (legal) from the platform's site profile (GET /site/v1/site-profile, an eighth fail-soft read: one warning and the build goes on). The name falls back to the site name, the logo to the site icon's 512 px rendering.OrganizationandWebSiteneed an absolute URL, so they are written only when the origin is known (siteUrl/ELDRA_SITE_URL); the other nodes fall back to relative URLs.legalis the organisation's legal details from Studio, present only for a company kennitala (a sole trader's are personal data), and absent from a platform before public contract 5.1.0, which reads asnull; the starter writes it aslegalName,taxIDandaddress.buildWebSiteLdalso takes analternateNamelist, which no platform read carries. - One
BreadcrumbListper page. The page-level builder owns it, so@eldrajs/ui'sBreadcrumbtakes:structured-data="false"(the starter'sbreadcrumbsblock does). Left at its defaulttrue, the component writes its own, as before. - Escaping.
serializeLdwrites<as a JSON escape, so a product called</script>cannot close the tag.
Opting out and editing. The module option eldra.structuredData takes { disable: true } (write none) or { disable: ['product', 'breadcrumb', 'itemList', 'organization', 'website'] }. It rides in the runtime config, so it cannot hold a function; to edit or drop a node call provideStructuredData((type, node, { path, locale }) => node | null) from a plugin. Both apply to every useStructuredData call, so a theme's own pages follow them too. Another theme on the same organisation is unaffected: the option is the theme's, the profile is the site's.
A theme that writes its own page markup calls useStructuredData([{ type, node }, ...], { enabled }) with nodes from the builders; pass enabled: !seo.noindex (from useEldraSeo) so a page kept out of the index carries no markup. One call per page: the head entry has a fixed key, so a second call replaces the first rather than adding a duplicate.
Failing soft
The read is one of the build's fail-soft platform reads (readSeo): no gateway client, an unreachable gateway, a timeout, an unknown pattern syntax or a response that is not the documented shape prints one warning ([eldra] could not read the platform's SEO settings) and the build goes on with the default pattern. Nothing breaks a deploy.
Adopting it in a theme
Replace the theme's own useHead({ title }) with useEldraSeo, and keep a not-found page out of the index by passing { entry: { title, noindex: true } }. The starter's seoInput() is a good starting point for the data of each context. The platform's site.name (from GET /site/v1/seo, always the resolved name: the merchant's own, else the site's name) is used first, for {{site.name}}, og:site_name, the structured data and the icon manifest. A theme's app.head.title is only the fallback when that read fails or is empty; otherwise there is none (never the package name) and titles are the bare page title.