Schema reference

Field roles and alt text

Say which field is a page's SEO title (and how the site composes it), meta description, share image, noindex and draft switches and canonical address, and where each image's alt text is.

Not verified yet

A role says what a field means to your site, not how it is edited. The CMS reads roles to know which field holds a page's search title, its meta description or an image's alt text, without guessing from field names. They are answered with the site's schema, so Norcube AI reads the same declaration.

You declare a role once, on the field, in a collection, a block or an input:

# .norcube/cms/blocks/seo.yml
label: SEO
fields:
  - key: page_title
    type: text
    label: Meta title
    role: seoTitle
    recommendedLength: { from: 30, to: 60 }
  - key: page_description
    type: paragraph
    label: Meta description
    role: seoDescription
    recommendedLength: { from: 70, to: 160 }
  - key: featured_image
    type: image
    label: Share image
    role: shareImage
    alt: featured_image_alt # the field next to it that holds its alt text
  - key: featured_image_alt
    type: text
    label: Share image description
  - key: canonical_url
    type: link
    label: Canonical URL
    role: canonical
  - key: no_index
    type: boolean
    label: Hide from search engines
    role: noindex
  - key: draft
    type: boolean
    label: Draft
    role: draft

A collection that pulls this block in with $ref: seo has all six page roles.

The roles

RoleThe field holdsField types
seoTitleThe page's title in search results and the browser tab.text, paragraph
seoDescriptionThe page's meta description, the snippet under the title.text, paragraph, richtext with excerpt
shareImageThe image shown when the page is shared on social networks.image
noindextrue hides the page from search engines.boolean, select with noindexWhen
canonicalThe address that should rank instead of this page.link, text
drafttrue means the page is not published yet.boolean, select with draftWhen
altThe alt text of the image next to it (see below).text, paragraph
noneNothing: the field has no role and is never guessed to have one.any

