@nera-static/mcp 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +2 -2
- package/CHANGELOG.md +14 -0
- package/bin/nera-mcp.js +13 -7
- package/docs/llms-full.txt +1219 -31
- package/package.json +29 -18
- package/skills/nera/SKILL.md +3 -0
- package/skills/nera/recipes/blog.md +9 -5
- package/src/catalog.js +1 -1
- package/src/hosted/app.js +4 -2
- package/src/hosted/checkout.js +46 -56
- package/src/hosted/config.js +12 -8
- package/src/hosted/consent.js +28 -23
- package/src/hosted/crypto.js +2 -1
- package/src/hosted/github.js +6 -3
- package/src/hosted/mcp.js +3 -3
- package/src/hosted/provider.js +13 -6
- package/src/hosted/repo.js +30 -16
- package/src/hosted/store.js +25 -7
- package/src/hosted/tools/publish.js +43 -17
- package/src/hosted/tools/read.js +31 -16
- package/src/hosted/tools/validate.js +10 -3
- package/src/hosted/tools/write.js +28 -9
- package/src/pages.js +21 -18
- package/src/paths.js +11 -18
- package/src/prompts.js +33 -15
- package/src/resources.js +7 -3
- package/src/runner.js +13 -11
- package/src/server-info.js +11 -0
- package/src/server.js +14 -4
- package/src/tools/cli.js +40 -22
- package/src/tools/files.js +14 -7
- package/src/tools/long-running.js +12 -31
- package/src/tools/sites.js +10 -8
package/docs/llms-full.txt
CHANGED
|
@@ -361,9 +361,10 @@ npx @nera-static/nera new <project-name>
|
|
|
361
361
|
|
|
362
362
|
`nera new .` scaffolds into the current, empty folder instead, and
|
|
363
363
|
`--theme <name>` starts the site from a theme. `--starter <name>` starts it
|
|
364
|
-
from a ready-to-edit starter kit instead (`blank`, `blog`,
|
|
365
|
-
`portfolio`; not together with `--theme`),
|
|
366
|
-
`--lang <code>` set `name` and `lang` in
|
|
364
|
+
from a ready-to-edit starter kit instead (`ansitz`, `blank`, `blog`,
|
|
365
|
+
`business`, `portfolio`, `stack` or `umwege`; not together with `--theme`),
|
|
366
|
+
and `--name "<site name>"` and `--lang <code>` set `name` and `lang` in
|
|
367
|
+
`config/app.yaml`:
|
|
367
368
|
|
|
368
369
|
```bash
|
|
369
370
|
npx @nera-static/nera new my-blog --starter blog --name "My Blog" --lang de
|
|
@@ -491,8 +492,8 @@ shows a raw translation key.
|
|
|
491
492
|
|
|
492
493
|
`--starter` takes:
|
|
493
494
|
|
|
494
|
-
- a starter name: `blank`, `blog`, `business
|
|
495
|
-
`@nera-static/starter-
|
|
495
|
+
- a starter name: `ansitz`, `blank`, `blog`, `business`, `portfolio`, `stack`
|
|
496
|
+
or `umwege`, short for `@nera-static/starter-ansitz` and so on;
|
|
496
497
|
- a package name: `@acme/starter-shop`, or unscoped `nera-starter-shop`;
|
|
497
498
|
- a GitHub URL: `https://github.com/owner/repo` (optionally `.git`, `#ref`),
|
|
498
499
|
or `github:owner/repo#ref`;
|
|
@@ -523,14 +524,36 @@ default. Every question has a flag (`--starter`, `--name`, `--lang`); with
|
|
|
523
524
|
`--yes`, or without a terminal (scripts, CI, AI agents), nothing is asked and
|
|
524
525
|
`nera new` scaffolds the base template.
|
|
525
526
|
|
|
527
|
+
`--starter blog` on a terminal asks one question, which blog:
|
|
528
|
+
|
|
529
|
+
```text
|
|
530
|
+
Which blog?
|
|
531
|
+
1) Blog (blog)
|
|
532
|
+
2) Blog for developers (stack)
|
|
533
|
+
3) Photo blog (ansitz)
|
|
534
|
+
4) Travel blog (umwege)
|
|
535
|
+
Choose 1–4 [1]:
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
Enter takes the plain blog, `@nera-static/starter-blog`; a number or a name
|
|
539
|
+
picks another. With `--yes`, or without a terminal, `--starter blog` is the
|
|
540
|
+
plain blog without asking. `--starter stack`, `ansitz` or `umwege` chooses
|
|
541
|
+
one of the other three directly.
|
|
542
|
+
|
|
526
543
|
The official starters:
|
|
527
544
|
|
|
528
|
-
| Starter | What you get |
|
|
529
|
-
| --- | --- |
|
|
530
|
-
| `
|
|
531
|
-
| `
|
|
532
|
-
| `
|
|
533
|
-
| `
|
|
545
|
+
| Starter | What you get | Demo |
|
|
546
|
+
| --- | --- | --- |
|
|
547
|
+
| `ansitz` | A photo blog on `@nera-static/theme-ansitz` with photographs, a series, tags, an archive, search, an Atom feed and a sitemap | [Ansitz](https://nera.js.org/themes/blog/ansitz/) |
|
|
548
|
+
| `blank` | One accessible layout, no theme | — |
|
|
549
|
+
| `blog` | A blog on `@nera-static/theme-blog` 2.x with a series, tags, an archive by year, search, an Atom feed and a sitemap | [Plain](https://nera.js.org/themes/blog/plain/) |
|
|
550
|
+
| `business` | A small-business site on `@nera-static/theme-business` with services, opening hours and a contact form | — |
|
|
551
|
+
| `portfolio` | A designer's portfolio on `@nera-static/theme-business` with projects in image galleries, an about page and a contact form | — |
|
|
552
|
+
| `stack` | A blog for developers on `@nera-static/theme-stack` with two series, highlighted code, tags, an archive, search, an Atom feed and a sitemap | [Stack](https://nera.js.org/themes/blog/stack/) |
|
|
553
|
+
| `umwege` | A travel blog on `@nera-static/theme-umwege` with trip facts, places, a series, photographs, tags, an archive, search, an Atom feed and a sitemap | [Umwege](https://nera.js.org/themes/blog/umwege/) |
|
|
554
|
+
|
|
555
|
+
The [themes page](https://nera.js.org/themes/index.html) shows every theme these starters use,
|
|
556
|
+
with a screenshot, its starters and a link to its README.
|
|
534
557
|
|
|
535
558
|
### Checking the built site
|
|
536
559
|
|
|
@@ -892,6 +915,1050 @@ with the files I need to create and their content.
|
|
|
892
915
|
Planned, not available yet: a **hosted connector** for claude.ai and ChatGPT
|
|
893
916
|
that works on your GitHub repository, with no local install.
|
|
894
917
|
|
|
918
|
+
# Style guide
|
|
919
|
+
|
|
920
|
+
Source: https://nera.js.org/docs/style-guide/index.html
|
|
921
|
+
|
|
922
|
+
Nera is many small packages: the engine `@nera-static/core`, the CLI
|
|
923
|
+
`@nera-static/nera`, the validator, the MCP server, some twenty plugins, the
|
|
924
|
+
themes and the starters. Each of them should read like the others. Open any of
|
|
925
|
+
them and you recognise Nera at a glance; only the feature differs. This style
|
|
926
|
+
guide writes down that **one handwriting**, for everyone who contributes to a
|
|
927
|
+
Nera package or writes a plugin, theme or starter of their own.
|
|
928
|
+
|
|
929
|
+
You do not need it to build a site. For that, start with the
|
|
930
|
+
[documentation](https://nera.js.org/docs/index.html).
|
|
931
|
+
|
|
932
|
+
## The principle
|
|
933
|
+
|
|
934
|
+
- **A generic helper exists once, in a shared package.** Checking for a plain
|
|
935
|
+
object, reading a plugin's config, printing a warning, guarding the core
|
|
936
|
+
version, joining a page URL, parsing a page date: none of this is written
|
|
937
|
+
again inside a plugin, theme, starter or tool. It comes from
|
|
938
|
+
`@nera-static/plugin-utils`. **No copies** — not in core, the CLI, the
|
|
939
|
+
validator or the MCP server either, and not as a commented copy "from
|
|
940
|
+
plugin-sitemap".
|
|
941
|
+
- **The same goes for the shape of a package.** A plugin, a theme and a
|
|
942
|
+
starter each have one layout: the same files in the same places, the same
|
|
943
|
+
hook shape, the same `package.json` key order, the same README outline, the
|
|
944
|
+
same way of writing tests.
|
|
945
|
+
- **Where a rule cannot be kept by hand, a tool enforces it.** Every Nera
|
|
946
|
+
repository runs the same checks in `npm run lint`, so CI refuses what breaks
|
|
947
|
+
them.
|
|
948
|
+
- **An unexplained variant is a defect.** If your package does something
|
|
949
|
+
differently from its siblings, either the guide allows it, or the difference
|
|
950
|
+
carries a comment that says why. Otherwise it is fixed like a bug.
|
|
951
|
+
|
|
952
|
+
## Why it matters
|
|
953
|
+
|
|
954
|
+
Every Nera package used to be started by copying a sibling of the same kind.
|
|
955
|
+
Copies drift: one plugin fixed its date parser, the next one kept the old
|
|
956
|
+
bug, a third one rewrote it with other rules. The result was dozens of copies
|
|
957
|
+
of the same helpers in several variants, and bugs that one fix in one place
|
|
958
|
+
would have removed everywhere. "Copy a sibling" is no longer the instruction.
|
|
959
|
+
This guide and the shared packages are.
|
|
960
|
+
|
|
961
|
+
A new repo starts from the canonical templates instead:
|
|
962
|
+
`node scripts/new-repo.js <plugin|theme|starter|tool> <name>` in the
|
|
963
|
+
[generator repo](https://github.com/seebaermichi/nera) writes the full file
|
|
964
|
+
set of its kind (package.json, lint, tests, workflows, README outline), and
|
|
965
|
+
the result passes `nera-stan` on its first commit. The steps are in
|
|
966
|
+
[Starting a new repository](https://github.com/seebaermichi/nera/blob/main/CONTRIBUTING.md#-starting-a-new-repository).
|
|
967
|
+
|
|
968
|
+
## Where the shared code lives
|
|
969
|
+
|
|
970
|
+
- **`@nera-static/plugin-utils`** holds every generic runtime helper, one
|
|
971
|
+
subpath per family. From version 1.7.0 on: `/values` (plain objects, text
|
|
972
|
+
values), `/config` (reading and normalising a plugin's config file), `/log`
|
|
973
|
+
(one warning format), `/guard` (the minimum core version) and `/packages`
|
|
974
|
+
(resolving a package from the site). More families follow, such as URLs,
|
|
975
|
+
dates, HTML escaping and the page language.
|
|
976
|
+
- **`@nera-static/test-utils`** (coming) will hold the shared test helpers:
|
|
977
|
+
building a site in a temporary folder, reading the output, the theme suites.
|
|
978
|
+
- **`@nera-static/stan`** (`nera-stan`, from version 1.0.0) is the one check
|
|
979
|
+
every repository runs: code, CSS, Pug and the package structure.
|
|
980
|
+
|
|
981
|
+
Before you write a helper, look in `@nera-static/plugin-utils`. If it is not
|
|
982
|
+
there and it is generic, it belongs there, not in your package.
|
|
983
|
+
|
|
984
|
+
## What the guide covers
|
|
985
|
+
|
|
986
|
+
The pages of this section follow the principle through each kind of package:
|
|
987
|
+
|
|
988
|
+
1. **[Plugins](https://nera.js.org/docs/style-guide/plugins.html)** — the anatomy of a plugin: files, the hook shape, config and
|
|
989
|
+
warnings, `package.json`, README and CHANGELOG.
|
|
990
|
+
2. **[Themes and starters](https://nera.js.org/docs/style-guide/themes-and-starters.html)** — the layout of a theme and a starter, the theme
|
|
991
|
+
helper object, the custom-property prefixes.
|
|
992
|
+
3. **[Tests](https://nera.js.org/docs/style-guide/tests.html)** — where tests live, how they are named and written, and the
|
|
993
|
+
shared helpers.
|
|
994
|
+
4. **[Tooling](https://nera.js.org/docs/style-guide/tooling.html)** — what `nera-stan` checks, how to run it, its documented
|
|
995
|
+
exceptions, and the shared `.editorconfig`.
|
|
996
|
+
|
|
997
|
+
# Plugins
|
|
998
|
+
|
|
999
|
+
Source: https://nera.js.org/docs/style-guide/plugins.html
|
|
1000
|
+
|
|
1001
|
+
Every Nera plugin has the same anatomy. Open `index.js` and you see the
|
|
1002
|
+
hooks; open `src/config.js` and you see the config keys and their defaults;
|
|
1003
|
+
open the README and the sections come in the same order as in every other
|
|
1004
|
+
plugin. This page describes that anatomy, for the official
|
|
1005
|
+
`@nera-static/plugin-*` packages and for your own.
|
|
1006
|
+
|
|
1007
|
+
How a site uses plugins, and the hook contract itself, is in the
|
|
1008
|
+
[plugins documentation](https://nera.js.org/docs/plugins.html).
|
|
1009
|
+
|
|
1010
|
+
## Files
|
|
1011
|
+
|
|
1012
|
+
```text
|
|
1013
|
+
nera-plugin-<name>/
|
|
1014
|
+
├── index.js # the hooks only: header comment, imports, exported hooks
|
|
1015
|
+
├── src/
|
|
1016
|
+
│ ├── config.js # the config reader: defaults, one reader per key, loadConfig()
|
|
1017
|
+
│ ├── log.js # the package's logger: createLogger('plugin-<name>')
|
|
1018
|
+
│ └── <feature>.js # pure functions, one concern per file
|
|
1019
|
+
├── config/<name>.yaml # every key, with its default; `nera add` copies it
|
|
1020
|
+
├── views/ # only with templates: flat <template>.pug, plus partials/ and helper/
|
|
1021
|
+
├── assets/ # only when getAssets ships static files (served under public/_nera/)
|
|
1022
|
+
├── bin/publish-template.js # only with views/
|
|
1023
|
+
├── test/ # see the Tests page of this guide
|
|
1024
|
+
├── README.md CHANGELOG.md LICENSE package.json package-lock.json
|
|
1025
|
+
├── eslint.config.js .editorconfig .gitignore
|
|
1026
|
+
├── .husky/ # pre-commit: npm run lint, pre-push: npm run lint && npx vitest run
|
|
1027
|
+
└── .github/ # workflows/test.yml, workflows/publish.yml, dependabot.yml, FUNDING.yml
|
|
1028
|
+
```
|
|
1029
|
+
|
|
1030
|
+
- A plugin has **no `src/warn.js` and no `src/guard.js`**. The warning
|
|
1031
|
+
format and the core version guard come from `@nera-static/plugin-utils`
|
|
1032
|
+
(`/log` and `/guard`, from version 1.7.0), so they cannot drift.
|
|
1033
|
+
- `config/<name>.yaml` lists every key, set or commented out, with its
|
|
1034
|
+
default. It is what `nera add <name>` copies into a site, so a plugin has no
|
|
1035
|
+
`bin/publish-config.js`.
|
|
1036
|
+
- `bin/publish-template.js` exists only when the plugin has `views/`. It
|
|
1037
|
+
calls `publishAllTemplates` from `@nera-static/plugin-utils`.
|
|
1038
|
+
|
|
1039
|
+
## The hooks
|
|
1040
|
+
|
|
1041
|
+
`index.js` holds the hooks and nothing else. Everything a hook does beyond
|
|
1042
|
+
reading its input and returning its output lives in `src/`.
|
|
1043
|
+
|
|
1044
|
+
```js
|
|
1045
|
+
// @nera-static/plugin-example — adds a list of related pages to every page.
|
|
1046
|
+
//
|
|
1047
|
+
// getAppData checks the core version and adds app.example, getMetaData adds
|
|
1048
|
+
// meta.related to every page, getAssets ships the default styles.
|
|
1049
|
+
import { fileURLToPath } from 'node:url'
|
|
1050
|
+
import { assertCoreVersion } from '@nera-static/plugin-utils/guard'
|
|
1051
|
+
import { loadConfig } from './src/config.js'
|
|
1052
|
+
import { log } from './src/log.js'
|
|
1053
|
+
import { relatedPages } from './src/related.js'
|
|
1054
|
+
|
|
1055
|
+
export function getAppData({ app = {}, pagesData = [] } = {}) {
|
|
1056
|
+
assertCoreVersion({ plugin: 'plugin-example', from: import.meta.url })
|
|
1057
|
+
return { ...app, example: { count: pagesData.length } }
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
export function getMetaData({ app = {}, pagesData = [] } = {}) {
|
|
1061
|
+
const config = loadConfig({ app })
|
|
1062
|
+
return pagesData.map((page) => ({
|
|
1063
|
+
...page,
|
|
1064
|
+
meta: { ...page.meta, related: relatedPages(page, pagesData, config, { onWarning: log.warn }) },
|
|
1065
|
+
}))
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
export function getAssets({ app = {}, pagesData = [] } = {}) {
|
|
1069
|
+
return [{ from: fileURLToPath(new URL('./assets/example.css', import.meta.url)), to: '_nera/example.css' }]
|
|
1070
|
+
}
|
|
1071
|
+
```
|
|
1072
|
+
|
|
1073
|
+
The rules:
|
|
1074
|
+
|
|
1075
|
+
- **Destructure with defaults**: `({ app = {}, pagesData = [] } = {})`.
|
|
1076
|
+
Never `(data)` with `data.app`.
|
|
1077
|
+
- **Export each hook with `export function`**, never through
|
|
1078
|
+
`export { … }`.
|
|
1079
|
+
- **Synchronous** unless the hook really has to wait. Core awaits every
|
|
1080
|
+
hook, but a synchronous one is easier to test and to reason about.
|
|
1081
|
+
- **Read the config inside the hook** through `loadConfig({ app })`, never
|
|
1082
|
+
at module scope. Then a test can run the hook against a site in a
|
|
1083
|
+
temporary folder.
|
|
1084
|
+
- **Return a new value.** `getAppData` returns a new plain object,
|
|
1085
|
+
`getMetaData` a new array of new page objects. Never change the input.
|
|
1086
|
+
- **The guard runs in `getAppData`**, the first hook core calls, and only in
|
|
1087
|
+
a plugin that has `getAssets`. Core older than 4.13.0 never calls
|
|
1088
|
+
`getAssets`, and the build would still exit 0; `assertCoreVersion` turns
|
|
1089
|
+
that into an error. Such a plugin also declares
|
|
1090
|
+
`"peerDependencies": { "@nera-static/core": ">=4.13.0" }`.
|
|
1091
|
+
- **Files go through `getAssets`.** Core deletes `public/` after the
|
|
1092
|
+
plugins have run, so whatever a plugin writes there directly is lost. A
|
|
1093
|
+
plugin's files are served under `_nera/<name>.*`.
|
|
1094
|
+
|
|
1095
|
+
## Config
|
|
1096
|
+
|
|
1097
|
+
`src/config.js` describes the config file once: its defaults and one reader
|
|
1098
|
+
per top-level key. `createConfigReader` from
|
|
1099
|
+
`@nera-static/plugin-utils/config` does the rest: it copies the defaults,
|
|
1100
|
+
skips empty keys, ignores unknown ones and prints the warnings.
|
|
1101
|
+
|
|
1102
|
+
```js
|
|
1103
|
+
import { createConfigReader, loadPluginConfig } from '@nera-static/plugin-utils/config'
|
|
1104
|
+
import { isText } from '@nera-static/plugin-utils/values'
|
|
1105
|
+
import { log } from './log.js'
|
|
1106
|
+
|
|
1107
|
+
const reader = createConfigReader({
|
|
1108
|
+
file: 'config/example.yaml',
|
|
1109
|
+
defaults: { heading: 'Related pages', limit: 3 },
|
|
1110
|
+
readers: {
|
|
1111
|
+
heading: (value, current, r) => (isText(value) ? value.trim() : r.bad('heading', value, current)),
|
|
1112
|
+
limit: (value, current, r) => (Number.isInteger(value) && value > 0 ? value : r.bad('limit', value, current)),
|
|
1113
|
+
},
|
|
1114
|
+
warn: log.warn,
|
|
1115
|
+
})
|
|
1116
|
+
|
|
1117
|
+
export function loadConfig({ cwd = process.cwd(), app } = {}) {
|
|
1118
|
+
return reader.normalize(loadPluginConfig('example', { cwd, app }))
|
|
1119
|
+
}
|
|
1120
|
+
```
|
|
1121
|
+
|
|
1122
|
+
- **`loadPluginConfig(name, { cwd, app })`** reads the site's
|
|
1123
|
+
`config/<name>.yaml`, or the folder `app.folders.config` names. Pass the
|
|
1124
|
+
`app` your hook receives.
|
|
1125
|
+
- **`reader.normalize(raw)`** returns a fresh copy of the defaults with each
|
|
1126
|
+
valid key replaced. A missing file gives the defaults without a word; a key
|
|
1127
|
+
left empty in YAML keeps its default.
|
|
1128
|
+
- **Every key has a reader**, and a reader either returns the checked value
|
|
1129
|
+
or calls `r.bad(key, value, fallback)`, `r.ignore(where, what)` or
|
|
1130
|
+
`r.unknown(where, key)`. A key without a reader is reported as unknown.
|
|
1131
|
+
- **The shipped `config/<name>.yaml` equals the defaults.** A test parses it
|
|
1132
|
+
and compares it with `reader.defaults()`.
|
|
1133
|
+
|
|
1134
|
+
## Warnings and errors
|
|
1135
|
+
|
|
1136
|
+
`src/log.js` creates the package's logger once:
|
|
1137
|
+
|
|
1138
|
+
```js
|
|
1139
|
+
import { createLogger } from '@nera-static/plugin-utils/log'
|
|
1140
|
+
|
|
1141
|
+
export const log = createLogger('plugin-example')
|
|
1142
|
+
```
|
|
1143
|
+
|
|
1144
|
+
Every message a plugin prints goes through it, so a site owner can tell from
|
|
1145
|
+
the build log where a message came from:
|
|
1146
|
+
|
|
1147
|
+
```text
|
|
1148
|
+
⚠️ plugin-example: config/example.yaml: expected a mapping at the top level, using defaults
|
|
1149
|
+
⚠️ plugin-example: config/example.yaml: ignoring unknown key "limits"
|
|
1150
|
+
⚠️ plugin-example: config/example.yaml: invalid limit 0, using 3
|
|
1151
|
+
⚠️ plugin-example: /blog/first.html: no date — add `date:` to its frontmatter
|
|
1152
|
+
```
|
|
1153
|
+
|
|
1154
|
+
- `log.warn(message)` prints `⚠️ plugin-<name>: <message>`. The config
|
|
1155
|
+
messages above come from the config reader; do not write your own.
|
|
1156
|
+
- `log.page(page, what, todo)` warns about one page:
|
|
1157
|
+
`<page>: <what> — <todo>`. Say what is wrong and what to do about it.
|
|
1158
|
+
- `log.info(message)` prints `ℹ️ plugin-<name>: <message>`, for a rare
|
|
1159
|
+
summary line.
|
|
1160
|
+
- **No bare `console.*`** in a plugin's runtime code. `nera-stan` refuses it
|
|
1161
|
+
(rule `nera/shared-logger`, from version 1.0.0).
|
|
1162
|
+
- **An error that should stop the build is thrown**, not logged:
|
|
1163
|
+
`throw new Error('plugin-<name>: …')`, with the same prefix and no emoji,
|
|
1164
|
+
as `assertCoreVersion` does:
|
|
1165
|
+
|
|
1166
|
+
```text
|
|
1167
|
+
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`).
|
|
1168
|
+
```
|
|
1169
|
+
|
|
1170
|
+
Feature modules in `src/` do not import the logger. They take an
|
|
1171
|
+
`onWarning` callback, as `relatedPages` does above, so they stay pure
|
|
1172
|
+
functions and a test can collect their warnings.
|
|
1173
|
+
|
|
1174
|
+
## Templates
|
|
1175
|
+
|
|
1176
|
+
- Views are flat: `views/<template>.pug`, with subfolders only for
|
|
1177
|
+
`partials/` and `helper/`.
|
|
1178
|
+
- A site gets them through `npm run publish-template` (and `nera add`),
|
|
1179
|
+
which copies them to `views/vendor/plugin-<name>/`.
|
|
1180
|
+
- **The markup and the BEM class names are a public contract.** Sites hold
|
|
1181
|
+
copies of the templates and style the classes from their own CSS, so
|
|
1182
|
+
renaming `.tag-cloud__item` breaks them: that is a major release.
|
|
1183
|
+
- Default styles use custom properties named `--nera-<name>-*`, as
|
|
1184
|
+
`--nera-code-*` in `plugin-code-blocks`. See
|
|
1185
|
+
[Themes and starters](https://nera.js.org/docs/style-guide/themes-and-starters.html#custom-properties)
|
|
1186
|
+
for the full prefix rule.
|
|
1187
|
+
|
|
1188
|
+
## package.json
|
|
1189
|
+
|
|
1190
|
+
The keys come in this order. Leave out what does not apply.
|
|
1191
|
+
|
|
1192
|
+
```json
|
|
1193
|
+
{
|
|
1194
|
+
"name": "@nera-static/plugin-example",
|
|
1195
|
+
"version": "1.0.0",
|
|
1196
|
+
"description": "A plugin for the Nera static site generator that adds related pages.",
|
|
1197
|
+
"main": "index.js",
|
|
1198
|
+
"type": "module",
|
|
1199
|
+
"exports": { ".": "./index.js" },
|
|
1200
|
+
"bin": { "nera-example": "bin/publish-template.js" },
|
|
1201
|
+
"scripts": {
|
|
1202
|
+
"publish-template": "node ./bin/publish-template.js",
|
|
1203
|
+
"lint": "nera-stan",
|
|
1204
|
+
"test": "vitest run",
|
|
1205
|
+
"test:watch": "vitest",
|
|
1206
|
+
"prepare": "husky"
|
|
1207
|
+
},
|
|
1208
|
+
"files": ["bin", "config", "index.js", "src", "views", "assets", "CHANGELOG.md"],
|
|
1209
|
+
"keywords": ["nera", "nera-plugin", "static-site-generator", "related-pages"],
|
|
1210
|
+
"author": "Michael Becker",
|
|
1211
|
+
"license": "MIT",
|
|
1212
|
+
"repository": { "type": "git", "url": "git+https://github.com/seebaermichi/nera-plugin-example.git" },
|
|
1213
|
+
"bugs": { "url": "https://github.com/seebaermichi/nera-plugin-example/issues" },
|
|
1214
|
+
"homepage": "https://github.com/seebaermichi/nera-plugin-example#readme",
|
|
1215
|
+
"publishConfig": { "access": "public" },
|
|
1216
|
+
"sideEffects": false,
|
|
1217
|
+
"engines": { "node": ">=22.12.0" },
|
|
1218
|
+
"peerDependencies": { "@nera-static/core": ">=4.13.0" },
|
|
1219
|
+
"dependencies": { "@nera-static/plugin-utils": "^1.7.0" },
|
|
1220
|
+
"devDependencies": { "@nera-static/core": "^4.15.1", "@nera-static/stan": "^1.0.0", "husky": "^9.1.7", "vitest": "^5.0.0" }
|
|
1221
|
+
}
|
|
1222
|
+
```
|
|
1223
|
+
|
|
1224
|
+
- `bin` and the `publish-template` script only with `views/`; `views` and
|
|
1225
|
+
`assets` in `files` only when the folders exist. `CHANGELOG.md` is always
|
|
1226
|
+
in `files`.
|
|
1227
|
+
- `peerDependencies` on core only for a plugin with `getAssets` (and so with
|
|
1228
|
+
the guard).
|
|
1229
|
+
- `engines.node` is core's floor.
|
|
1230
|
+
- `keywords` always include `nera`, `nera-plugin` and
|
|
1231
|
+
`static-site-generator`, never the generic `plugin`.
|
|
1232
|
+
- Write `package.json` the way `npm pkg fix` leaves it: `bin` paths without
|
|
1233
|
+
a leading `./`, `repository.url` with the `git+` prefix.
|
|
1234
|
+
|
|
1235
|
+
## README
|
|
1236
|
+
|
|
1237
|
+
The sections come in this order. Leave out the optional ones that do not
|
|
1238
|
+
apply, and add no others between them.
|
|
1239
|
+
|
|
1240
|
+
```markdown
|
|
1241
|
+
# @nera-static/plugin-example
|
|
1242
|
+
[](…/actions/workflows/test.yml)
|
|
1243
|
+
[](https://www.npmjs.com/package/@nera-static/plugin-example)
|
|
1244
|
+
|
|
1245
|
+
A plugin for the [Nera](https://nera.js.org) static site generator that …
|
|
1246
|
+
|
|
1247
|
+
## ✨ Features
|
|
1248
|
+
## 🚀 Installation nera add example, then npm install … as the manual path
|
|
1249
|
+
## 🧩 Usage a minimal working example
|
|
1250
|
+
## ⚙️ Configuration a key | default | meaning table, then the full shipped YAML
|
|
1251
|
+
## <feature sections> plain headings without emoji, e.g. "Multilingual sites"
|
|
1252
|
+
## 🛠️ Template Publishing only with views/
|
|
1253
|
+
## 🎨 Styling only with views/: the BEM classes are the public contract
|
|
1254
|
+
## 📊 Generated Output the exact app.<key> / meta.<key> shape
|
|
1255
|
+
## ⚠️ Warnings optional: the messages and what to do about them
|
|
1256
|
+
## Known limitations optional
|
|
1257
|
+
## 🧩 Compatibility core floor, Node floor, plugin order (start: / end:)
|
|
1258
|
+
## 🧪 Development
|
|
1259
|
+
## 🤝 Contributing one line linking the shared contributing guide
|
|
1260
|
+
## 📦 License
|
|
1261
|
+
```
|
|
1262
|
+
|
|
1263
|
+
- A plugin with the core guard says so right under the first paragraph:
|
|
1264
|
+
`Requires @nera-static/core 4.13.0 or later`, linked to Compatibility.
|
|
1265
|
+
- **The README is the public spec.** Everything a user needs, such as a
|
|
1266
|
+
markup contract, is written there. Never link a `ROADMAP` file: it is
|
|
1267
|
+
local only and the link would end in a 404.
|
|
1268
|
+
- No `Author` and no `Links` section: `package.json` already carries both.
|
|
1269
|
+
|
|
1270
|
+
## CHANGELOG
|
|
1271
|
+
|
|
1272
|
+
Every plugin keeps a `CHANGELOG.md` in the
|
|
1273
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format:
|
|
1274
|
+
|
|
1275
|
+
```markdown
|
|
1276
|
+
## [2.0.0] - 2026-11-27
|
|
1277
|
+
|
|
1278
|
+
### Changed
|
|
1279
|
+
|
|
1280
|
+
- **BREAKING**: `app.example` is now `app.related`.
|
|
1281
|
+
|
|
1282
|
+
### Migration from v1.x
|
|
1283
|
+
|
|
1284
|
+
- Replace `app.example` with `app.related` in your templates.
|
|
1285
|
+
```
|
|
1286
|
+
|
|
1287
|
+
- One heading per release, `## [x.y.z] - YYYY-MM-DD`, newest first.
|
|
1288
|
+
- Only the groups `### Added`, `### Changed`, `### Fixed` and
|
|
1289
|
+
`### Removed`.
|
|
1290
|
+
- Bullets are written `- …`, a dash and three spaces, so the text starts
|
|
1291
|
+
in column 4.
|
|
1292
|
+
- A breaking entry starts with `**BREAKING**:`, and a major release has a
|
|
1293
|
+
`### Migration from vX.x` section with the before and after.
|
|
1294
|
+
- **The version bump and the CHANGELOG entry go in the same commit as the
|
|
1295
|
+
change**, not at release time.
|
|
1296
|
+
|
|
1297
|
+
What counts as what:
|
|
1298
|
+
|
|
1299
|
+
- **Major** — a hook's return shape, a renamed or removed config key or a
|
|
1300
|
+
default with a new meaning, a renamed `app.<key>` or `meta.<key>`, changed
|
|
1301
|
+
template markup or BEM classes, a higher core floor.
|
|
1302
|
+
- **Minor** — a new config key with a sensible default, a new template, a new
|
|
1303
|
+
`app.<key>` beside the existing ones, a higher Node floor documented as the
|
|
1304
|
+
real one.
|
|
1305
|
+
- **Patch** — a bugfix with the same output shape, README and internal
|
|
1306
|
+
changes.
|
|
1307
|
+
- **No release** — a `package-lock.json` refresh, devDependency bumps, CI,
|
|
1308
|
+
husky or lint configuration.
|
|
1309
|
+
|
|
1310
|
+
# Themes and starters
|
|
1311
|
+
|
|
1312
|
+
Source: https://nera.js.org/docs/style-guide/themes-and-starters.html
|
|
1313
|
+
|
|
1314
|
+
A theme is the look of a site, shipped as an npm package whose files a site
|
|
1315
|
+
overrides one by one. A starter is a whole sample site that `nera new
|
|
1316
|
+
--starter <name>` copies once. Both follow one layout, so a theme author who
|
|
1317
|
+
knows one official theme finds their way in every other, and a new theme
|
|
1318
|
+
starts from this page and from `node scripts/new-repo.js theme <name>` (or
|
|
1319
|
+
`starter <name>`) in the generator repo, rather than from a copy of a sibling.
|
|
1320
|
+
|
|
1321
|
+
How a site installs and overrides a theme is in the
|
|
1322
|
+
[core concepts](https://nera.js.org/docs/core-concepts.html); how a site uses a starter is in
|
|
1323
|
+
the [CLI reference](https://nera.js.org/docs/cli.html).
|
|
1324
|
+
|
|
1325
|
+
## Theme files
|
|
1326
|
+
|
|
1327
|
+
```text
|
|
1328
|
+
nera-theme-<name>/
|
|
1329
|
+
├── views/
|
|
1330
|
+
│ ├── layouts/layout.pug # the shell: blocks head, header, main, footer, scripts
|
|
1331
|
+
│ ├── pages/ # one view per page type: default.pug, home.pug, post.pug, …
|
|
1332
|
+
│ └── partials/
|
|
1333
|
+
│ ├── helpers.pug # the contract functions and the neraTheme object
|
|
1334
|
+
│ ├── tokens.pug # config/theme.yaml tokens as --theme-* custom properties
|
|
1335
|
+
│ ├── head.pug header.pug footer.pug scripts.pug lang-switch.pug …
|
|
1336
|
+
│ └── <seam>.pug # empty or a plugin-free default; a site overrides it
|
|
1337
|
+
├── assets/
|
|
1338
|
+
│ ├── css/theme.css # the one stylesheet
|
|
1339
|
+
│ └── fonts/<name>/ # only with webfonts: woff2 files plus their licence texts
|
|
1340
|
+
├── config/theme.yaml # every key the theme reads, with its default
|
|
1341
|
+
├── test/
|
|
1342
|
+
│ ├── site/ # the fixture site the tests build, in two languages
|
|
1343
|
+
│ ├── helpers/ global-setup.js
|
|
1344
|
+
│ └── <section>.test.js # one file per section of the theme's contract
|
|
1345
|
+
├── README.md CHANGELOG.md LICENSE package.json package-lock.json
|
|
1346
|
+
├── eslint.config.js vitest.config.js .editorconfig .gitignore
|
|
1347
|
+
├── .husky/ # pre-commit: npm run lint, pre-push: npm run lint && npx vitest run
|
|
1348
|
+
└── .github/ # workflows/test.yml, workflows/publish.yml, dependabot.yml, FUNDING.yml
|
|
1349
|
+
```
|
|
1350
|
+
|
|
1351
|
+
- **One stylesheet, `assets/css/theme.css`.** No `@import` chain and no
|
|
1352
|
+
build step: the file a site links is the file in the repository.
|
|
1353
|
+
- **A script a plugin needs comes from that plugin**, never from a copy in
|
|
1354
|
+
the theme (see "Starter files" below).
|
|
1355
|
+
- `package.json` lists `views`, `assets`, `config` and `CHANGELOG.md` in
|
|
1356
|
+
`files`, carries `nera.generator` with the core floor
|
|
1357
|
+
(`{ "generator": ">=4.15.0" }`), lists the plugins it styles as optional
|
|
1358
|
+
`peerDependencies`, and has the keywords `nera` and `nera-theme`.
|
|
1359
|
+
|
|
1360
|
+
## Design tokens
|
|
1361
|
+
|
|
1362
|
+
A site changes a theme's colours, fonts and sizes in its own
|
|
1363
|
+
`config/theme.yaml`, without touching the CSS:
|
|
1364
|
+
|
|
1365
|
+
```yaml
|
|
1366
|
+
# config/theme.yaml
|
|
1367
|
+
tokens:
|
|
1368
|
+
color:
|
|
1369
|
+
bg: '#f4f5f7'
|
|
1370
|
+
accent: '#d02408'
|
|
1371
|
+
accent_text: '#ffffff'
|
|
1372
|
+
font:
|
|
1373
|
+
body: "'Inter', system-ui, sans-serif"
|
|
1374
|
+
size:
|
|
1375
|
+
measure: '46rem'
|
|
1376
|
+
```
|
|
1377
|
+
|
|
1378
|
+
`partials/tokens.pug` turns every token into a custom property named
|
|
1379
|
+
`--theme-<group>-<name>`, with `_` written as `-`: `tokens.color.accent_text`
|
|
1380
|
+
becomes `--theme-color-accent-text`. It writes them into one inline `<style>`
|
|
1381
|
+
and drops every value that could break out of the rule (`<`, `>`, `{`, `}`,
|
|
1382
|
+
`;`). The theme's own `config/theme.yaml` holds every key with its default,
|
|
1383
|
+
and `theme.css` repeats that default as the fallback of each `var()`.
|
|
1384
|
+
|
|
1385
|
+
## Custom properties
|
|
1386
|
+
|
|
1387
|
+
Every custom property in a theme or a plugin carries a prefix that says who
|
|
1388
|
+
owns it:
|
|
1389
|
+
|
|
1390
|
+
| prefix | owner | example |
|
|
1391
|
+
|---|---|---|
|
|
1392
|
+
| `--theme-*` | the public tokens from `config/theme.yaml`; a site may set them | `--theme-color-accent` |
|
|
1393
|
+
| `--<theme>-*` | a theme's internal aliases, named after the theme | `--stack-bg` |
|
|
1394
|
+
| `--nera-<plugin>-*` | a plugin's default styles | `--nera-code-bg` |
|
|
1395
|
+
|
|
1396
|
+
**No unprefixed custom property** in a theme or a plugin. A short name such
|
|
1397
|
+
as `--bg`, `--text` or `--accent` collides with a site's own CSS. A theme
|
|
1398
|
+
that wants short internal names aliases the tokens once, under its own
|
|
1399
|
+
prefix, and uses the aliases from then on:
|
|
1400
|
+
|
|
1401
|
+
```css
|
|
1402
|
+
:root {
|
|
1403
|
+
--stack-bg: var(--theme-color-bg, #f4f5f7);
|
|
1404
|
+
--stack-accent: var(--theme-color-accent, #d02408);
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
body {
|
|
1408
|
+
background: var(--stack-bg);
|
|
1409
|
+
}
|
|
1410
|
+
```
|
|
1411
|
+
|
|
1412
|
+
Renaming a custom property a site may have set is a breaking change and
|
|
1413
|
+
needs a major release.
|
|
1414
|
+
|
|
1415
|
+
## Seams
|
|
1416
|
+
|
|
1417
|
+
A seam is a partial the theme ships empty, or with a default that needs no
|
|
1418
|
+
plugin. A site fills it by putting a file of the same path into its own
|
|
1419
|
+
`theme/views/`. Common seams are `head-extra`, `scripts-extra`,
|
|
1420
|
+
`footer-extra` and `nav-main`; blog themes add seams such as `post-media`,
|
|
1421
|
+
`post-tags`, `post-pagination` and `tag-cloud`.
|
|
1422
|
+
|
|
1423
|
+
- **A theme reads no plugin data.** It does not look into `app.tags`,
|
|
1424
|
+
`meta.images` or any other key a plugin writes, and it does not parse a
|
|
1425
|
+
page's `content`. Plugin output reaches a page only through a seam the
|
|
1426
|
+
site fills, so a plugin's new data shape can never break a theme.
|
|
1427
|
+
- A seam override starts with a one-line comment that says what it fills:
|
|
1428
|
+
`//- Seam override: plugin-navigation's list form …`.
|
|
1429
|
+
- The theme's README lists every seam with where it renders, what is in
|
|
1430
|
+
scope and the typical override, ready to copy.
|
|
1431
|
+
|
|
1432
|
+
## The helper object: `neraTheme`
|
|
1433
|
+
|
|
1434
|
+
`partials/helpers.pug` holds two things:
|
|
1435
|
+
|
|
1436
|
+
- **The contract functions** every view of the theme, and a site's own
|
|
1437
|
+
layout, may call: in the blog and business themes `pageLang(page)`,
|
|
1438
|
+
`sameLang(page)`, `homeHref(lang)`, `formatDate(value, lang)`,
|
|
1439
|
+
`isoDate(value)` and `hrefFor(value, lang)`. They are documented in the
|
|
1440
|
+
README and are part of the contract.
|
|
1441
|
+
- **One object for the theme's internal helpers, named `neraTheme`** in
|
|
1442
|
+
every theme, never after the theme. The shared partials (`tokens.pug`,
|
|
1443
|
+
`lang-switch.pug`, `head.pug`) then read the same in every theme, and a
|
|
1444
|
+
check can hold them identical.
|
|
1445
|
+
|
|
1446
|
+
```pug
|
|
1447
|
+
//- partials/tokens.pug
|
|
1448
|
+
if neraTheme.tokenRule()
|
|
1449
|
+
style!= neraTheme.tokenRule()
|
|
1450
|
+
```
|
|
1451
|
+
|
|
1452
|
+
`neraTheme` stays internal: a site calls the contract functions, not the
|
|
1453
|
+
object. A theme that renames its helper object to `neraTheme` still says so
|
|
1454
|
+
in its CHANGELOG, because a site that copied a partial calling the old name
|
|
1455
|
+
breaks.
|
|
1456
|
+
|
|
1457
|
+
## Webfonts
|
|
1458
|
+
|
|
1459
|
+
- A theme with webfonts **serves them itself**: woff2 files under
|
|
1460
|
+
`assets/fonts/<theme>/`, next to the licence text of each family
|
|
1461
|
+
(`OFL-<family>.txt`). No request to a font CDN, so a site with the theme
|
|
1462
|
+
makes no third-party request.
|
|
1463
|
+
- The `@font-face` rules come first in `theme.css`, under a comment that
|
|
1464
|
+
names the licence and the source package with its version, for example
|
|
1465
|
+
`From @fontsource-variable/inter 5.3.0`.
|
|
1466
|
+
- Every `font-family` ends in a system font stack, so text renders before the
|
|
1467
|
+
font has loaded (`font-display: swap`).
|
|
1468
|
+
- A theme without webfonts uses system font stacks only.
|
|
1469
|
+
|
|
1470
|
+
## Theme tests
|
|
1471
|
+
|
|
1472
|
+
A theme is tested by building a site with it, not by unit tests of its
|
|
1473
|
+
templates:
|
|
1474
|
+
|
|
1475
|
+
- `test/site/` is a complete fixture site in two languages that uses the
|
|
1476
|
+
theme from the repository (`theme: ../..`) and every plugin the theme
|
|
1477
|
+
styles.
|
|
1478
|
+
- `test/global-setup.js` builds each variant of the fixture once, through
|
|
1479
|
+
the installed `nera` CLI, and the test files read the output.
|
|
1480
|
+
- One test file per section of the theme's contract: `build`, `contract`,
|
|
1481
|
+
`contrast`, `override`, `pages`, `package`, `plugin-classes`, `tokens`,
|
|
1482
|
+
`validate` and so on.
|
|
1483
|
+
- The fixture passes `nera validate` and `nera build --check` with every rule
|
|
1484
|
+
at `error`; a rule the theme deliberately breaks (external links in a new
|
|
1485
|
+
tab) is turned off in the fixture's `config/validate.yaml`, with a comment
|
|
1486
|
+
that says why, and named in the README.
|
|
1487
|
+
- The shared theme suites move into `@nera-static/test-utils` (coming), so a
|
|
1488
|
+
theme passes its options instead of copying the suites.
|
|
1489
|
+
|
|
1490
|
+
## Starter files
|
|
1491
|
+
|
|
1492
|
+
```text
|
|
1493
|
+
nera-starter-<name>/
|
|
1494
|
+
├── pages/ # the sample pages, ready to edit
|
|
1495
|
+
├── config/ # app.yaml, theme.yaml and every plugin's config
|
|
1496
|
+
├── theme/ # the sample site's own files: seam overrides, vendor views, images
|
|
1497
|
+
├── assets/ plugins/ .neraignore # only when the sample site needs them
|
|
1498
|
+
├── test/
|
|
1499
|
+
│ ├── package.test.js # the package: name, files, nera.starter, dependencies
|
|
1500
|
+
│ └── scaffold.test.js # nera new --starter on this repo, then a clean build
|
|
1501
|
+
├── README.md CHANGELOG.md LICENSE package.json package-lock.json
|
|
1502
|
+
├── eslint.config.js .editorconfig .gitignore .husky/ .github/
|
|
1503
|
+
```
|
|
1504
|
+
|
|
1505
|
+
- **`nera new` copies only `pages/`, `config/`, `theme/`, `assets/`,
|
|
1506
|
+
`plugins/` and `.neraignore`.** Everything else in the repository, its
|
|
1507
|
+
tests included, stays behind. The CLI merges the starter's `dependencies`
|
|
1508
|
+
into the new site's `package.json`.
|
|
1509
|
+
- `package.json` carries `nera.starter` with a `label` and a `description`,
|
|
1510
|
+
which `nera new` shows when it offers the starters:
|
|
1511
|
+
|
|
1512
|
+
```json
|
|
1513
|
+
"nera": {
|
|
1514
|
+
"starter": {
|
|
1515
|
+
"label": "Blog for developers",
|
|
1516
|
+
"description": "A ready-to-edit Nera blog for developers on @nera-static/theme-stack: …"
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
```
|
|
1520
|
+
|
|
1521
|
+
- Plugins and the theme are `dependencies`. `@nera-static/nera` is a
|
|
1522
|
+
devDependency only: the CLI never merges it, so the new site keeps the
|
|
1523
|
+
version it was created with.
|
|
1524
|
+
- `files` lists the copied folders and `CHANGELOG.md`, and leaves out what a
|
|
1525
|
+
build writes, such as `!theme/assets/search-index*.json`.
|
|
1526
|
+
- **A starter copies no plugin script.** A script such as the search or the
|
|
1527
|
+
contact form script comes from its plugin through `getAssets`, served under
|
|
1528
|
+
`public/_nera/<plugin>.js`, and the layout links it there. A copy in
|
|
1529
|
+
`theme/assets/js/` would have to be refreshed by hand on every plugin
|
|
1530
|
+
release, and nothing would notice when it drifts.
|
|
1531
|
+
- Vendor views under `theme/views/vendor/plugin-<name>/` are the published
|
|
1532
|
+
templates of the installed plugin version, unchanged. A deliberate change
|
|
1533
|
+
goes into a seam override, not into the vendor copy.
|
|
1534
|
+
- A fresh site from the starter passes `nera validate` and
|
|
1535
|
+
`nera build --check` without a finding. `scaffold.test.js` proves it.
|
|
1536
|
+
|
|
1537
|
+
## Starter README
|
|
1538
|
+
|
|
1539
|
+
The sections come in this order:
|
|
1540
|
+
|
|
1541
|
+
```markdown
|
|
1542
|
+
# @nera-static/starter-example
|
|
1543
|
+
[](…)
|
|
1544
|
+
[](…)
|
|
1545
|
+
|
|
1546
|
+
A ready-to-edit … for the Nera static site generator, on @nera-static/theme-…
|
|
1547
|
+
|
|
1548
|
+
## Usage npx @nera-static/nera new my-site --starter example
|
|
1549
|
+
## What you get the pages, the plugins, what the sample shows
|
|
1550
|
+
## <extra sections> optional, e.g. picture credits or texts for --lang de
|
|
1551
|
+
## Requirements the CLI, core and Node floors
|
|
1552
|
+
## License
|
|
1553
|
+
## First steps always last
|
|
1554
|
+
```
|
|
1555
|
+
|
|
1556
|
+
**`## First steps` is always the last section.** `nera new` prints it after
|
|
1557
|
+
the site is created, from its heading to the next `#` or `##` heading, its
|
|
1558
|
+
`###` subsections included; as the last section it is also where the README
|
|
1559
|
+
ends, with the same text the new owner just saw. It is a short numbered
|
|
1560
|
+
list of what the new owner must change first: the site's `origin`, the legal pages, the author.
|
|
1561
|
+
|
|
1562
|
+
## Versioning
|
|
1563
|
+
|
|
1564
|
+
Themes and starters follow the release rules of the
|
|
1565
|
+
[plugins page](https://nera.js.org/docs/style-guide/plugins.html#changelog), with these
|
|
1566
|
+
additions:
|
|
1567
|
+
|
|
1568
|
+
- **Major** for a theme: a renamed or removed seam, a contract function, a
|
|
1569
|
+
token or a public class; a changed meaning of a `config/theme.yaml` key; a
|
|
1570
|
+
higher core floor.
|
|
1571
|
+
- A starter has no update path: a site created from it owns its files, so a
|
|
1572
|
+
starter release changes only what new sites get.
|
|
1573
|
+
|
|
1574
|
+
# Tests
|
|
1575
|
+
|
|
1576
|
+
Source: https://nera.js.org/docs/style-guide/tests.html
|
|
1577
|
+
|
|
1578
|
+
Every Nera package is tested with [vitest](https://vitest.dev), and every
|
|
1579
|
+
package writes its tests the same way: the same folders, the same file
|
|
1580
|
+
names, the same config, the same style inside a test. Open the tests of any
|
|
1581
|
+
Nera package and you find the end-to-end test in the same file, the
|
|
1582
|
+
fixtures in the same folder and the same phrasing in every `it`.
|
|
1583
|
+
|
|
1584
|
+
## Layout and names
|
|
1585
|
+
|
|
1586
|
+
```text
|
|
1587
|
+
test/
|
|
1588
|
+
├── <module>.test.js # one file per source module
|
|
1589
|
+
├── integration.test.js # the end-to-end test through core or the CLI
|
|
1590
|
+
├── helpers.js # the package's own helpers, when it needs any
|
|
1591
|
+
├── helpers/<topic>.js # instead of helpers.js, once a second concern appears
|
|
1592
|
+
├── fixtures/<name>/ # data a test reads
|
|
1593
|
+
├── site/ # a whole fixture site (themes, starters)
|
|
1594
|
+
└── global-setup.js # only for builds shared across files
|
|
1595
|
+
```
|
|
1596
|
+
|
|
1597
|
+
- **Tests live in `test/`** at the root of the repository, never in `src/`.
|
|
1598
|
+
- **One file per source module**: `src/config.js` is tested in
|
|
1599
|
+
`test/config.test.js`.
|
|
1600
|
+
- **The end-to-end test is always `test/integration.test.js`**: it builds a
|
|
1601
|
+
site through core or runs the CLI. Themes keep one file per section of
|
|
1602
|
+
their contract instead, and read the builds from `test/global-setup.js`
|
|
1603
|
+
(see [Themes and starters](https://nera.js.org/docs/style-guide/themes-and-starters.html#theme-tests)).
|
|
1604
|
+
- **No infixes**: no `.unit.`, `.integration.` or `.template.` in a file
|
|
1605
|
+
name. The folder and the module name say enough.
|
|
1606
|
+
- **Fixtures**: data in `test/fixtures/<name>`, a whole fixture site in
|
|
1607
|
+
`test/site/`.
|
|
1608
|
+
- **Helpers**: the package's own helpers in `test/helpers.js`, split into
|
|
1609
|
+
`test/helpers/<topic>.js` once there is a second concern (for example
|
|
1610
|
+
`test/helpers/fake-github.js`). A helper that more than one package needs
|
|
1611
|
+
belongs in `@nera-static/test-utils`, not in a copy.
|
|
1612
|
+
- **`test/global-setup.js` only for builds shared across files**, as in
|
|
1613
|
+
themes and starters, where building the fixture once per file would be
|
|
1614
|
+
too slow.
|
|
1615
|
+
|
|
1616
|
+
## vitest.config.js
|
|
1617
|
+
|
|
1618
|
+
Every repository has a `vitest.config.js`, and it starts from the same
|
|
1619
|
+
content:
|
|
1620
|
+
|
|
1621
|
+
```js
|
|
1622
|
+
import { defineConfig } from 'vitest/config'
|
|
1623
|
+
|
|
1624
|
+
export default defineConfig({
|
|
1625
|
+
test: {
|
|
1626
|
+
include: ['test/**/*.test.js'],
|
|
1627
|
+
environment: 'node',
|
|
1628
|
+
restoreMocks: true,
|
|
1629
|
+
unstubEnvs: true,
|
|
1630
|
+
unstubGlobals: true,
|
|
1631
|
+
},
|
|
1632
|
+
})
|
|
1633
|
+
```
|
|
1634
|
+
|
|
1635
|
+
- **`restoreMocks`, `unstubEnvs` and `unstubGlobals`** undo every spy, every
|
|
1636
|
+
stubbed environment variable and every stubbed global after each test, so
|
|
1637
|
+
no test has to clean up after itself and none leaks into the next.
|
|
1638
|
+
- **No `globals: true`.** Tests import what they use from `'vitest'`.
|
|
1639
|
+
- **Anything else is added only when the package needs it, with a comment
|
|
1640
|
+
that says why**: `testTimeout` and `hookTimeout` when every test builds a
|
|
1641
|
+
site, `globalSetup: ['test/global-setup.js']` for shared builds,
|
|
1642
|
+
`isolate: false` where the test files do not touch shared state.
|
|
1643
|
+
- **A timeout that only a few tests need stays on those tests**, as the
|
|
1644
|
+
third argument of `it`, not in the config.
|
|
1645
|
+
|
|
1646
|
+
## Scripts
|
|
1647
|
+
|
|
1648
|
+
```json
|
|
1649
|
+
"scripts": {
|
|
1650
|
+
"lint": "nera-stan",
|
|
1651
|
+
"test": "vitest run",
|
|
1652
|
+
"test:watch": "vitest",
|
|
1653
|
+
"prepare": "husky"
|
|
1654
|
+
}
|
|
1655
|
+
```
|
|
1656
|
+
|
|
1657
|
+
- **`npm test` runs the suite once and exits**, the same single pass that
|
|
1658
|
+
CI (`npx vitest run` in `test.yml`) and the husky `pre-push` hook run.
|
|
1659
|
+
Watch mode is `npm run test:watch`.
|
|
1660
|
+
- **No coverage script** until someone needs coverage.
|
|
1661
|
+
- **`npm run lint` runs `nera-stan`**, which also checks the test files
|
|
1662
|
+
(see [Tooling](https://nera.js.org/docs/style-guide/tooling.html)).
|
|
1663
|
+
|
|
1664
|
+
## Writing tests
|
|
1665
|
+
|
|
1666
|
+
```js
|
|
1667
|
+
import fs from 'node:fs'
|
|
1668
|
+
import path from 'node:path'
|
|
1669
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
1670
|
+
import { loadConfig } from '../src/config.js'
|
|
1671
|
+
|
|
1672
|
+
const ROOT = path.resolve(import.meta.dirname, '..')
|
|
1673
|
+
|
|
1674
|
+
describe('loadConfig', () => {
|
|
1675
|
+
it('returns the defaults when the config file is missing', () => {
|
|
1676
|
+
expect(loadConfig({ cwd: path.join(ROOT, 'test/fixtures/empty') })).toEqual({ heading: 'Related pages', limit: 3 })
|
|
1677
|
+
})
|
|
1678
|
+
|
|
1679
|
+
it('warns about an unknown key and ignores it', () => {
|
|
1680
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
1681
|
+
const config = loadConfig({ cwd: path.join(ROOT, 'test/fixtures/unknown-key') })
|
|
1682
|
+
|
|
1683
|
+
expect(config).not.toHaveProperty('limits')
|
|
1684
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining('ignoring unknown key "limits"'))
|
|
1685
|
+
})
|
|
1686
|
+
})
|
|
1687
|
+
```
|
|
1688
|
+
|
|
1689
|
+
- **Import everything explicitly from `'vitest'`**, and use `it`, never
|
|
1690
|
+
`test`.
|
|
1691
|
+
- **`describe` names the unit** (a function, a module, a command) or the
|
|
1692
|
+
scenario, in lower case: `describe('a site deployed under base_path')`.
|
|
1693
|
+
- **`it` states the behaviour in the present tense, without "should"**:
|
|
1694
|
+
`it('copies the stylesheet')`, not `it('should copy the stylesheet')`.
|
|
1695
|
+
- **English**, in names and comments.
|
|
1696
|
+
- **`expect` only**, no other assertion library.
|
|
1697
|
+
- **No file snapshots.** Write the expected values out. An inline snapshot
|
|
1698
|
+
is fine for long generated markup, such as the `<picture>` element of the
|
|
1699
|
+
images plugin.
|
|
1700
|
+
- **Anchor paths on the test file**:
|
|
1701
|
+
`path.resolve(import.meta.dirname, '..')`. Never resolve a path against
|
|
1702
|
+
the current directory, as in `path.resolve('views/tags.pug')`: the test
|
|
1703
|
+
then passes only when vitest runs from the package root.
|
|
1704
|
+
- **Temporary folders only under `os.tmpdir()`**, never inside the
|
|
1705
|
+
repository, and removed after the tests.
|
|
1706
|
+
- **Never `process.chdir`.** A hook that reads `process.cwd()` is tested by
|
|
1707
|
+
spying on it (`vi.spyOn(process, 'cwd')`) or by passing `cwd` in, as
|
|
1708
|
+
`loadConfig({ cwd })` allows.
|
|
1709
|
+
- **Mock with `vi.spyOn` and with `vi.fn()` passed in** as a dependency.
|
|
1710
|
+
`vi.mock` only when the code offers no seam. Restoring is left to
|
|
1711
|
+
`restoreMocks`.
|
|
1712
|
+
- **Built-in modules with the `node:` prefix**: `'node:fs'`,
|
|
1713
|
+
`'node:path'`, `'node:os'`. Synchronous `fs` is fine for writing fixtures.
|
|
1714
|
+
|
|
1715
|
+
`nera-stan` checks four of these rules in every test file, from version
|
|
1716
|
+
1.0.0: `nera/test-no-chdir`, `nera/test-no-cwd-path`, `nera/test-name` and
|
|
1717
|
+
`nera/test-helpers`.
|
|
1718
|
+
|
|
1719
|
+
## Integration tests
|
|
1720
|
+
|
|
1721
|
+
How the end-to-end test builds its site depends on the kind of package:
|
|
1722
|
+
|
|
1723
|
+
- **Plugins**: `test/integration.test.js` creates a site in a temporary
|
|
1724
|
+
folder with the plugin under test, builds it through `@nera-static/core`
|
|
1725
|
+
and asserts on the files in `public/`. Every plugin has
|
|
1726
|
+
`@nera-static/core` as a devDependency for this. The unit tests of a hook
|
|
1727
|
+
run it against a temporary site by pointing `process.cwd()` at it, not by
|
|
1728
|
+
changing the directory.
|
|
1729
|
+
- **Themes and starters**: `test/global-setup.js` builds each variant of
|
|
1730
|
+
the fixture site once, and the test files read the builds through
|
|
1731
|
+
vitest's `inject('builds')`.
|
|
1732
|
+
- **The CLI, the validator and the MCP server**: a temporary folder with the
|
|
1733
|
+
files the test needs, and the working directory passed in or spied on.
|
|
1734
|
+
|
|
1735
|
+
## Shared test helpers
|
|
1736
|
+
|
|
1737
|
+
`@nera-static/test-utils` (coming) will hold the helpers that Nera packages
|
|
1738
|
+
write today in their own `test/helpers.js`: creating a temporary folder and
|
|
1739
|
+
writing files into it, building a site in it, reading its `public/`,
|
|
1740
|
+
capturing console output, running the CLI, and the shared suites for themes
|
|
1741
|
+
and for template publishing.
|
|
1742
|
+
|
|
1743
|
+
- **A generic test helper comes from `@nera-static/test-utils`**, not from a
|
|
1744
|
+
local copy. `nera/test-helpers` refuses a function in a test file that
|
|
1745
|
+
carries the name of one of its helpers; the list of names ships with
|
|
1746
|
+
`nera-stan` 1.0.0.
|
|
1747
|
+
- **What only your package needs stays in `test/helpers.js`**, such as a fake
|
|
1748
|
+
of an external service.
|
|
1749
|
+
|
|
1750
|
+
# Tooling
|
|
1751
|
+
|
|
1752
|
+
Source: https://nera.js.org/docs/style-guide/tooling.html
|
|
1753
|
+
|
|
1754
|
+
A rule that only lives on a page drifts. Every rule of this guide that a
|
|
1755
|
+
machine can check is checked by one tool, `nera-stan`, which every Nera
|
|
1756
|
+
repository runs in `npm run lint`. What a single repository cannot see,
|
|
1757
|
+
such as a helper written twice in two packages, a weekly check across all
|
|
1758
|
+
repositories finds. Everything else is in the shared `.editorconfig`.
|
|
1759
|
+
|
|
1760
|
+
## nera-stan
|
|
1761
|
+
|
|
1762
|
+
`@nera-static/stan` (bin `nera-stan`, from version 1.0.0) is the handwriting
|
|
1763
|
+
check of a single Nera repository. It is a devDependency of every package
|
|
1764
|
+
and runs as its lint script:
|
|
1765
|
+
|
|
1766
|
+
```json
|
|
1767
|
+
"scripts": {
|
|
1768
|
+
"lint": "nera-stan"
|
|
1769
|
+
}
|
|
1770
|
+
```
|
|
1771
|
+
|
|
1772
|
+
So the same check runs everywhere it matters:
|
|
1773
|
+
|
|
1774
|
+
- **on your machine**, with `npm run lint`, and through the husky hooks:
|
|
1775
|
+
`pre-commit: npm run lint` before every commit,
|
|
1776
|
+
`pre-push: npm run lint && npx vitest run` before every push;
|
|
1777
|
+
- **in CI**, where `test.yml` runs `npm run lint` on every push and pull
|
|
1778
|
+
request, and `publish.yml` refuses to publish a release that fails it.
|
|
1779
|
+
|
|
1780
|
+
`nera-stan` brings its own ESLint configuration and never reads the
|
|
1781
|
+
repository's `eslint.config.js`, so no repository can loosen a rule. The
|
|
1782
|
+
`eslint.config.js` only serves your editor, and it is two lines:
|
|
1783
|
+
|
|
1784
|
+
```js
|
|
1785
|
+
import nera from '@nera-static/stan'
|
|
1786
|
+
|
|
1787
|
+
export default [...nera]
|
|
1788
|
+
```
|
|
1789
|
+
|
|
1790
|
+
### Running it
|
|
1791
|
+
|
|
1792
|
+
```text
|
|
1793
|
+
nera-stan [dir] [--fix]
|
|
1794
|
+
```
|
|
1795
|
+
|
|
1796
|
+
- **`dir`** is the repository to check, the current directory by default.
|
|
1797
|
+
- **`--fix`** applies the fixes that have one obviously correct result and
|
|
1798
|
+
leaves everything else to you.
|
|
1799
|
+
- **`--help`** and **`--version`** print the usage and the version.
|
|
1800
|
+
|
|
1801
|
+
`nera-stan` prints one finding per line on stdout, sorted by file and line,
|
|
1802
|
+
with the file relative to the repository, and a summary line on stderr:
|
|
1803
|
+
|
|
1804
|
+
```text
|
|
1805
|
+
index.js:14 nera/shared-logger `console.warn` in plugin runtime code: `import { createLogger } from '@nera-static/plugin-utils/log'`, create one logger with `createLogger('plugin-example')` and call its `warn`/`info` instead
|
|
1806
|
+
src/related.js:3 @stylistic/comma-dangle Missing trailing comma.
|
|
1807
|
+
nera-stan: 2 problems (1 fixable with --fix)
|
|
1808
|
+
```
|
|
1809
|
+
|
|
1810
|
+
The exit code says how it went:
|
|
1811
|
+
|
|
1812
|
+
| Exit code | Meaning |
|
|
1813
|
+
| --------- | --------------------------------------------------------- |
|
|
1814
|
+
| `0` | clean |
|
|
1815
|
+
| `1` | findings |
|
|
1816
|
+
| `2` | a usage error, a missing or invalid `package.json`, or an internal error |
|
|
1817
|
+
|
|
1818
|
+
Every rule is an error. There is no warning level: what `nera-stan` reports
|
|
1819
|
+
is fixed, or it is a documented exception.
|
|
1820
|
+
|
|
1821
|
+
### Repository kinds
|
|
1822
|
+
|
|
1823
|
+
Some rules apply only to some kinds of repository. `nera-stan` reads the kind
|
|
1824
|
+
from `package.json`, nothing else:
|
|
1825
|
+
|
|
1826
|
+
| Kind | Detected by |
|
|
1827
|
+
| --------- | --------------------------------------------------------------------------- |
|
|
1828
|
+
| `core` | the name `@nera-static/core` |
|
|
1829
|
+
| `starter` | a `nera.starter` field |
|
|
1830
|
+
| `theme` | a name `@nera-static/theme-*`, or a `nera.generator` field |
|
|
1831
|
+
| `plugin` | a name `@nera-static/plugin-*`, except `@nera-static/plugin-utils` |
|
|
1832
|
+
| `site` | no `@nera-static/` name, and a dependency on `@nera-static/nera` |
|
|
1833
|
+
| `tool` | everything else: the CLI, the validator, plugin-utils, the MCP server, … |
|
|
1834
|
+
|
|
1835
|
+
### What it checks
|
|
1836
|
+
|
|
1837
|
+
In every kind, for every `.js`, `.mjs` and `.cjs` file:
|
|
1838
|
+
|
|
1839
|
+
- **ESLint's recommended rules**, with the Node globals (the browser globals
|
|
1840
|
+
for scripts under `assets/`, vitest's in test files).
|
|
1841
|
+
- **The formatting**: 4 spaces, no semicolons, single quotes (double quotes
|
|
1842
|
+
where they avoid escaping), trailing commas in multi-line literals,
|
|
1843
|
+
parentheses around every arrow function parameter, spaces inside braces, a
|
|
1844
|
+
final newline, no trailing spaces, at most 120 characters per line (long
|
|
1845
|
+
strings, URLs and comments excepted).
|
|
1846
|
+
- **`prefer-const`, `no-var` and `no-unused-vars`.**
|
|
1847
|
+
- **Built-in modules with the `node:` prefix** (`n/prefer-node-protocol`).
|
|
1848
|
+
|
|
1849
|
+
And the Nera rules:
|
|
1850
|
+
|
|
1851
|
+
| Rule | Kinds | Files | What it refuses | `--fix` |
|
|
1852
|
+
| ----------------------- | -------------- | ----------------------------- | --------------- | ------- |
|
|
1853
|
+
| `nera/no-local-helper` | all but plugin-utils and test-utils | all but the browser scripts in `assets/` and `views/` | a local function with the name or the shape of a `@nera-static/plugin-utils` helper; the message names the export to import | no |
|
|
1854
|
+
| `nera/shared-logger` | plugin | runtime code (not `test/`, `bin/`, `scripts/`, `views/`, `assets/`) | a bare `console.*`; use `createLogger` | no |
|
|
1855
|
+
| `nera/no-copied-from` | all | comments everywhere; `ROADMAP` in published files | a "copied from …" note, and a reference to a local-only `ROADMAP` file | no |
|
|
1856
|
+
| `nera/hook-shape` | plugin | runtime code | a hook exported through `export { … }`, a hook that does not destructure its argument with defaults, a config read at module scope | adds the missing defaults |
|
|
1857
|
+
| `nera/test-no-chdir` | all | test files | `process.chdir` | no |
|
|
1858
|
+
| `nera/test-no-cwd-path` | all | test files | a path resolved against the current directory, as `path.resolve('views/x.pug')` | no |
|
|
1859
|
+
| `nera/test-name` | all | test files | a test name that starts with "should" | no |
|
|
1860
|
+
| `nera/test-helpers` | all | test files | a local copy of a `@nera-static/test-utils` helper | no |
|
|
1861
|
+
|
|
1862
|
+
Test files are everything under `test/` and every `*.test.js`. The writing
|
|
1863
|
+
rules behind the test rules are on the [Tests](https://nera.js.org/docs/style-guide/tests.html)
|
|
1864
|
+
page.
|
|
1865
|
+
|
|
1866
|
+
`--fix` changes only what has one correct result: the formatting rules,
|
|
1867
|
+
the `node:` prefix, and the missing defaults of a hook
|
|
1868
|
+
(`({ app, pagesData })` becomes `({ app = {}, pagesData = [] } = {})`).
|
|
1869
|
+
It never rewrites `(data)` into a destructured argument, and it does not
|
|
1870
|
+
rename tests, because dropping "should" changes the verb.
|
|
1871
|
+
|
|
1872
|
+
Since 1.1.0 three more rule families stand next to the code rules:
|
|
1873
|
+
|
|
1874
|
+
- `css/*`: every CSS file through stylelint, with the BEM class pattern and
|
|
1875
|
+
the [custom-property prefixes](https://nera.js.org/docs/style-guide/themes-and-starters.html#custom-properties).
|
|
1876
|
+
- `pug/*`: every Pug template parses, is indented in multiples of 4 spaces
|
|
1877
|
+
without tabs, quotes attribute values singly and writes BEM class literals.
|
|
1878
|
+
- `structure/*`: `package.json`, README, CHANGELOG, LICENSE, the canonical
|
|
1879
|
+
files and the files each kind of repository must have.
|
|
1880
|
+
|
|
1881
|
+
### Exceptions
|
|
1882
|
+
|
|
1883
|
+
- **Always ignored**: `node_modules/`, `public/`, `dist/`, `coverage/`,
|
|
1884
|
+
`.nera-cache/` and `test/site/public/`, plus everything the repository's
|
|
1885
|
+
`.gitignore` lists.
|
|
1886
|
+
- **A repository's own exceptions** go into `package.json`, under one key,
|
|
1887
|
+
and nowhere else:
|
|
1888
|
+
|
|
1889
|
+
```json
|
|
1890
|
+
"nera-stan": {
|
|
1891
|
+
"ignores": ["test/markup/", "demo/demo.js"],
|
|
1892
|
+
"variants": { ".github/workflows/test.yml": "image-cache" },
|
|
1893
|
+
"skip": { "structure/test-scripts": "a theme without tests: it compiles its templates instead" }
|
|
1894
|
+
}
|
|
1895
|
+
```
|
|
1896
|
+
|
|
1897
|
+
`ignores` is for files that are not Nera code, such as generated fixtures
|
|
1898
|
+
or a vendored demo. `variants` picks a named variant of a canonical file,
|
|
1899
|
+
and `skip` switches a rule off with its reason. The
|
|
1900
|
+
[README](https://github.com/seebaermichi/nera-stan#readme) lists the
|
|
1901
|
+
allowed values.
|
|
1902
|
+
- **A single line** can be excepted with an ESLint comment that names the
|
|
1903
|
+
rule and says why:
|
|
1904
|
+
|
|
1905
|
+
```js
|
|
1906
|
+
// eslint-disable-next-line nera/shared-logger -- the CLI prints its own report
|
|
1907
|
+
console.log(report)
|
|
1908
|
+
```
|
|
1909
|
+
|
|
1910
|
+
A disable comment that no longer suppresses anything is itself an error,
|
|
1911
|
+
so exceptions do not outlive their reason. A disable comment without a
|
|
1912
|
+
reason after ` -- ` is an error too.
|
|
1913
|
+
|
|
1914
|
+
## .editorconfig
|
|
1915
|
+
|
|
1916
|
+
Every repository carries the same `.editorconfig`. It sets the indentation
|
|
1917
|
+
for the file types no linter touches, such as Pug, CSS, YAML and JSON, in
|
|
1918
|
+
every editor that reads it:
|
|
1919
|
+
|
|
1920
|
+
```ini
|
|
1921
|
+
root = true
|
|
1922
|
+
|
|
1923
|
+
[*]
|
|
1924
|
+
charset = utf-8
|
|
1925
|
+
end_of_line = lf
|
|
1926
|
+
indent_style = space
|
|
1927
|
+
indent_size = 4
|
|
1928
|
+
insert_final_newline = true
|
|
1929
|
+
trim_trailing_whitespace = true
|
|
1930
|
+
|
|
1931
|
+
[*.md]
|
|
1932
|
+
trim_trailing_whitespace = false
|
|
1933
|
+
```
|
|
1934
|
+
|
|
1935
|
+
Markdown keeps its trailing whitespace, because two trailing spaces are a
|
|
1936
|
+
line break there.
|
|
1937
|
+
|
|
1938
|
+
## The weekly cross-repository check
|
|
1939
|
+
|
|
1940
|
+
`nera-stan` sees one repository at a time. `style-check`, a script in the
|
|
1941
|
+
engine's repository (`generator/scripts/style-check.js`), reads all of them
|
|
1942
|
+
side by side and reports what only shows up across repositories:
|
|
1943
|
+
|
|
1944
|
+
- helpers defined in two or more repositories, which belong in
|
|
1945
|
+
`@nera-static/plugin-utils`;
|
|
1946
|
+
- plugin templates and scripts that a theme, a starter or the website
|
|
1947
|
+
copied, compared with the plugin version they were copied from;
|
|
1948
|
+
- files that must be identical in every repository of a kind.
|
|
1949
|
+
|
|
1950
|
+
It runs every Monday on a fresh clone of all public Nera repositories and
|
|
1951
|
+
writes its report into the workflow summary. A deliberate difference is
|
|
1952
|
+
listed in its allow-list with a reason, and stays visible in the report as
|
|
1953
|
+
allowed.
|
|
1954
|
+
|
|
1955
|
+
## No Prettier
|
|
1956
|
+
|
|
1957
|
+
Nera does not use Prettier. ESLint's formatting rules already enforce the
|
|
1958
|
+
handwriting for JavaScript, a second formatter would fight them, and the
|
|
1959
|
+
Pug plugin for Prettier would rewrite every template. There is no build or
|
|
1960
|
+
format step in a Nera package: what you write is what `nera-stan` checks.
|
|
1961
|
+
|
|
895
1962
|
# Build a blog with Nera
|
|
896
1963
|
|
|
897
1964
|
Source: https://nera.js.org/tutorials/build-a-blog.html
|
|
@@ -913,13 +1980,21 @@ places: `pages/` for your content (it starts with `pages/index.md`, plus
|
|
|
913
1980
|
publish), `theme/views/` for the Pug templates (`layouts/layout.pug` is the HTML
|
|
914
1981
|
shell, `pages/default.pug` renders a page into it), and `config/` for settings.
|
|
915
1982
|
|
|
916
|
-
Want a finished blog to edit instead?
|
|
917
|
-
theme, sample posts, tags, an archive,
|
|
1983
|
+
Want a finished blog to edit instead? A blog starter sets one up with a
|
|
1984
|
+
theme, sample posts in a series, tags, an archive, search, an Atom feed, a
|
|
1985
|
+
sitemap and structured data:
|
|
918
1986
|
|
|
919
1987
|
```bash
|
|
920
1988
|
npx @nera-static/nera new my-blog --starter blog
|
|
921
1989
|
```
|
|
922
1990
|
|
|
1991
|
+
On a terminal it asks which of four blogs: the plain blog (Enter), a blog for
|
|
1992
|
+
developers (`stack`), a photo blog (`ansitz`) or a travel blog (`umwege`).
|
|
1993
|
+
Without a terminal it takes the plain blog, and `--starter stack`, `ansitz` or
|
|
1994
|
+
`umwege` picks one of the others directly. See them first on the
|
|
1995
|
+
[themes page](https://nera.js.org/themes/index.html), with a screenshot and a demo of each. The
|
|
1996
|
+
[starter kits](https://nera.js.org/docs/cli.html#starter-kits) list says what each one brings.
|
|
1997
|
+
|
|
923
1998
|
Its files won't match the steps below: this tutorial builds a simpler blog by
|
|
924
1999
|
hand, to show how the pieces fit together.
|
|
925
2000
|
|
|
@@ -1375,9 +2450,13 @@ strip_html: true
|
|
|
1375
2450
|
output_filename: search-index.json
|
|
1376
2451
|
group_by_lang: false
|
|
1377
2452
|
show_title: true
|
|
2453
|
+
include_script: true
|
|
1378
2454
|
```
|
|
1379
2455
|
|
|
1380
|
-
`show_title` and `group_by_lang` come up in steps 3 and 4.
|
|
2456
|
+
`show_title` and `group_by_lang` come up in steps 3 and 4. `include_script`
|
|
2457
|
+
matters only if your site or theme loads the client itself, for example through
|
|
2458
|
+
a theme's `scripts-extra` seam: set it to `false` and the template leaves out
|
|
2459
|
+
its `script` tag for `/js/search.js`, so the page does not load the script twice.
|
|
1381
2460
|
|
|
1382
2461
|
`fields` replaces the default list rather than extending it, so keep `content`
|
|
1383
2462
|
(the page body) and `href` (the result link). Any other frontmatter key works if
|
|
@@ -1435,9 +2514,11 @@ If your page has no heading of its own, keep `show_title: true` and the
|
|
|
1435
2514
|
template's `h1` is the page heading.
|
|
1436
2515
|
|
|
1437
2516
|
The template's texts go through `t()`: `search_title` (the heading, default
|
|
1438
|
-
`Search`), `search_placeholder` (default `Search...`)
|
|
1439
|
-
input's accessible name (default `Search`)
|
|
1440
|
-
in `
|
|
2517
|
+
`Search`), `search_placeholder` (default `Search...`), `search_label`, the
|
|
2518
|
+
input's accessible name (default `Search`), and `search_no_results`, the
|
|
2519
|
+
message shown in a `p.search__empty` below the results when a query matches
|
|
2520
|
+
nothing (default `No results`). Translate them under `translations` in
|
|
2521
|
+
`config/app.yaml`, for example for German:
|
|
1441
2522
|
|
|
1442
2523
|
```yaml
|
|
1443
2524
|
translations:
|
|
@@ -1445,6 +2526,7 @@ translations:
|
|
|
1445
2526
|
search_title: Suche
|
|
1446
2527
|
search_placeholder: Suchen…
|
|
1447
2528
|
search_label: Suche
|
|
2529
|
+
search_no_results: Keine Treffer
|
|
1448
2530
|
```
|
|
1449
2531
|
|
|
1450
2532
|
Finally, make sure search runs **last** in `config/plugin-order.yaml` so it
|
|
@@ -1491,7 +2573,7 @@ right language too — the tag pages from `plugin-tags` among them.
|
|
|
1491
2573
|
|
|
1492
2574
|
Render, and you have working search. This site's [Search page](https://nera.js.org/search.html) is
|
|
1493
2575
|
built from the same parts, with two differences: its Markdown has no heading, so
|
|
1494
|
-
it keeps the template's `h1`, translated with the
|
|
2576
|
+
it keeps the template's `h1`, translated with the four keys in English, German
|
|
1495
2577
|
and Spanish; and it sets `group_by_lang: true`, so the box returns only pages in
|
|
1496
2578
|
the language you are reading.
|
|
1497
2579
|
|
|
@@ -3390,8 +4472,8 @@ npx nera add images
|
|
|
3390
4472
|
```
|
|
3391
4473
|
|
|
3392
4474
|
There is nothing else to set up: a `config/images.yaml` is optional, and so
|
|
3393
|
-
is every key in it.
|
|
3394
|
-
(`nera new --starter …`) already
|
|
4475
|
+
is every key in it. Every official starter except `blank`
|
|
4476
|
+
(`nera new --starter …`) already ships the plugin.
|
|
3395
4477
|
|
|
3396
4478
|
## 2. Before and after
|
|
3397
4479
|
|
|
@@ -3849,7 +4931,7 @@ locally:
|
|
|
3849
4931
|
```bash
|
|
3850
4932
|
npm ci
|
|
3851
4933
|
npm run lint # eslint
|
|
3852
|
-
npm test # node --test on the
|
|
4934
|
+
npm test # node --test on the local plugins' and scripts' tests
|
|
3853
4935
|
npm run validate # nera validate: layouts, includes, frontmatter
|
|
3854
4936
|
npm run build -- --check # nera build --check
|
|
3855
4937
|
```
|
|
@@ -3859,8 +4941,10 @@ legal-notice problems and reports what it finds. Findings are warnings, so they
|
|
|
3859
4941
|
fail the run only for a rule that `config/validate.yaml` promotes to an error.
|
|
3860
4942
|
|
|
3861
4943
|
A push to `main` then runs [`.github/workflows/deploy.yml`](https://github.com/seebaermichi/nera-website/blob/main/.github/workflows/deploy.yml): `npm ci`,
|
|
3862
|
-
`npm run build`,
|
|
3863
|
-
|
|
4944
|
+
`npm run build`, then `npm run build:demos` and `npm run check:demos`, which build
|
|
4945
|
+
and check the [blog theme demos](https://nera.js.org/themes/blog/plain/) under `/themes/blog/` from
|
|
4946
|
+
the starters' latest releases. `public/` is then published to GitHub Pages — the
|
|
4947
|
+
site you are reading at nera.js.org.
|
|
3864
4948
|
|
|
3865
4949
|
That's the entire stack: Markdown in, static HTML out, plugins for the rest. If
|
|
3866
4950
|
you've read the other tutorials in this section, you've now seen every piece of it
|
|
@@ -3878,9 +4962,12 @@ keeps bringing the theme's fixes, like a child theme in WordPress.
|
|
|
3878
4962
|
|
|
3879
4963
|
This tutorial uses `@nera-static/theme-business`, the theme of the business
|
|
3880
4964
|
and portfolio starters. You change a colour, add a few CSS rules, replace one
|
|
3881
|
-
partial, update the theme, and add a theme to a site that has none.
|
|
3882
|
-
|
|
3883
|
-
|
|
4965
|
+
partial, update the theme, and add a theme to a site that has none. Then a
|
|
4966
|
+
blog switches between the four blog themes. Every command and output below
|
|
4967
|
+
was run in a fresh site with theme-business 1.0.3, `@nera-static/nera` 1.29.0
|
|
4968
|
+
and `@nera-static/core` 4.19.1; section 9 in a blog from `--starter blog`
|
|
4969
|
+
with theme-blog 2.1.0, theme-stack 2.2.0, theme-ansitz 1.1.0 and
|
|
4970
|
+
theme-umwege 1.1.1.
|
|
3884
4971
|
|
|
3885
4972
|
## 1. Start a site with a theme
|
|
3886
4973
|
|
|
@@ -3900,7 +4987,7 @@ cd my-site
|
|
|
3900
4987
|
|
|
3901
4988
|
```json
|
|
3902
4989
|
"dependencies": {
|
|
3903
|
-
"@nera-static/nera": "^1.
|
|
4990
|
+
"@nera-static/nera": "^1.29.0",
|
|
3904
4991
|
"@nera-static/theme-business": "^1.0.3"
|
|
3905
4992
|
}
|
|
3906
4993
|
```
|
|
@@ -3912,8 +4999,9 @@ theme: business
|
|
|
3912
4999
|
```
|
|
3913
5000
|
|
|
3914
5001
|
`business` is short for `@nera-static/theme-business`. The site gets no
|
|
3915
|
-
layout of its own: `theme/` holds only
|
|
3916
|
-
view comes from the package in
|
|
5002
|
+
layout of its own: `theme/` holds only empty folders (`views/layouts/`,
|
|
5003
|
+
`views/pages/` and `assets/`), and every view comes from the package in
|
|
5004
|
+
`node_modules/`.
|
|
3917
5005
|
|
|
3918
5006
|
Want sample pages for services, opening hours and contact as well? The
|
|
3919
5007
|
business starter brings the same theme with them:
|
|
@@ -4254,7 +5342,102 @@ theme-business has `pages/home.pug`, `default.pug`, `contact.pug`,
|
|
|
4254
5342
|
site nor the theme has fails `nera validate` with `layout-unresolved`, which
|
|
4255
5343
|
names both places it looked.
|
|
4256
5344
|
|
|
4257
|
-
## 9.
|
|
5345
|
+
## 9. Switch between the blog themes
|
|
5346
|
+
|
|
5347
|
+
Four themes are made for blogs: `@nera-static/theme-blog` ("Plain"),
|
|
5348
|
+
`theme-stack` for code, `theme-ansitz` for photographs and `theme-umwege` for
|
|
5349
|
+
travel. The [themes page](https://nera.js.org/themes/index.html) shows each with a screenshot and
|
|
5350
|
+
a demo of its starter's sample posts. The four
|
|
5351
|
+
share one contract, so a blog written for one renders in each of the others.
|
|
5352
|
+
Start one with the plain blog:
|
|
5353
|
+
|
|
5354
|
+
```bash
|
|
5355
|
+
npx @nera-static/nera new my-blog --starter blog --yes
|
|
5356
|
+
cd my-blog
|
|
5357
|
+
```
|
|
5358
|
+
|
|
5359
|
+
With `--yes`, `--starter blog` takes the plain blog without asking: the site
|
|
5360
|
+
depends on `@nera-static/theme-blog` `^2.1.0`, and `config/app.yaml` says
|
|
5361
|
+
`theme: blog`.
|
|
5362
|
+
|
|
5363
|
+
What the four themes share:
|
|
5364
|
+
|
|
5365
|
+
| shared | keys |
|
|
5366
|
+
|---|---|
|
|
5367
|
+
| page types | `pages/home.pug`, `post.pug`, `archive.pug`, `tag.pug`, `default.pug` |
|
|
5368
|
+
| `config/theme.yaml` | `author.name`, `author.bio`, `author.href`, `blog.home_posts`, `blog.featured_series`, `blog.highlight_tag`, `blog.post_layouts`, `footer_links`, `extra_css` |
|
|
5369
|
+
| post frontmatter | `date`, `updated`, `author`, `image`, `image_alt`, `tags`, `series`, `series_part`, `facts`, `location`, `image_note` |
|
|
5370
|
+
| the rest | the seams for plugin output and the `t()` keys |
|
|
5371
|
+
|
|
5372
|
+
To switch to Stack, install the package:
|
|
5373
|
+
|
|
5374
|
+
```bash
|
|
5375
|
+
npm install @nera-static/theme-stack
|
|
5376
|
+
```
|
|
5377
|
+
|
|
5378
|
+
```text
|
|
5379
|
+
added 1 package, and audited 168 packages in 833ms
|
|
5380
|
+
```
|
|
5381
|
+
|
|
5382
|
+
and change the one line in `config/app.yaml`:
|
|
5383
|
+
|
|
5384
|
+
```yaml:config/app.yaml
|
|
5385
|
+
theme: stack
|
|
5386
|
+
```
|
|
5387
|
+
|
|
5388
|
+
```bash
|
|
5389
|
+
npx nera build --check
|
|
5390
|
+
```
|
|
5391
|
+
|
|
5392
|
+
```text
|
|
5393
|
+
✓ No problems found.
|
|
5394
|
+
```
|
|
5395
|
+
|
|
5396
|
+
The same pages, the same `config/theme.yaml` and every file the starter put
|
|
5397
|
+
into `theme/` now render in Stack. `theme: ansitz` and `theme: umwege`
|
|
5398
|
+
(after `npm install @nera-static/theme-ansitz @nera-static/theme-umwege`)
|
|
5399
|
+
build just as clean. Once you have chosen, remove the packages you no longer
|
|
5400
|
+
use: `npm uninstall @nera-static/theme-blog`.
|
|
5401
|
+
|
|
5402
|
+
What a theme does not draw, it ignores, so switching never breaks a page:
|
|
5403
|
+
|
|
5404
|
+
- `location` and `image_note` appear in Ansitz (both) and Umwege
|
|
5405
|
+
(`location`); Plain and Stack show neither. Give the starter's post
|
|
5406
|
+
`pages/posts/tags.md` a `location: Berlin`, and its page carries
|
|
5407
|
+
`<p class="post__location">` under Ansitz and Umwege and nothing under
|
|
5408
|
+
Plain and Stack, with a clean build in all four.
|
|
5409
|
+
- `blog.highlight_tag` is a list on the home in Plain, Ansitz and Umwege;
|
|
5410
|
+
Stack renders nothing for it. `blog.featured_series` is a block on the home
|
|
5411
|
+
in Plain, Stack and Ansitz; Umwege renders nothing for it.
|
|
5412
|
+
|
|
5413
|
+
`blog.home_posts` counts the posts the home lists **after** its large
|
|
5414
|
+
opening, which is never counted: the "Latest post" in Plain and Stack, the
|
|
5415
|
+
boarding pass in Umwege (both the newest post), and the hero in Ansitz (the
|
|
5416
|
+
newest post with an `image`). Each theme has a default that fills its own
|
|
5417
|
+
grid (Plain 9, Stack 6, Ansitz and Umwege 7). Set it in your
|
|
5418
|
+
`config/theme.yaml` and it applies to whichever theme you use: with
|
|
5419
|
+
`home_posts: 2`, "Recent posts" lists two posts in all four.
|
|
5420
|
+
|
|
5421
|
+
Two things deserve a look when you switch:
|
|
5422
|
+
|
|
5423
|
+
- **Tokens** are each theme's own. The eight colour tokens (`bg`, `surface`,
|
|
5424
|
+
`text`, `muted`, `accent`, `accent_text`, `border`, `focus`) exist in all
|
|
5425
|
+
four, so colours you set carry over, but they were chosen for another
|
|
5426
|
+
look: drop them, or check their contrast again (section 4). Stack and
|
|
5427
|
+
Umwege have a few tokens of their own (Stack's `night`, `night_text`,
|
|
5428
|
+
`night_muted` and `highlight`, Umwege's `sun`, `coral` and `sky`).
|
|
5429
|
+
- **Your files in `theme/views/`** stay and win over every theme. The
|
|
5430
|
+
starter's seams (`partials/post-media.pug`, `tag-cloud.pug` and the
|
|
5431
|
+
others), its search page type `pages/search.pug` and its vendor copies
|
|
5432
|
+
rendered unchanged under all four themes. An override of a theme's own
|
|
5433
|
+
view, like the `page-header.pug` of section 6, is a copy of one theme's
|
|
5434
|
+
file: compare it with the new theme's file of the same path (section 7)
|
|
5435
|
+
before you keep it.
|
|
5436
|
+
|
|
5437
|
+
Stack, Ansitz and Umwege are wider than Plain; their READMEs suggest wider
|
|
5438
|
+
`widths` for `@nera-static/plugin-images` in `config/images.yaml`.
|
|
5439
|
+
|
|
5440
|
+
## 10. Build your own theme
|
|
4258
5441
|
|
|
4259
5442
|
A theme of your own is an npm package with the same layout: `views/`,
|
|
4260
5443
|
`assets/` and `config/theme.yaml`. `@nera-static/theme-example` is the
|
|
@@ -4270,4 +5453,9 @@ The [theme-business README](https://github.com/seebaermichi/nera-theme-business#
|
|
|
4270
5453
|
has every token, setting, seam and public class. The plugin tutorials, such
|
|
4271
5454
|
as [Custom navigation](https://nera.js.org/tutorials/custom-navigation.html), show how to publish
|
|
4272
5455
|
a plugin's templates; with theme-business you include them from a seam, as
|
|
4273
|
-
its README shows for each plugin it supports.
|
|
5456
|
+
its README shows for each plugin it supports. The READMEs of
|
|
5457
|
+
[theme-blog](https://github.com/seebaermichi/nera-theme-blog#readme),
|
|
5458
|
+
[theme-stack](https://github.com/seebaermichi/nera-theme-stack#readme),
|
|
5459
|
+
[theme-ansitz](https://github.com/seebaermichi/nera-theme-ansitz#readme) and
|
|
5460
|
+
[theme-umwege](https://github.com/seebaermichi/nera-theme-umwege#readme) say
|
|
5461
|
+
what each blog theme draws from the shared keys.
|