Plugins
Every Nera plugin has the same anatomy. Open index.js and you see the
hooks; open src/config.js and you see the config keys and their defaults;
open the README and the sections come in the same order as in every other
plugin. This page describes that anatomy, for the official
@nera-static/plugin-* packages and for your own.
How a site uses plugins, and the hook contract itself, is in the plugins documentation.
Files
nera-plugin-<name>/
├── index.js # the hooks only: header comment, imports, exported hooks
├── src/
│ ├── config.js # the config reader: defaults, one reader per key, loadConfig()
│ ├── log.js # the package's logger: createLogger('plugin-<name>')
│ └── <feature>.js # pure functions, one concern per file
├── config/<name>.yaml # every key, with its default; `nera add` copies it
├── views/ # only with templates: flat <template>.pug, plus partials/ and helper/
├── assets/ # only when getAssets ships static files (served under public/_nera/)
├── bin/publish-template.js # only with views/
├── test/ # see the Tests page of this guide
├── README.md CHANGELOG.md LICENSE package.json package-lock.json
├── eslint.config.js .editorconfig .gitignore
├── .husky/ # pre-commit: npm run lint, pre-push: npm run lint && npx vitest run
└── .github/ # workflows/test.yml, workflows/publish.yml, dependabot.yml, FUNDING.yml
- A plugin has no
src/warn.jsand nosrc/guard.js. The warning format and the core version guard come from@nera-static/plugin-utils(/logand/guard, from version 1.7.0), so they cannot drift. config/<name>.yamllists every key, set or commented out, with its default. It is whatnera add <name>copies into a site, so a plugin has nobin/publish-config.js.bin/publish-template.jsexists only when the plugin hasviews/. It callspublishAllTemplatesfrom@nera-static/plugin-utils.
The hooks
index.js holds the hooks and nothing else. Everything a hook does beyond
reading its input and returning its output lives in src/.
// @nera-static/plugin-example — adds a list of related pages to every page.
//
// getAppData checks the core version and adds app.example, getMetaData adds
// meta.related to every page, getAssets ships the default styles.
import { fileURLToPath } from 'node:url'
import { assertCoreVersion } from '@nera-static/plugin-utils/guard'
import { loadConfig } from './src/config.js'
import { log } from './src/log.js'
import { relatedPages } from './src/related.js'
export function getAppData({ app = {}, pagesData = [] } = {}) {
assertCoreVersion({ plugin: 'plugin-example', from: import.meta.url })
return { ...app, example: { count: pagesData.length } }
}
export function getMetaData({ app = {}, pagesData = [] } = {}) {
const config = loadConfig({ app })
return pagesData.map((page) => ({
...page,
meta: { ...page.meta, related: relatedPages(page, pagesData, config, { onWarning: log.warn }) },
}))
}
export function getAssets({ app = {}, pagesData = [] } = {}) {
return [{ from: fileURLToPath(new URL('./assets/example.css', import.meta.url)), to: '_nera/example.css' }]
}
The rules:
- Destructure with defaults:
({ app = {}, pagesData = [] } = {}). Never(data)withdata.app. - Export each hook with
export function, never throughexport { … }. - Synchronous unless the hook really has to wait. Core awaits every hook, but a synchronous one is easier to test and to reason about.
- Read the config inside the hook through
loadConfig({ app }), never at module scope. Then a test can run the hook against a site in a temporary folder. - Return a new value.
getAppDatareturns a new plain object,getMetaDataa new array of new page objects. Never change the input. - The guard runs in
getAppData, the first hook core calls, and only in a plugin that hasgetAssets. Core older than 4.13.0 never callsgetAssets, and the build would still exit 0;assertCoreVersionturns that into an error. Such a plugin also declares"peerDependencies": { "@nera-static/core": ">=4.13.0" }. - Files go through
getAssets. Core deletespublic/after the plugins have run, so whatever a plugin writes there directly is lost. A plugin's files are served under_nera/<name>.*.
Config
src/config.js describes the config file once: its defaults and one reader
per top-level key. createConfigReader from
@nera-static/plugin-utils/config does the rest: it copies the defaults,
skips empty keys, ignores unknown ones and prints the warnings.
import { createConfigReader, loadPluginConfig } from '@nera-static/plugin-utils/config'
import { isText } from '@nera-static/plugin-utils/values'
import { log } from './log.js'
const reader = createConfigReader({
file: 'config/example.yaml',
defaults: { heading: 'Related pages', limit: 3 },
readers: {
heading: (value, current, r) => (isText(value) ? value.trim() : r.bad('heading', value, current)),
limit: (value, current, r) => (Number.isInteger(value) && value > 0 ? value : r.bad('limit', value, current)),
},
warn: log.warn,
})
export function loadConfig({ cwd = process.cwd(), app } = {}) {
return reader.normalize(loadPluginConfig('example', { cwd, app }))
}
loadPluginConfig(name, { cwd, app })reads the site'sconfig/<name>.yaml, or the folderapp.folders.confignames. Pass theappyour hook receives.reader.normalize(raw)returns a fresh copy of the defaults with each valid key replaced. A missing file gives the defaults without a word; a key left empty in YAML keeps its default.- Every key has a reader, and a reader either returns the checked value
or calls
r.bad(key, value, fallback),r.ignore(where, what)orr.unknown(where, key). A key without a reader is reported as unknown. - The shipped
config/<name>.yamlequals the defaults. A test parses it and compares it withreader.defaults().
Warnings and errors
src/log.js creates the package's logger once:
import { createLogger } from '@nera-static/plugin-utils/log'
export const log = createLogger('plugin-example')
Every message a plugin prints goes through it, so a site owner can tell from the build log where a message came from:
⚠️ plugin-example: config/example.yaml: expected a mapping at the top level, using defaults
⚠️ plugin-example: config/example.yaml: ignoring unknown key "limits"
⚠️ plugin-example: config/example.yaml: invalid limit 0, using 3
⚠️ plugin-example: /blog/first.html: no date — add `date:` to its frontmatter
log.warn(message)prints⚠️ plugin-<name>: <message>. The config messages above come from the config reader; do not write your own.log.page(page, what, todo)warns about one page:<page>: <what> — <todo>. Say what is wrong and what to do about it.log.info(message)printsℹ️ plugin-<name>: <message>, for a rare summary line.- No bare
console.*in a plugin's runtime code.nera-stanrefuses it (rulenera/shared-logger, from version 1.0.0). - An error that should stop the build is thrown, not logged:
throw new Error('plugin-<name>: …'), with the same prefix and no emoji, asassertCoreVersiondoes:
plugin-example: @nera-static/core 4.12.0 is too old; it needs >= 4.13.0 (the getAssets hook). Update with `npm update @nera-static/nera` (or `@nera-static/core`).
Feature modules in src/ do not import the logger. They take an
onWarning callback, as relatedPages does above, so they stay pure
functions and a test can collect their warnings.
Templates
- Views are flat:
views/<template>.pug, with subfolders only forpartials/andhelper/. - A site gets them through
npm run publish-template(andnera add), which copies them toviews/vendor/plugin-<name>/. - The markup and the BEM class names are a public contract. Sites hold
copies of the templates and style the classes from their own CSS, so
renaming
.tag-cloud__itembreaks them: that is a major release. - Default styles use custom properties named
--nera-<name>-*, as--nera-code-*inplugin-code-blocks. See Themes and starters for the full prefix rule.
package.json
The keys come in this order. Leave out what does not apply.
{
"name": "@nera-static/plugin-example",
"version": "1.0.0",
"description": "A plugin for the Nera static site generator that adds related pages.",
"main": "index.js",
"type": "module",
"exports": { ".": "./index.js" },
"bin": { "nera-example": "bin/publish-template.js" },
"scripts": {
"publish-template": "node ./bin/publish-template.js",
"lint": "nera-stan",
"test": "vitest run",
"test:watch": "vitest",
"prepare": "husky"
},
"files": ["bin", "config", "index.js", "src", "views", "assets", "CHANGELOG.md"],
"keywords": ["nera", "nera-plugin", "static-site-generator", "related-pages"],
"author": "Michael Becker",
"license": "MIT",
"repository": { "type": "git", "url": "git+https://github.com/seebaermichi/nera-plugin-example.git" },
"bugs": { "url": "https://github.com/seebaermichi/nera-plugin-example/issues" },
"homepage": "https://github.com/seebaermichi/nera-plugin-example#readme",
"publishConfig": { "access": "public" },
"sideEffects": false,
"engines": { "node": ">=22.12.0" },
"peerDependencies": { "@nera-static/core": ">=4.13.0" },
"dependencies": { "@nera-static/plugin-utils": "^1.7.0" },
"devDependencies": { "@nera-static/core": "^4.15.1", "@nera-static/stan": "^1.0.0", "husky": "^9.1.7", "vitest": "^5.0.0" }
}
binand thepublish-templatescript only withviews/;viewsandassetsinfilesonly when the folders exist.CHANGELOG.mdis always infiles.peerDependencieson core only for a plugin withgetAssets(and so with the guard).engines.nodeis core's floor.keywordsalways includenera,nera-pluginandstatic-site-generator, never the genericplugin.- Write
package.jsonthe waynpm pkg fixleaves it:binpaths without a leading./,repository.urlwith thegit+prefix.
README
The sections come in this order. Leave out the optional ones that do not apply, and add no others between them.
# @nera-static/plugin-example
[](…/actions/workflows/test.yml)
[](https://www.npmjs.com/package/@nera-static/plugin-example)
A plugin for the [Nera](https://nera.js.org) static site generator that …
## ✨ Features
## 🚀 Installation nera add example, then npm install … as the manual path
## 🧩 Usage a minimal working example
## ⚙️ Configuration a key | default | meaning table, then the full shipped YAML
## <feature sections> plain headings without emoji, e.g. "Multilingual sites"
## 🛠️ Template Publishing only with views/
## 🎨 Styling only with views/: the BEM classes are the public contract
## 📊 Generated Output the exact app.<key> / meta.<key> shape
## ⚠️ Warnings optional: the messages and what to do about them
## Known limitations optional
## 🧩 Compatibility core floor, Node floor, plugin order (start: / end:)
## 🧪 Development
## 🤝 Contributing one line linking the shared contributing guide
## 📦 License
- A plugin with the core guard says so right under the first paragraph:
Requires @nera-static/core 4.13.0 or later, linked to Compatibility. - The README is the public spec. Everything a user needs, such as a
markup contract, is written there. Never link a
ROADMAPfile: it is local only and the link would end in a 404. - No
Authorand noLinkssection:package.jsonalready carries both.
CHANGELOG
Every plugin keeps a CHANGELOG.md in the
Keep a Changelog format:
## [2.0.0] - 2026-11-27
### Changed
- **BREAKING**: `app.example` is now `app.related`.
### Migration from v1.x
- Replace `app.example` with `app.related` in your templates.
- One heading per release,
## [x.y.z] - YYYY-MM-DD, newest first. - Only the groups
### Added,### Changed,### Fixedand### Removed. - Bullets are written
- …, a dash and three spaces, so the text starts in column 4. - A breaking entry starts with
**BREAKING**:, and a major release has a### Migration from vX.xsection with the before and after. - The version bump and the CHANGELOG entry go in the same commit as the change, not at release time.
What counts as what:
- Major — a hook's return shape, a renamed or removed config key or a
default with a new meaning, a renamed
app.<key>ormeta.<key>, changed template markup or BEM classes, a higher core floor. - Minor — a new config key with a sensible default, a new template, a new
app.<key>beside the existing ones, a higher Node floor documented as the real one. - Patch — a bugfix with the same output shape, README and internal changes.
- No release — a
package-lock.jsonrefresh, devDependency bumps, CI, husky or lint configuration.