The first six are page roles: a collection has at most one field for each, counting the fields of every block it pulls in by $ref and the fields inside groups. A page role never sits inside a list (an array's items, or a block used as a list item), because a list repeats per item and a page has one title.

A localized group (a group that holds every language of a text in one file) takes the role of its language fields' type, and the role then holds per language.

A page's own title, description or image (a top-level title, a hero heading) needs no role. Give seoTitle to the field that holds the search title when it differs from the page title; when there is none, leave the role out.

A select for noindex or draft

A site that keeps its robots directive or its workflow state in a select says which of the select's values switch the role on, with noindexWhen or draftWhen:

- key: robots
  type: select
  label: Search engine indexing
  role: noindex
  noindexWhen: ['noindex,follow', 'noindex,nofollow'] # quoted: a comma splits a flow list
  options: ['index,follow', 'noindex,follow', 'noindex,nofollow']
- key: state
  type: select
  label: State
  role: draft
  draftWhen: [writing, review]
  options: [writing, review, published]

Every entry must be one of the select's options, each listed once, 1 to 100 of them. There is no default: a select with the role and no list is an error, because only you know which values hide a page or keep it unpublished. A boolean needs no list (true switches the role on), and the list goes on no other field. Quote a value that holds a comma: in a YAML flow list, [noindex,follow] is two entries, noindex and follow.

What a draft changes. role: draft marks your site's own field that says a page is not published yet. It is not the CMS's unpublished changes, which are a separate thing. A draft page is not checked for search and accessibility in content health, and it does not count as a language version of its page.

A title the site composes

Many sites build the page title in their code instead of showing the field as it is: <title>{title} – Studio Nord</title>. Say how with titleTemplate: next to role: seoTitle, and content health measures the title the site shows, not the field alone:

- key: title
  type: text
  label: Title
  role: seoTitle
  titleTemplate: '{value} – {{site_name}}'
PlaceholderIs
{value}The field's own text, in the page's language. Required.
{field:<key>}Another field of the page, outside lists (a.b reaches into a group). A localized group in the page's language; a list of choices joined by commas.
{field:<key>|label}A select's option label in the page's language: the option's labels.<language>, else its label, else its value.
{{key}}A site variable, in the page's language.

A select's options can carry their label per language in labels, next to the label the editor shows:

- key: kind
  type: select
  label: Kind
  options:
    - value: painting
      label: Malba
      labels: { cs: Malba, en: Painting, it: Pittura }
    - value: drawing
      label: Kresba
      labels: { cs: Kresba, en: Drawing, it: Disegno }

With titleTemplate: '{field:kind|label} – {value} – {{site_name}}', the English page of a painting called "Morning fog" has the title "Painting – Morning fog – Studio Nord" (when the site variable site_name is Studio Nord). Each labels entry must be one of the site's languages (preview.locales).

What makes a template an error:

  • it has no {value}, is longer than 300 bytes, or uses a brace that is not one of the placeholders above (so a typo never passes as text);
  • it sits on a field without role: seoTitle;
  • {field:<key>} names a field the page does not have, a list, or a group that is not localized, or |label asks for the label of a field that is not a select or multichoice. It is judged in the collection, so a template in a block names the fields of each page that uses it.

A variable your site does not define is not an error (variables are content), but a title that uses one is not measured. Templates are for titles only: a site rarely composes its description, and the common case, the first paragraph of a text, is excerpt below.

A description from rich text

When the meta description is the first paragraph of the page's text, give the rich text field the role and say so with excerpt:

- key: intro
  type: richtext
  label: Introduction
  role: seoDescription
  excerpt: firstParagraph

firstParagraph is the only value: the plain text of the first paragraph. Headings and code blocks are skipped, bold, italics and link marks are removed (a link keeps its text); in HTML rich text it is the first <p>. A rich text field with role seoDescription needs excerpt, and excerpt goes on no other field. A rich text field is never guessed to be the description.

Roles on a group of languages

A site that keeps every language of a page in one file holds each text in a localized group, one field per language (see Languages in one file). The role goes on the group, never on its language fields, and means each language:

# .norcube/cms/collections/works.yml (excerpt)
- key: title
  type: group
  label: Title
  localized: true
  fallback: cs
  role: seoTitle
  titleTemplate: '{value} – {{site_name}}'
  fields:
    - { key: cs, type: text, label: Czech }
    - { key: en, type: text, label: English }
    - { key: it, type: text, label: Italian }

Here the Czech page's title is title.cs, the English page's title.en, each composed by the template in its own language. A localized group of rich text fields takes role: seoDescription with excerpt the same way. A group that is not localized holds no page role.

Alt text for images

Every image field can say where its alt text is, in one of these ways.

alt: on the image names the field next to it, in the same fields list (the same group or list item), that holds the text. It is a key, not a path: a field in another group cannot be named.

- key: image
  type: image
  label: Image
  alt: imageAlt
- key: imageAlt
  type: text
  label: Image description

role: alt on a text field marks it as the alt text of the one image in its fields list. It suits an "image object", a group or list item made of an image and the text that describes it, such as a client logo and the client's name:

- key: logos
  type: array
  label: Logos
  items:
    - key: logo
      type: group
      label: Logo
      fields:
        - key: img
          type: image
          label: Logo
        - key: name
          type: text
          label: Client name
          role: alt

alt: { from: [...] } on the image composes the alt text from fields next to it, the way your site's code does (alt={`${title} – ${technique}`}):

- key: image
  type: image
  label: Image
  alt: { from: [title, technique], separator: ' – ' }

The parts that are not empty are joined by separator (a space when it says none); the alt text is empty when every part is. It takes 1 to 10 parts and a separator of at most 20 bytes, and content health checks the joined text.

decorative: true on the image says it needs no alt text: a background, a pattern, an ornament.

- key: background
  type: image
  label: Background
  decorative: true

A field named by alt: or listed in from is a text or paragraph field, or a localized group of them: the alt text is then per language, so each language's page has its own.

alt and decorative belong on image fields only. An image is either decorative or has alt text, never both.

Values the site fills in code

Some sites fill an empty role field themselves. A site may render a 1200 x 630 share card for every page at build time, compose a title from the page heading, or fall back to one description for the whole site. Say so with whenEmpty: next to role:, and content health stops reporting those empty fields as missing:

# .norcube/cms/blocks/seo.yml
fields:
  # The site renders a share card per page (src/pages/og/[...path].png.ts)
  # when the editor picks no image.
  - key: og_image
    type: image
    label: Share image
    role: shareImage
    whenEmpty: generated
  # The layout falls back to the site's default description.
  - key: description
    type: paragraph
    label: Meta description
    role: seoDescription
    whenEmpty: siteDefault
ValueMeans
generatedThe site makes the value for each page in code, such as a share card per page.
siteDefaultThe site falls back to one value for the whole site, such as a default og image.

whenEmpty goes only on a field with role seoTitle, seoDescription or shareImage:

  • Not on alt. Alt text describes one particular image, and code can't write it reliably: a copied title or file name is worse for a screen reader than an honest gap. An image that needs no alt text is marked decorative: true instead.
  • Not on noindex or canonical. Their empty value already means something (the page is indexed, and is canonical to itself), and no check reports it.

It states what your site's code does, so the CMS never guesses it: a role guessed from a field name never has it, and Generate schema does not write it. Values an editor does fill in are still checked for length and duplicates. On the Content health page, The site fills these on a missing title, description or share image issue writes it for you (with the field's role), after showing the lines.

