Skip to content

Theme.Core

Nacara.Theme.Core is what any site builds its layouts on: the head, the shell, the shared script, the default tokens and the stylesheet that draws what plugins emit.

A site that writes its own layouts uses it directly. Theme.Docs and the themes are built on it.

Add it

Terminal
dotnet add package Nacara.Theme.Core --prerelease

A site with its own layouts

ThemeCore.register adds what a site that writes its own layouts needs: the code-block renderer, the behaviours script, the default tokens and the content stylesheet. ThemeCore.registerWith (ThemeCore.defaultTokens false) leaves the tokens out.

ThemeCore.tokensStylesheet registers the default tokens on their own.

A site with its own look builds one.

The shell

The pieces of a page every theme writes the same way.

FunctionWhat it renders
Head.meta modelCharset, viewport, title, description, canonical url, social cards, favicon
Head.ofContext title description contextThe same, resolved for the page a layout renders
Shell.stylesheetLinks siteA link to every stylesheet plugins contributed
Shell.scripts siteEvery script plugins contributed
Shell.skipLink className targetThe link that jumps past the navigation
Shell.untranslatedNotice pageThe note on a page standing in for a missing translation
Shell.generatedBy pageThe attribute naming the plugin that generated the page
Behaviours.bootstrapTag ()The inline script that settles the colour scheme before first paint
Behaviours.scriptTag siteThe deferred script tag of the shared behaviours

Pages and scope

A PageScope is the page, the site, and every page of the site. PageScope.ofContext builds one from the PageContext a layout is given.

FunctionWhat it returns
Head.resolve title description favicon scopeA HeadModel: the title, the description, the canonical url, the favicon. OgType is website on a home page and article elsewhere
Head.withImage site image modelThe model with the image shown on social sites. SocialImage.ofPath path makes one from a path relative to the site root, or an absolute url
Translations.resolve site pages pageA TranslationModel per locale: the page's version in it
Pages.section pageThe first segment of the page's route
Pages.ofSection scopeThe pages of the page's section, in front-matter order
Pages.find pages pathPageIndex.find of Nacara.Core
Links.resolve site pages urlPageIndex.link of Nacara.Core

Icons holds inline SVG icons.

Registration

ThemeCore.configureBase registers the code-block renderer and the behaviours script. A theme calls it from its own plugin. A documentation theme calls ThemeDocs.configure, which calls it.

ThemeCore.contentStylesheet registers the content styles as a stylesheet of its own, in the nacara.content layer, linked by Shell.stylesheetLinks. Use it when the content styles are not part of a bundle.

The code-block renderer is NacaraCodeBlockRenderer. Register your own ICodeBlockRenderer after it to replace its markup. See Code blocks.

Reference

Nacara.Theme.Core, module by module.

Edit this page