An empty SEO title already falls back to the page's own title in the checks. Add whenEmpty to the seoTitle field only when your site shows something else (a title it composes, or one for the whole site): the page title is then not measured in its place. A siteDefault description is the same text on every page that leaves the field empty, so search engines may pick their own snippet there; writing one for your most important pages is still worth it.

When the schema says nothing

Sites written before roles still get answers: when no field declares a role, the CMS guesses it from field keys and labels. Each answer says whether it was declared or guessed, and a declared role always wins over a guess.

Keys and labels are compared in lower case with everything but letters and digits removed, so meta_title, metaTitle and "Meta title" are the same name. Only fields outside lists, of a type the role accepts and declaring no role of their own, are candidates, and two candidates for one role guess nothing.

RoleKey anywhereLabelKey directly inside an SEO group
seoTitleseo_title, meta_title, page_titleSEO title, Meta titletitle
seoDescriptionseo_description, meta_description, page_descriptionSEO description, Meta descriptiondescription
shareImageshare_image, social_image, og_image, open_graph_image, featured_image, seo_image, meta_imageShare image, Social image, OG image, Open Graph imageimage
noindexnoindex, no_index, hide_from_search, hide_from_search_engines; a select robots, meta_robotsNo index, Hide from search engines, Robots, Meta robots
canonicalcanonical, canonical_url, canonical_linkCanonical, Canonical URL, Canonical link
draftdraft, is_draft (a boolean)Draft

An SEO group is a group whose key, or the block it was pulled in from, is seo, meta or metadata. A top-level title, description or image is the page's own and is never guessed as a search field. A robots or meta robots select is guessed as the noindex switch only when some of its options carry the directive noindex (or none), and those options are then the guessed noindexWhen. A rich text field is never guessed to be the description, and titleTemplate, excerpt and localized are never guessed: they state what your site does.

Confirming or rejecting a guess

You don't have to write these by hand. On the Content health page, Guessed fields lists every field whose role was guessed, with The guess is right (writes its role:), Not right (pick the role it really holds, or Not a search field) and Confirm all. Each shows the exact lines first and writes them in one commit, keeping the rest of the file as it is.

Saying a field has no role

A field whose name looks like a search field but isn't (a meta.title that is a heading on the page, say) is guessed anyway. Say it holds no role, and the guess stops:

- key: title
  type: text
  label: Title
  role: none

role: none goes on any field, any number of times, also inside lists, and takes no whenEmpty. It also keeps the field from being guessed as an image's alt text. Not a search field on the Content health page writes it for you.

Alt text guesses

An image's alt text is guessed from a text or paragraph field next to it that declares no role, in this order: <key>_alt or <key>Alt (also <key>_alt_text); then, when the image is the only one in its fields list, alt, alt_text or alternative_text; and failing those, name. Two fields that fit one step guess nothing.

What validation reports

These are errors in the editor's site check and in nrc cms validate:

RuleReported when
schema.unknown_rolerole is not one of the seven roles or none.
schema.role_type_mismatchThe field's type cannot hold its role, such as shareImage on a text field or noindex on a multichoice, or a group that is not localized has a page role.
schema.duplicate_roleA second field of the collection or block has the same page role, or a second role: alt sits in one fields list.
schema.misplaced_roleA page role sits inside a list, or role: alt sits in a fields list with no image.
schema.invalid_altalt (or an entry of alt.from) names no text or paragraph field, or localized group of them, next to the image; alt.from lists no field, more than 10 or one twice, or the separator is over 20 bytes; decorative is not true or false or comes with alt text; or role: alt sits beside several images, a decorative one, or one that names another field.
schema.invalid_when_emptywhenEmpty is not generated or siteDefault, sits on a field without a role, or on a role other than seoTitle, seoDescription and shareImage (none included).
schema.invalid_title_templateA titleTemplate that does not parse, has no {value}, sits on a field without role: seoTitle, or names a field the page does not have.
schema.invalid_excerptA rich text field with role seoDescription and no excerpt, a value other than firstParagraph, or excerpt on any other field.
schema.invalid_role_valuesA select with role noindex or draft has no noindexWhen or draftWhen, the list is empty, longer than 100, repeats a value or names one that is not an option, or the key sits where nothing reads it.
schema.invalid_localizedA localized group breaks the rules in Languages in one file, or an option's labels names a language the site lacks.

A block is checked in its own file and again where it is used, so a block whose roles are fine on their own but which is used as a list item is reported at the collection.

The roles are also what content health reads to check titles, descriptions, share images and alt text, to know which pages are hidden from search engines, and to leave drafts out. To run those checks from a checkout too, add --quality to nrc cms validate (see From the command line).

Generate schema writes roles and alt text into the schemas it proposes, so a new site starts with them declared.

On this page