@nera-static/mcp 1.3.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 +42 -0
- package/README.md +58 -1
- package/bin/nera-mcp.js +211 -63
- package/docs/llms-full.txt +2336 -179
- package/package.json +31 -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 +131 -0
- package/src/hosted/checkout.js +417 -0
- package/src/hosted/config.js +93 -0
- package/src/hosted/consent.js +146 -0
- package/src/hosted/crypto.js +91 -0
- package/src/hosted/github.js +160 -0
- package/src/hosted/mcp.js +62 -0
- package/src/hosted/provider.js +376 -0
- package/src/hosted/repo.js +489 -0
- package/src/hosted/store.js +490 -0
- package/src/hosted/tools/publish.js +192 -0
- package/src/hosted/tools/read.js +351 -0
- package/src/hosted/tools/validate.js +51 -0
- package/src/hosted/tools/write.js +201 -0
- package/src/pages.js +171 -0
- package/src/paths.js +11 -18
- package/src/prompts.js +80 -10
- package/src/resources.js +22 -6
- package/src/runner.js +27 -17
- package/src/server-info.js +11 -0
- package/src/server.js +14 -4
- package/src/tools/cli.js +47 -23
- package/src/tools/files.js +19 -111
- package/src/tools/long-running.js +14 -33
- package/src/tools/sites.js +39 -13
package/docs/llms-full.txt
CHANGED
|
@@ -206,8 +206,23 @@ Source: https://nera.js.org/docs/plugins.html
|
|
|
206
206
|
|
|
207
207
|
## Installing
|
|
208
208
|
|
|
209
|
+
```bash
|
|
210
|
+
npx nera add navigation
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
`nera add` installs `@nera-static/plugin-navigation`, copies its default
|
|
214
|
+
`config/navigation.yaml` into your site when you have none, and publishes its
|
|
215
|
+
templates. It needs `@nera-static/nera` 1.26.0 or later (on an older site, run
|
|
216
|
+
`npx nera update` first); the [CLI reference](https://nera.js.org/docs/cli.html#adding-a-plugin)
|
|
217
|
+
has the details.
|
|
218
|
+
|
|
219
|
+
The manual way does the same in steps: install the package, copy its
|
|
220
|
+
`config/<name>.yaml` from `node_modules/@nera-static/plugin-<name>/config/`
|
|
221
|
+
into your `config/`, and run its publish command when it ships templates:
|
|
222
|
+
|
|
209
223
|
```bash
|
|
210
224
|
npm install @nera-static/plugin-navigation
|
|
225
|
+
npx nera-navigation
|
|
211
226
|
```
|
|
212
227
|
|
|
213
228
|
Any dependency whose name starts with `@nera-static/plugin-` is discovered and
|
|
@@ -256,8 +271,10 @@ on a name clash. Invalid entries are skipped with a warning.
|
|
|
256
271
|
## Config lives in your project
|
|
257
272
|
|
|
258
273
|
Every plugin reads `config/<name>.yaml` from **your** site, not from the package.
|
|
259
|
-
The YAML shipped inside the package is
|
|
260
|
-
|
|
274
|
+
The YAML shipped inside the package is a documented starting point:
|
|
275
|
+
`nera add` copies it into your `config/` when you have none, after a manual
|
|
276
|
+
install you copy it yourself, and then you edit it. Missing keys fall back to
|
|
277
|
+
sensible defaults.
|
|
261
278
|
|
|
262
279
|
## Ordering
|
|
263
280
|
|
|
@@ -267,14 +284,16 @@ last so it indexes the final page data.
|
|
|
267
284
|
|
|
268
285
|
## Templates
|
|
269
286
|
|
|
270
|
-
Plugins that ship views expose a publish command
|
|
287
|
+
Plugins that ship views expose a publish command, which `nera add` runs for
|
|
288
|
+
you:
|
|
271
289
|
|
|
272
290
|
```bash
|
|
273
291
|
npx nera-navigation # copies templates into theme/views/vendor/plugin-navigation/
|
|
274
292
|
```
|
|
275
293
|
|
|
276
294
|
Then `include` them from your layouts. Publishing **skips if the folder already
|
|
277
|
-
exists
|
|
295
|
+
exists**, also when `nera add` runs again — run the publish command with
|
|
296
|
+
`--force` (or delete the folder) to pull in template updates.
|
|
278
297
|
|
|
279
298
|
# Deployment
|
|
280
299
|
|
|
@@ -342,9 +361,10 @@ npx @nera-static/nera new <project-name>
|
|
|
342
361
|
|
|
343
362
|
`nera new .` scaffolds into the current, empty folder instead, and
|
|
344
363
|
`--theme <name>` starts the site from a theme. `--starter <name>` starts it
|
|
345
|
-
from a ready-to-edit starter kit instead (`blank`, `blog`,
|
|
346
|
-
`portfolio`; not together with `--theme`),
|
|
347
|
-
`--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`:
|
|
348
368
|
|
|
349
369
|
```bash
|
|
350
370
|
npx @nera-static/nera new my-blog --starter blog --name "My Blog" --lang de
|
|
@@ -365,6 +385,7 @@ with `npx`, e.g. `npx nera validate`. The scaffold also wires `build`, `dev` and
|
|
|
365
385
|
| `nera build` | Build `pages/` → `public/`; with `--check`, check the result too |
|
|
366
386
|
| `nera dev` | Build + live-reload preview on `:3000` |
|
|
367
387
|
| `nera serve` | Serve `public/` without rebuilding |
|
|
388
|
+
| `nera add <plugin>` | Add an official plugin: install it, copy its default config and publish its templates |
|
|
368
389
|
| `nera update` | Update the site's Nera packages (`npm update`) and raise their `^` ranges in `package.json` to the installed versions, then create or refresh `AGENTS.md` and `CLAUDE.md` |
|
|
369
390
|
| `nera validate` | Check layouts, includes and YAML before publishing |
|
|
370
391
|
| `nera check` | Check the built `public/` for accessibility, privacy and legal-notice problems |
|
|
@@ -412,6 +433,47 @@ Netlify secrets). A custom domain still points at the old host until you run
|
|
|
412
433
|
with `--domain <host>` and change its DNS records. `--json` reports the old
|
|
413
434
|
host as `movedFrom`.
|
|
414
435
|
|
|
436
|
+
### Adding a plugin
|
|
437
|
+
|
|
438
|
+
`nera add <plugin>` adds one official plugin to the site. It needs
|
|
439
|
+
`@nera-static/nera` 1.26.0 or later; on an older site, run `npx nera update`
|
|
440
|
+
first.
|
|
441
|
+
|
|
442
|
+
```bash
|
|
443
|
+
npx nera add sitemap
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
It takes one plugin per call, written as `<name>`, `plugin-<name>` or
|
|
447
|
+
`@nera-static/plugin-<name>`, and:
|
|
448
|
+
|
|
449
|
+
1. runs `npm install @nera-static/plugin-<name>`;
|
|
450
|
+
2. copies the plugin's default `config/<name>.yaml` into the site's `config/`
|
|
451
|
+
when the site has none. An existing file is kept as it is. The summary
|
|
452
|
+
says which: `copied`, `kept`, or `none` when the plugin ships no default;
|
|
453
|
+
3. runs the plugin's [publish command](#plugin-publish-commands) when it ships
|
|
454
|
+
templates, which copies them into `theme/views/vendor/plugin-<name>/`.
|
|
455
|
+
|
|
456
|
+
Before npm runs, `nera add` refuses another scope, a version (`sitemap@1`), a
|
|
457
|
+
path and `plugin-utils` (a library, not a plugin), and it refuses a folder
|
|
458
|
+
that is not a Nera site. In an older cloned site, run `nera update --migrate`
|
|
459
|
+
first. Running it again for a plugin you already added keeps your config file
|
|
460
|
+
and your published templates.
|
|
461
|
+
|
|
462
|
+
With `--json` it prints one object on stdout; the output of npm and of the
|
|
463
|
+
publish command goes to stderr:
|
|
464
|
+
|
|
465
|
+
```json
|
|
466
|
+
{
|
|
467
|
+
"ok": true,
|
|
468
|
+
"plugin": "@nera-static/plugin-sitemap",
|
|
469
|
+
"config": { "file": "config/sitemap.yaml", "status": "copied" },
|
|
470
|
+
"templates": "none"
|
|
471
|
+
}
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
`status` is `copied`, `kept` or `none`, and `templates` is `published` or
|
|
475
|
+
`none`. A failure prints `{ "ok": false, "error": "…" }`.
|
|
476
|
+
|
|
415
477
|
### Starter kits
|
|
416
478
|
|
|
417
479
|
A starter kit is a whole ready-to-edit site: sample pages, config, optional
|
|
@@ -430,8 +492,8 @@ shows a raw translation key.
|
|
|
430
492
|
|
|
431
493
|
`--starter` takes:
|
|
432
494
|
|
|
433
|
-
- a starter name: `blank`, `blog`, `business
|
|
434
|
-
`@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;
|
|
435
497
|
- a package name: `@acme/starter-shop`, or unscoped `nera-starter-shop`;
|
|
436
498
|
- a GitHub URL: `https://github.com/owner/repo` (optionally `.git`, `#ref`),
|
|
437
499
|
or `github:owner/repo#ref`;
|
|
@@ -462,14 +524,36 @@ default. Every question has a flag (`--starter`, `--name`, `--lang`); with
|
|
|
462
524
|
`--yes`, or without a terminal (scripts, CI, AI agents), nothing is asked and
|
|
463
525
|
`nera new` scaffolds the base template.
|
|
464
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
|
+
|
|
465
543
|
The official starters:
|
|
466
544
|
|
|
467
|
-
| Starter | What you get |
|
|
468
|
-
| --- | --- |
|
|
469
|
-
| `
|
|
470
|
-
| `
|
|
471
|
-
| `
|
|
472
|
-
| `
|
|
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.
|
|
473
557
|
|
|
474
558
|
### Checking the built site
|
|
475
559
|
|
|
@@ -614,8 +698,11 @@ untouched.
|
|
|
614
698
|
|
|
615
699
|
## Plugin publish commands
|
|
616
700
|
|
|
617
|
-
Each template-shipping plugin exposes a bin
|
|
618
|
-
`theme/views/vendor
|
|
701
|
+
Each template-shipping plugin exposes a bin that copies its Pug into
|
|
702
|
+
`theme/views/vendor/plugin-<name>/`. `nera add` runs it for you. Run it
|
|
703
|
+
yourself after a plain `npm install`, or to pull in template updates:
|
|
704
|
+
publishing skips a folder that already exists, and `--force` overwrites it,
|
|
705
|
+
discarding your edits to the published copies. `nera add` has no `--force`.
|
|
619
706
|
|
|
620
707
|
```bash
|
|
621
708
|
npx nera-navigation
|
|
@@ -685,7 +772,66 @@ Open the site's folder in the assistant — the folder with `package.json` and
|
|
|
685
772
|
`AGENTS.md` convention read it too.
|
|
686
773
|
- **Chat assistants without access to your files** (claude.ai, ChatGPT and the
|
|
687
774
|
like) never see `AGENTS.md`. Give them Nera's docs in the prompt instead —
|
|
688
|
-
see
|
|
775
|
+
see [Docs for AI](#docs-for-ai).
|
|
776
|
+
|
|
777
|
+
Claude Desktop, Claude Code, Cursor and Codex can also work through the Nera
|
|
778
|
+
MCP server, which creates, builds, checks and publishes sites for them — see
|
|
779
|
+
the next section.
|
|
780
|
+
|
|
781
|
+
## The Nera MCP server
|
|
782
|
+
|
|
783
|
+
[`@nera-static/mcp`](https://github.com/seebaermichi/nera-mcp) is a local
|
|
784
|
+
[MCP](https://modelcontextprotocol.io) server. It lets an assistant create,
|
|
785
|
+
edit, build, validate, preview and publish Nera sites in one folder on your
|
|
786
|
+
computer — your **Sites folder** — and nowhere else.
|
|
787
|
+
|
|
788
|
+
### Claude Desktop extension
|
|
789
|
+
|
|
790
|
+
The easiest way, and no Node.js needed: Claude Desktop runs the server on the
|
|
791
|
+
Node it ships.
|
|
792
|
+
|
|
793
|
+
1. Download `nera-mcp-<version>.mcpb` from the
|
|
794
|
+
[latest release](https://github.com/seebaermichi/nera-mcp/releases/latest).
|
|
795
|
+
2. Double-click it and choose **Install** in Claude Desktop.
|
|
796
|
+
3. Pick your **Sites folder** when Claude Desktop asks for it: the folder your
|
|
797
|
+
sites live in.
|
|
798
|
+
|
|
799
|
+
The extension runs on macOS and Windows. To update, install the `.mcpb` of a
|
|
800
|
+
newer release.
|
|
801
|
+
|
|
802
|
+
### Claude Code plugin
|
|
803
|
+
|
|
804
|
+
The plugin brings the server and the Nera skill in one install:
|
|
805
|
+
|
|
806
|
+
```bash
|
|
807
|
+
claude plugin marketplace add seebaermichi/nera-mcp
|
|
808
|
+
claude plugin install nera@nera
|
|
809
|
+
```
|
|
810
|
+
|
|
811
|
+
or, inside Claude Code 2.1.275 or later, in one step:
|
|
812
|
+
|
|
813
|
+
```text
|
|
814
|
+
/plugin install nera --marketplace seebaermichi/nera-mcp
|
|
815
|
+
```
|
|
816
|
+
|
|
817
|
+
Claude Code asks for your **Sites folder** when the plugin is enabled. The
|
|
818
|
+
plugin starts the server with `npx`, so it needs Node.js 22.12 or later
|
|
819
|
+
(`node --version`).
|
|
820
|
+
|
|
821
|
+
### Other clients
|
|
822
|
+
|
|
823
|
+
Cursor, Codex and other MCP clients add the server to their configuration by
|
|
824
|
+
hand, which also needs Node.js 22.12 or later. The commands and configuration
|
|
825
|
+
files are in the README, under
|
|
826
|
+
[Manual configuration](https://github.com/seebaermichi/nera-mcp#manual-configuration).
|
|
827
|
+
|
|
828
|
+
### What the assistant can do
|
|
829
|
+
|
|
830
|
+
With the server, the assistant lists the starter kits, themes and plugins,
|
|
831
|
+
creates a site, reads and writes its pages and files, adds plugins, builds,
|
|
832
|
+
validates, starts a preview and publishes to GitHub Pages or Netlify — with the
|
|
833
|
+
same results as you get in a terminal. The full list is in the README, under
|
|
834
|
+
[Tools](https://github.com/seebaermichi/nera-mcp#tools).
|
|
689
835
|
|
|
690
836
|
## Docs for AI
|
|
691
837
|
|
|
@@ -727,8 +873,8 @@ Add a page:
|
|
|
727
873
|
|
|
728
874
|
```text
|
|
729
875
|
Add an "About us" page at pages/about.md with the same layout as
|
|
730
|
-
pages/index.md, and link it from the menu (add
|
|
731
|
-
@nera-static/plugin-navigation
|
|
876
|
+
pages/index.md, and link it from the menu (if the site has no menu yet, add
|
|
877
|
+
@nera-static/plugin-navigation with npx nera add navigation). Then run
|
|
732
878
|
npx nera validate and npx nera build --check and fix what they report.
|
|
733
879
|
```
|
|
734
880
|
|
|
@@ -736,9 +882,9 @@ Add a contact form with the plugin:
|
|
|
736
882
|
|
|
737
883
|
```text
|
|
738
884
|
Add a contact form to the contact page with @nera-static/plugin-contact-form.
|
|
739
|
-
|
|
740
|
-
template and set my address in config/contact-form.yaml
|
|
741
|
-
by hand.
|
|
885
|
+
Add it with npx nera add contact-form, include its template in the page
|
|
886
|
+
template and set my address as recipient in the config/contact-form.yaml it
|
|
887
|
+
copies. Do not write a form by hand.
|
|
742
888
|
```
|
|
743
889
|
|
|
744
890
|
Add a second language:
|
|
@@ -766,9 +912,1052 @@ with the files I need to create and their content.
|
|
|
766
912
|
|
|
767
913
|
## What's planned
|
|
768
914
|
|
|
769
|
-
Planned, not available yet:
|
|
770
|
-
|
|
771
|
-
|
|
915
|
+
Planned, not available yet: a **hosted connector** for claude.ai and ChatGPT
|
|
916
|
+
that works on your GitHub repository, with no local install.
|
|
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.
|
|
772
1961
|
|
|
773
1962
|
# Build a blog with Nera
|
|
774
1963
|
|
|
@@ -791,13 +1980,21 @@ places: `pages/` for your content (it starts with `pages/index.md`, plus
|
|
|
791
1980
|
publish), `theme/views/` for the Pug templates (`layouts/layout.pug` is the HTML
|
|
792
1981
|
shell, `pages/default.pug` renders a page into it), and `config/` for settings.
|
|
793
1982
|
|
|
794
|
-
Want a finished blog to edit instead?
|
|
795
|
-
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:
|
|
796
1986
|
|
|
797
1987
|
```bash
|
|
798
1988
|
npx @nera-static/nera new my-blog --starter blog
|
|
799
1989
|
```
|
|
800
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
|
+
|
|
801
1998
|
Its files won't match the steps below: this tutorial builds a simpler blog by
|
|
802
1999
|
hand, to show how the pieces fit together.
|
|
803
2000
|
|
|
@@ -841,30 +2038,32 @@ build server, say — is the same for every file, so the order would be arbitrar
|
|
|
841
2038
|
## 3. List the posts on the home page
|
|
842
2039
|
|
|
843
2040
|
`@nera-static/plugin-simple-page-list` collects the pages of a folder into a
|
|
844
|
-
sorted list.
|
|
2041
|
+
sorted list. Add it:
|
|
845
2042
|
|
|
846
2043
|
```bash
|
|
847
|
-
|
|
848
|
-
npx nera-simple-page-list
|
|
2044
|
+
npx nera add simple-page-list
|
|
849
2045
|
```
|
|
850
2046
|
|
|
851
|
-
|
|
852
|
-
copies the
|
|
2047
|
+
`nera add` installs the package, which Nera then picks up from your
|
|
2048
|
+
`package.json` on its own. It also copies the plugin's default
|
|
2049
|
+
`config/simple-page-list.yaml` and publishes its template to
|
|
853
2050
|
`theme/views/vendor/plugin-simple-page-list/simple-page-list.pug`.
|
|
854
2051
|
|
|
855
|
-
|
|
856
|
-
|
|
2052
|
+
The copied config already lists the posts folder, newest first. Without its
|
|
2053
|
+
comments it reads:
|
|
857
2054
|
|
|
858
|
-
```yaml
|
|
859
|
-
|
|
2055
|
+
```yaml:config/simple-page-list.yaml
|
|
2056
|
+
page_paths:
|
|
2057
|
+
- /posts
|
|
860
2058
|
more_link_text: Read more
|
|
861
2059
|
sortBy: date
|
|
862
2060
|
sortOrder: descending
|
|
863
2061
|
```
|
|
864
2062
|
|
|
865
|
-
`
|
|
866
|
-
|
|
867
|
-
|
|
2063
|
+
`page_paths` groups the list by the last segment of each path, so your posts
|
|
2064
|
+
arrive in `app.pageList.posts`. Add more folders here later, and each gets its
|
|
2065
|
+
own key. `sortBy: date` reads a post's `date` from the frontmatter and falls
|
|
2066
|
+
back to `createdAt`, so your posts sort by the dates you just set.
|
|
868
2067
|
|
|
869
2068
|
Now a page template that renders the page's own content and the list below it.
|
|
870
2069
|
Create `theme/views/pages/blog.pug`:
|
|
@@ -946,11 +2145,13 @@ if groups.length > 0
|
|
|
946
2145
|
+pageListItems(group.pages)
|
|
947
2146
|
```
|
|
948
2147
|
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
the
|
|
953
|
-
|
|
2148
|
+
It reads `app.pageList` in either shape. For your config that is one group,
|
|
2149
|
+
`posts`: under the heading "Recent Pages" and a group heading "posts", each post
|
|
2150
|
+
becomes an `article` with its title, description and a "Read more" link. To
|
|
2151
|
+
change the headings or the markup, edit this file — it is your copy now.
|
|
2152
|
+
Running `npx nera add simple-page-list` again keeps your config and this folder.
|
|
2153
|
+
`npx nera-simple-page-list --force` overwrites the folder with the shipped
|
|
2154
|
+
template and discards your edits.
|
|
954
2155
|
|
|
955
2156
|
Prefer to write the list yourself? See
|
|
956
2157
|
[Write your own local plugin](https://nera.js.org/tutorials/write-a-local-plugin.html).
|
|
@@ -964,8 +2165,9 @@ Prefer to write the list yourself? See
|
|
|
964
2165
|
- **Sitemap:** set your site's origin as in
|
|
965
2166
|
[Add canonical links for SEO](https://nera.js.org/tutorials/canonical-links-seo.html), then add
|
|
966
2167
|
`@nera-static/plugin-sitemap` from the [plugin catalog](https://nera.js.org/plugins/index.html).
|
|
967
|
-
- **Images and code:** `@nera-static/plugin-images`
|
|
968
|
-
|
|
2168
|
+
- **Images and code:** `@nera-static/plugin-images` turns your photos into
|
|
2169
|
+
responsive images ([tutorial](https://nera.js.org/tutorials/responsive-images.html)), and
|
|
2170
|
+
`@nera-static/plugin-code-blocks` (syntax highlighting) is in the
|
|
969
2171
|
[plugin catalog](https://nera.js.org/plugins/index.html) too.
|
|
970
2172
|
|
|
971
2173
|
## 5. Preview and build
|
|
@@ -996,22 +2198,19 @@ the link for the current page — no JavaScript required.
|
|
|
996
2198
|
## 1. Install and publish the template
|
|
997
2199
|
|
|
998
2200
|
```bash
|
|
999
|
-
|
|
1000
|
-
npx nera-navigation
|
|
2201
|
+
npx nera add navigation
|
|
1001
2202
|
```
|
|
1002
2203
|
|
|
1003
|
-
|
|
2204
|
+
`nera add` installs the package, copies its default `config/navigation.yaml` into
|
|
2205
|
+
your site and publishes the nav templates into
|
|
1004
2206
|
`theme/views/vendor/plugin-navigation/`, where you can edit them freely.
|
|
1005
2207
|
|
|
1006
2208
|
## 2. Define the menu
|
|
1007
2209
|
|
|
1008
|
-
|
|
2210
|
+
Open `config/navigation.yaml`, the file `nera add` copied. Its menu is a single flat
|
|
2211
|
+
list that already holds the Home link, so add your other pages below it:
|
|
1009
2212
|
|
|
1010
2213
|
```yaml
|
|
1011
|
-
active_class: nav__link--active
|
|
1012
|
-
active_path_class: nav__link--active-path
|
|
1013
|
-
nav_class: nav
|
|
1014
|
-
|
|
1015
2214
|
elements:
|
|
1016
2215
|
- href: /index.html
|
|
1017
2216
|
name: Home
|
|
@@ -1019,15 +2218,24 @@ elements:
|
|
|
1019
2218
|
name: Docs
|
|
1020
2219
|
```
|
|
1021
2220
|
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
2221
|
+
Above the list the file carries the three class keys, commented out at their
|
|
2222
|
+
defaults:
|
|
2223
|
+
|
|
2224
|
+
```yaml
|
|
2225
|
+
# nav_class: nav
|
|
2226
|
+
# active_class: nav__link--active
|
|
2227
|
+
# active_path_class: nav__link--active-path
|
|
2228
|
+
```
|
|
2229
|
+
|
|
2230
|
+
Leave them commented out and the plugin uses exactly these values. `active_class`
|
|
2231
|
+
goes on the link to the current page, `active_path_class` on a section link — one pointing at a folder's index,
|
|
1025
2232
|
such as `/docs/index.html` or `/docs/` — when the current page sits in that folder or below
|
|
1026
2233
|
(the site root never counts). `nav_class` is the BEM block name the other classes derive
|
|
1027
2234
|
from: `nav_class: mainmenu` renames the whole family to `.mainmenu`, `.mainmenu--list`,
|
|
1028
2235
|
`.mainmenu__item`, `.mainmenu__link`, `.mainmenu__link--active` and
|
|
1029
2236
|
`.mainmenu__link--active-path`. The two state keys override just their own class, so
|
|
1030
|
-
when you rename,
|
|
2237
|
+
when you rename, leave them commented out — uncommented with the values above,
|
|
2238
|
+
they keep `nav__link--active`.
|
|
1031
2239
|
|
|
1032
2240
|
Every entry needs an `href`: one without it is skipped with a warning, and the build
|
|
1033
2241
|
still succeeds.
|
|
@@ -1037,8 +2245,8 @@ still succeeds.
|
|
|
1037
2245
|
> `npx nera-navigation --force` once — it overwrites that folder, so if you edited your
|
|
1038
2246
|
> copy, save your changes first and carry them over.
|
|
1039
2247
|
|
|
1040
|
-
Need more than one menu?
|
|
1041
|
-
`app.nav.<name>.elements`:
|
|
2248
|
+
Need more than one menu? Replace the flat list with named ones — the copied file
|
|
2249
|
+
shows this shape in a comment at its end. Each becomes `app.nav.<name>.elements`:
|
|
1042
2250
|
|
|
1043
2251
|
```yaml
|
|
1044
2252
|
elements:
|
|
@@ -1090,10 +2298,12 @@ a browsable overview page for every tag automatically.
|
|
|
1090
2298
|
## 1. Install and publish templates
|
|
1091
2299
|
|
|
1092
2300
|
```bash
|
|
1093
|
-
|
|
1094
|
-
npx nera-tags
|
|
2301
|
+
npx nera add tags
|
|
1095
2302
|
```
|
|
1096
2303
|
|
|
2304
|
+
`nera add` installs the package, copies its default `config/tags.yaml` into
|
|
2305
|
+
your site and publishes the templates into `theme/views/vendor/plugin-tags/`.
|
|
2306
|
+
|
|
1097
2307
|
## 2. Tag some pages
|
|
1098
2308
|
|
|
1099
2309
|
Add a comma-separated `tags` value to any page's frontmatter:
|
|
@@ -1109,19 +2319,27 @@ tags: plugins, search
|
|
|
1109
2319
|
Tags are slugified and case-folded, so `Web Dev`, `web dev` and `WEB DEV` all map to
|
|
1110
2320
|
one page at `/tags/web-dev.html`.
|
|
1111
2321
|
|
|
1112
|
-
## 3. Configure
|
|
2322
|
+
## 3. Configure
|
|
1113
2323
|
|
|
1114
|
-
`config/tags.yaml`
|
|
2324
|
+
`config/tags.yaml`, the file `nera add` copied, sets every key to its default,
|
|
2325
|
+
so it changes nothing until you edit it; the keys commented out in it are
|
|
2326
|
+
examples. These are the first four:
|
|
1115
2327
|
|
|
1116
2328
|
```yaml
|
|
1117
2329
|
meta_property_name: tags
|
|
1118
2330
|
tag_overview_path: '/tags'
|
|
1119
2331
|
tag_separator: ','
|
|
2332
|
+
tag_overview_layout: pages/default.pug
|
|
2333
|
+
```
|
|
2334
|
+
|
|
2335
|
+
`tag_overview_layout` is the layout every generated tag page renders with.
|
|
2336
|
+
Point it at a layout that renders the published overview template:
|
|
2337
|
+
|
|
2338
|
+
```yaml
|
|
1120
2339
|
tag_overview_layout: pages/tag-overview.pug
|
|
1121
2340
|
```
|
|
1122
2341
|
|
|
1123
|
-
|
|
1124
|
-
template. Create `theme/views/pages/tag-overview.pug`:
|
|
2342
|
+
Then create `theme/views/pages/tag-overview.pug`:
|
|
1125
2343
|
|
|
1126
2344
|
```pug
|
|
1127
2345
|
extends ../layouts/layout
|
|
@@ -1168,7 +2386,7 @@ Tags are then collected per `meta.lang`, and the language code prefixes the whol
|
|
|
1168
2386
|
```
|
|
1169
2387
|
|
|
1170
2388
|
The default language stays unprefixed, which is what you want when it is served
|
|
1171
|
-
from the root. If every language sits in its own directory,
|
|
2389
|
+
from the root. If every language sits in its own directory, set
|
|
1172
2390
|
`prefix_default_lang: true` so it gets a segment too. Pages without a `meta.lang`
|
|
1173
2391
|
fall into the default language rather than a bucket of their own, so a
|
|
1174
2392
|
single-language site is unaffected by any of this.
|
|
@@ -1200,30 +2418,27 @@ client script — no server required.
|
|
|
1200
2418
|
## 1. Install
|
|
1201
2419
|
|
|
1202
2420
|
```bash
|
|
1203
|
-
|
|
2421
|
+
npx nera add search
|
|
1204
2422
|
```
|
|
1205
2423
|
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
npx nera-search
|
|
1210
|
-
```
|
|
1211
|
-
|
|
1212
|
-
This copies the search box into `theme/views/vendor/plugin-search/` and the client into
|
|
2424
|
+
`nera add` installs the package, copies its default `config/search.yaml` into
|
|
2425
|
+
your site and publishes the plugin's files: the search box into
|
|
2426
|
+
`theme/views/vendor/plugin-search/` and the client into
|
|
1213
2427
|
`theme/assets/js/search.js`.
|
|
1214
2428
|
|
|
1215
|
-
Both copies are yours from then on. Running `npx nera
|
|
1216
|
-
|
|
1217
|
-
`search
|
|
2429
|
+
Both copies are yours from then on. Running `npx nera add search` again, or
|
|
2430
|
+
the plugin's own `npx nera-search`, skips the template if the
|
|
2431
|
+
`vendor/plugin-search/` folder exists and the client if `search.js` exists, so
|
|
2432
|
+
it never discards your edits — and a template change in a
|
|
1218
2433
|
new release never reaches your site on its own. To refresh after an upgrade, run
|
|
1219
2434
|
`npx nera-search --force`, but only if you never edited the copies: it overwrites
|
|
1220
2435
|
both. If you did, diff them against the package and merge the changes by hand
|
|
1221
2436
|
(the plugin README's *Template Publishing* section explains how).
|
|
1222
2437
|
|
|
1223
|
-
##
|
|
2438
|
+
## 2. Configure
|
|
1224
2439
|
|
|
1225
|
-
`config/search.yaml` controls which fields are
|
|
1226
|
-
|
|
2440
|
+
`config/search.yaml`, the file `nera add` copied, controls which fields are
|
|
2441
|
+
indexed. Its values are the defaults, so it changes nothing until you edit it:
|
|
1227
2442
|
|
|
1228
2443
|
```yaml
|
|
1229
2444
|
fields:
|
|
@@ -1233,8 +2448,16 @@ fields:
|
|
|
1233
2448
|
- href
|
|
1234
2449
|
strip_html: true
|
|
1235
2450
|
output_filename: search-index.json
|
|
2451
|
+
group_by_lang: false
|
|
2452
|
+
show_title: true
|
|
2453
|
+
include_script: true
|
|
1236
2454
|
```
|
|
1237
2455
|
|
|
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.
|
|
2460
|
+
|
|
1238
2461
|
`fields` replaces the default list rather than extending it, so keep `content`
|
|
1239
2462
|
(the page body) and `href` (the result link). Any other frontmatter key works if
|
|
1240
2463
|
your pages define it — the starter page `nera new` scaffolds has a `description`
|
|
@@ -1251,7 +2474,7 @@ write the attribute on raw HTML:
|
|
|
1251
2474
|
<aside data-search-ignore>Not part of the index.</aside>
|
|
1252
2475
|
```
|
|
1253
2476
|
|
|
1254
|
-
##
|
|
2477
|
+
## 3. Add a search page
|
|
1255
2478
|
|
|
1256
2479
|
The search box is Pug, so it belongs in a view, not in the Markdown. Create
|
|
1257
2480
|
`theme/views/pages/search.pug` on top of the layout `nera new` scaffolds:
|
|
@@ -1280,19 +2503,22 @@ Search across the documentation.
|
|
|
1280
2503
|
```
|
|
1281
2504
|
|
|
1282
2505
|
That page brings its own `# Search` heading, so turn off the template's `h1` in
|
|
1283
|
-
`config/search.yaml`, or `nera build --check` warns `a11y-h1` about two of them
|
|
2506
|
+
`config/search.yaml`, or `nera build --check` warns `a11y-h1` about two of them —
|
|
2507
|
+
set it to `false`:
|
|
1284
2508
|
|
|
1285
2509
|
```yaml
|
|
1286
2510
|
show_title: false
|
|
1287
2511
|
```
|
|
1288
2512
|
|
|
1289
|
-
If your page has no heading of its own,
|
|
1290
|
-
`h1` is the page heading.
|
|
2513
|
+
If your page has no heading of its own, keep `show_title: true` and the
|
|
2514
|
+
template's `h1` is the page heading.
|
|
1291
2515
|
|
|
1292
2516
|
The template's texts go through `t()`: `search_title` (the heading, default
|
|
1293
|
-
`Search`), `search_placeholder` (default `Search...`)
|
|
1294
|
-
input's accessible name (default `Search`)
|
|
1295
|
-
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:
|
|
1296
2522
|
|
|
1297
2523
|
```yaml
|
|
1298
2524
|
translations:
|
|
@@ -1300,6 +2526,7 @@ translations:
|
|
|
1300
2526
|
search_title: Suche
|
|
1301
2527
|
search_placeholder: Suchen…
|
|
1302
2528
|
search_label: Suche
|
|
2529
|
+
search_no_results: Keine Treffer
|
|
1303
2530
|
```
|
|
1304
2531
|
|
|
1305
2532
|
Finally, make sure search runs **last** in `config/plugin-order.yaml` so it
|
|
@@ -1311,11 +2538,11 @@ plugin-order:
|
|
|
1311
2538
|
- plugin-search
|
|
1312
2539
|
```
|
|
1313
2540
|
|
|
1314
|
-
##
|
|
2541
|
+
## 4. Per-language search (optional)
|
|
1315
2542
|
|
|
1316
2543
|
By default every page lands in one index, so the search box on a German page
|
|
1317
|
-
also returns English and Spanish hits. Set `group_by_lang` to
|
|
1318
|
-
an index of its own:
|
|
2544
|
+
also returns English and Spanish hits. Set `group_by_lang` to `true` to give
|
|
2545
|
+
each language an index of its own:
|
|
1319
2546
|
|
|
1320
2547
|
```yaml
|
|
1321
2548
|
group_by_lang: true
|
|
@@ -1341,12 +2568,12 @@ the *default* language's index, so building the attribute from it would search
|
|
|
1341
2568
|
English from a German page. `app.searchIndexPaths` has every language keyed by
|
|
1342
2569
|
code, and each index entry carries its `lang`.
|
|
1343
2570
|
|
|
1344
|
-
Because search runs last (step
|
|
2571
|
+
Because search runs last (step 3), pages other plugins generate land in the
|
|
1345
2572
|
right language too — the tag pages from `plugin-tags` among them.
|
|
1346
2573
|
|
|
1347
2574
|
Render, and you have working search. This site's [Search page](https://nera.js.org/search.html) is
|
|
1348
2575
|
built from the same parts, with two differences: its Markdown has no heading, so
|
|
1349
|
-
it keeps the template's `h1`, translated with the
|
|
2576
|
+
it keeps the template's `h1`, translated with the four keys in English, German
|
|
1350
2577
|
and Spanish; and it sets `group_by_lang: true`, so the box returns only pages in
|
|
1351
2578
|
the language you are reading.
|
|
1352
2579
|
|
|
@@ -1361,10 +2588,14 @@ docs and multi-part tutorials.
|
|
|
1361
2588
|
## 1. Install and publish the template
|
|
1362
2589
|
|
|
1363
2590
|
```bash
|
|
1364
|
-
|
|
1365
|
-
npx nera-page-pagination
|
|
2591
|
+
npx nera add page-pagination
|
|
1366
2592
|
```
|
|
1367
2593
|
|
|
2594
|
+
`nera add` installs the package, copies its `config/page-pagination.yaml` into
|
|
2595
|
+
your site and publishes the template into
|
|
2596
|
+
`theme/views/vendor/plugin-page-pagination/`. The defaults need no setting, so
|
|
2597
|
+
the one key in that file is commented out.
|
|
2598
|
+
|
|
1368
2599
|
## 2. Order the pages
|
|
1369
2600
|
|
|
1370
2601
|
By default the plugin reads a `pagination_order` number from each page:
|
|
@@ -1380,8 +2611,8 @@ Pages are ordered by `pagination_order` first, then by creation date, then by
|
|
|
1380
2611
|
path — so a page without an explicit order still lands somewhere stable.
|
|
1381
2612
|
|
|
1382
2613
|
> Ordering starts at `0` if you want it to: the plugin treats `0` as a real value,
|
|
1383
|
-
> not "missing".
|
|
1384
|
-
> `
|
|
2614
|
+
> not "missing". To read a different key, uncomment `order_property` in
|
|
2615
|
+
> `config/page-pagination.yaml` and set its name.
|
|
1385
2616
|
|
|
1386
2617
|
## 3. Render the links
|
|
1387
2618
|
|
|
@@ -1410,24 +2641,17 @@ without you touching the Markdown.
|
|
|
1410
2641
|
## 1. Install
|
|
1411
2642
|
|
|
1412
2643
|
```bash
|
|
1413
|
-
|
|
2644
|
+
npx nera add link-attributes
|
|
1414
2645
|
```
|
|
1415
2646
|
|
|
1416
|
-
|
|
1417
|
-
|
|
2647
|
+
`nera add` installs the package and copies its default `config/link-attributes.yaml`
|
|
2648
|
+
into your site. There is no template to publish — this plugin only transforms
|
|
2649
|
+
content, and its one setting lives in that file.
|
|
1418
2650
|
|
|
1419
2651
|
## 2. Configure
|
|
1420
2652
|
|
|
1421
|
-
`config/link-attributes.yaml
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
```bash
|
|
1425
|
-
npx nera-link-attributes
|
|
1426
|
-
```
|
|
1427
|
-
|
|
1428
|
-
An existing file is left alone, so re-running never overwrites your edits;
|
|
1429
|
-
`npx nera-link-attributes --force` replaces it with a fresh copy. You can also
|
|
1430
|
-
write the file by hand:
|
|
2653
|
+
`config/link-attributes.yaml`, the file `nera add` copied, lists the attributes to
|
|
2654
|
+
add:
|
|
1431
2655
|
|
|
1432
2656
|
```yaml
|
|
1433
2657
|
attributes:
|
|
@@ -1435,6 +2659,10 @@ attributes:
|
|
|
1435
2659
|
- rel="noopener noreferrer"
|
|
1436
2660
|
```
|
|
1437
2661
|
|
|
2662
|
+
These defaults are what this tutorial wants, so you can keep the file as it is.
|
|
2663
|
+
Running `nera add` again keeps your edits; to get the defaults back, the plugin's
|
|
2664
|
+
own command `npx nera-link-attributes --force` replaces the file with a fresh copy.
|
|
2665
|
+
|
|
1438
2666
|
Without any `attributes` the plugin leaves your pages unchanged — no file, no new
|
|
1439
2667
|
tabs.
|
|
1440
2668
|
|
|
@@ -1470,14 +2698,14 @@ search console weeks later. So check the output, as this tutorial does at every
|
|
|
1470
2698
|
## 1. Install and publish the template
|
|
1471
2699
|
|
|
1472
2700
|
```bash
|
|
1473
|
-
|
|
1474
|
-
npx nera-canonical-links
|
|
2701
|
+
npx nera add canonical-links
|
|
1475
2702
|
```
|
|
1476
2703
|
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
2704
|
+
`nera add` installs the package, copies its default `config/canonical-links.yaml`
|
|
2705
|
+
into your site and publishes `index.pug` and its `partials/` to
|
|
2706
|
+
`theme/views/vendor/plugin-canonical-links/`. Publishing skips if that folder
|
|
2707
|
+
already exists, so your edits are safe; `npx nera-canonical-links --force`
|
|
2708
|
+
overwrites them with the shipped templates after an upgrade.
|
|
1481
2709
|
|
|
1482
2710
|
## 2. Set your origin
|
|
1483
2711
|
|
|
@@ -1488,10 +2716,14 @@ Canonical URLs are absolute, so the plugin needs your site's origin. Set it once
|
|
|
1488
2716
|
origin: https://example.com
|
|
1489
2717
|
```
|
|
1490
2718
|
|
|
1491
|
-
That is all the configuration a single-language site needs — **the
|
|
1492
|
-
config
|
|
1493
|
-
|
|
1494
|
-
|
|
2719
|
+
That is all the configuration a single-language site needs — **the
|
|
2720
|
+
`config/canonical-links.yaml` that `nera add` copied can stay as it is**. Its
|
|
2721
|
+
one active key, `page_identifier: slug`, is the default, and the others are
|
|
2722
|
+
commented-out examples. One of them, `app_origin`, is used as a fallback when
|
|
2723
|
+
`app.yaml` has no `origin`; when both are set, `origin` in `app.yaml` wins. A
|
|
2724
|
+
trailing slash is stripped either way. A file copied before plugin-canonical-links 2.2.4 set
|
|
2725
|
+
`app_origin: https://example.com` and `available_languages` as active samples:
|
|
2726
|
+
delete those two keys, or set them to your own values.
|
|
1495
2727
|
|
|
1496
2728
|
With no origin at all, the plugin emits no canonical or alternate links and prints
|
|
1497
2729
|
one warning during the build:
|
|
@@ -1542,8 +2774,8 @@ Build and view the source of `pages/getting-started.md` — you'll see:
|
|
|
1542
2774
|
|
|
1543
2775
|
## 4. Link translations with hreflang
|
|
1544
2776
|
|
|
1545
|
-
Alternate-language links need three things. First,
|
|
1546
|
-
`config/canonical-links.yaml
|
|
2777
|
+
Alternate-language links need three things. First, uncomment
|
|
2778
|
+
`available_languages` in `config/canonical-links.yaml` and list your languages:
|
|
1547
2779
|
|
|
1548
2780
|
```yaml
|
|
1549
2781
|
page_identifier: slug
|
|
@@ -1553,8 +2785,8 @@ available_languages:
|
|
|
1553
2785
|
```
|
|
1554
2786
|
|
|
1555
2787
|
`page_identifier` names the frontmatter key that marks two pages as translations
|
|
1556
|
-
of each other; `slug` is the default,
|
|
1557
|
-
page sets its `lang`. Third, translations share an identical `slug`:
|
|
2788
|
+
of each other; `slug` is the default, and the copied file already sets it.
|
|
2789
|
+
Second, every page sets its `lang`. Third, translations share an identical `slug`:
|
|
1558
2790
|
|
|
1559
2791
|
```markdown
|
|
1560
2792
|
---
|
|
@@ -1624,7 +2856,11 @@ Generated pages have no `slug`, so they get a canonical link and no alternates.
|
|
|
1624
2856
|
The sitemap plugin, [`@nera-static/plugin-sitemap`](https://www.npmjs.com/package/@nera-static/plugin-sitemap),
|
|
1625
2857
|
reads the same origin (`origin` in `app.yaml`, else `app_origin`) and the same
|
|
1626
2858
|
`base_path`, so the URLs in your sitemap and your canonical links agree — on a
|
|
1627
|
-
`base_path` site from plugin-canonical-links 2.2.3 on.
|
|
2859
|
+
`base_path` site from plugin-canonical-links 2.2.3 on. Add it the same way:
|
|
2860
|
+
|
|
2861
|
+
```bash
|
|
2862
|
+
npx nera add sitemap
|
|
2863
|
+
```
|
|
1628
2864
|
|
|
1629
2865
|
This site uses the plugin as well, set up as this tutorial describes:
|
|
1630
2866
|
`origin: https://nera.js.org` in `config/app.yaml`, the root-absolute include in its layout,
|
|
@@ -1811,11 +3047,13 @@ in any view through `app.stacks`. Several blocks that form one section become a
|
|
|
1811
3047
|
## 1. Install
|
|
1812
3048
|
|
|
1813
3049
|
```bash
|
|
1814
|
-
|
|
3050
|
+
npx nera add stacks
|
|
1815
3051
|
```
|
|
1816
3052
|
|
|
1817
|
-
|
|
1818
|
-
|
|
3053
|
+
`nera add` installs the package and publishes its default template into
|
|
3054
|
+
`theme/views/vendor/plugin-stacks/` (section 4). It copies no config file, as
|
|
3055
|
+
the plugin needs none: stacks are defined in frontmatter. Nera finds the plugin
|
|
3056
|
+
on its own.
|
|
1819
3057
|
|
|
1820
3058
|
## 2. What makes a page a stack
|
|
1821
3059
|
|
|
@@ -1868,15 +3106,10 @@ plugin warns.
|
|
|
1868
3106
|
|
|
1869
3107
|
## 4. Render a stack through a template
|
|
1870
3108
|
|
|
1871
|
-
A stack can bring its own markup.
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
```
|
|
1876
|
-
|
|
1877
|
-
It lands in `theme/views/vendor/plugin-stacks/stack-template.pug`. Point a
|
|
1878
|
-
stack at it with **`stack_layout`**, a path from the **project root** (where
|
|
1879
|
-
you run `nera build`), not from the views folder:
|
|
3109
|
+
A stack can bring its own markup. `nera add` already published the plugin's
|
|
3110
|
+
default template to `theme/views/vendor/plugin-stacks/stack-template.pug`.
|
|
3111
|
+
Point a stack at it with **`stack_layout`**, a path from the **project root**
|
|
3112
|
+
(where you run `nera build`), not from the views folder:
|
|
1880
3113
|
|
|
1881
3114
|
```markdown:pages/stacks/call-to-action.md
|
|
1882
3115
|
---
|
|
@@ -2082,17 +3315,18 @@ you add a category, `notice: false` no longer applies, and the build says so:
|
|
|
2082
3315
|
## 2. Install and wire the layout
|
|
2083
3316
|
|
|
2084
3317
|
```bash
|
|
2085
|
-
|
|
2086
|
-
npx nera-consent-config
|
|
2087
|
-
npx nera-consent
|
|
3318
|
+
npx nera add consent
|
|
2088
3319
|
```
|
|
2089
3320
|
|
|
2090
|
-
`
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
`
|
|
2095
|
-
|
|
3321
|
+
`nera add` installs the package, copies its documented `config/consent.yaml`
|
|
3322
|
+
and publishes the five views (`banner`, `settings`, `notice`, `head`, `embed`)
|
|
3323
|
+
into `theme/views/vendor/plugin-consent/`. In the copied file `revision` and
|
|
3324
|
+
`notice` are set to their defaults and every example (`privacy_url`,
|
|
3325
|
+
`categories`, `texts`) is commented out, so the site starts in notice mode.
|
|
3326
|
+
Until you set `privacy_url`, the build warns that the notice links no privacy
|
|
3327
|
+
policy. `nera add` keeps a `config/consent.yaml` or a views folder that already
|
|
3328
|
+
exists. To overwrite them with the plugin's current versions, and your edits
|
|
3329
|
+
with them, run `npx nera-consent-config --force` and `npx nera-consent --force`.
|
|
2096
3330
|
|
|
2097
3331
|
Plugins cannot touch your layout, so this is the one manual step. Add the
|
|
2098
3332
|
stylesheet, the `head` view and the runtime inside `<head>`, a settings link
|
|
@@ -2563,22 +3797,22 @@ fit together.
|
|
|
2563
3797
|
```bash
|
|
2564
3798
|
npx @nera-static/nera new my-site
|
|
2565
3799
|
cd my-site
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
3800
|
+
npx nera add one-page
|
|
3801
|
+
npx nera add page-navigation
|
|
3802
|
+
npx nera add contact-form
|
|
3803
|
+
npx nera add social-media-links
|
|
3804
|
+
```
|
|
3805
|
+
|
|
3806
|
+
`nera add` takes one plugin per call. Each call installs the package, which
|
|
3807
|
+
Nera then finds on its own, and copies the plugin's default config into
|
|
3808
|
+
`config/`. Three of the four ship templates, and `nera add` publishes them into
|
|
3809
|
+
`theme/views/vendor/plugin-<name>/`, where they are yours to edit. The contact
|
|
3810
|
+
form's client script lands in `theme/assets/js/contact-form.js`.
|
|
3811
|
+
`plugin-one-page` ships no template. Its copied `config/one-page.yaml` only
|
|
3812
|
+
names the frontmatter keys it reads (`add_to_page`, `add_to_page_order`,
|
|
3813
|
+
`anchor_id` and the others). Leave it as it is, and
|
|
3814
|
+
`config/page-navigation.yaml` too, which sets the class of the active link.
|
|
3815
|
+
Steps 7 and 8 replace the other two files.
|
|
2582
3816
|
|
|
2583
3817
|
## 2. The target page
|
|
2584
3818
|
|
|
@@ -2847,7 +4081,9 @@ live in each page's frontmatter, next to the content they point to.
|
|
|
2847
4081
|
|
|
2848
4082
|
## 7. The contact form
|
|
2849
4083
|
|
|
2850
|
-
`plugin-contact-form` renders a form from `config/contact-form.yaml`.
|
|
4084
|
+
`plugin-contact-form` renders a form from `config/contact-form.yaml`. The copy
|
|
4085
|
+
`nera add` made documents every key, with the recipient commented out and a
|
|
4086
|
+
set of sample fields; replace it with this one. On submit
|
|
2851
4087
|
a small script in the browser builds a `mailto:` link from the fields and opens
|
|
2852
4088
|
the visitor's own email program with subject and message filled in. There is no
|
|
2853
4089
|
backend: your site stores and sends nothing, and the message leaves only through
|
|
@@ -2961,7 +4197,8 @@ fields.` in the status line. Three details are worth knowing:
|
|
|
2961
4197
|
## 8. Social links in the footer
|
|
2962
4198
|
|
|
2963
4199
|
`plugin-social-media-links` reads a list of links from
|
|
2964
|
-
`config/social-media-links.yaml
|
|
4200
|
+
`config/social-media-links.yaml`. In the copy `nera add` made, the list is a
|
|
4201
|
+
commented-out example, so nothing renders yet. Replace the file with:
|
|
2965
4202
|
|
|
2966
4203
|
```yaml:config/social-media-links.yaml
|
|
2967
4204
|
aria_label: Social media
|
|
@@ -2979,9 +4216,9 @@ social_media_links:
|
|
|
2979
4216
|
The `d` attribute is shortened here; paste the full path of the icon you use.
|
|
2980
4217
|
Simple Icons (simpleicons.org) has brand logos as SVG. `icon` is escaped unless
|
|
2981
4218
|
the entry sets `icon_raw: true`, so set it only for markup you wrote or checked
|
|
2982
|
-
yourself. The LinkedIn entry has no icon and shows its name only. The
|
|
2983
|
-
|
|
2984
|
-
CSS. Loading it from a CDN sends every visitor's IP address to a third party,
|
|
4219
|
+
yourself. The LinkedIn entry has no icon and shows its name only. The example
|
|
4220
|
+
list in the copied config uses Font Awesome `<i>` tags instead, which need the
|
|
4221
|
+
Font Awesome CSS. Loading it from a CDN sends every visitor's IP address to a third party,
|
|
2985
4222
|
and `nera build --check` then warns `privacy-third-party`. Inline SVG or plain
|
|
2986
4223
|
text needs no request at all.
|
|
2987
4224
|
|
|
@@ -3199,16 +4436,423 @@ particular spot of a layout.
|
|
|
3199
4436
|
- [How this website is built](https://nera.js.org/tutorials/how-this-site-is-built.html) shows a
|
|
3200
4437
|
complete Nera site with its plugins working together.
|
|
3201
4438
|
|
|
3202
|
-
#
|
|
4439
|
+
# Responsive images with plugin-images
|
|
3203
4440
|
|
|
3204
|
-
Source: https://nera.js.org/tutorials/
|
|
4441
|
+
Source: https://nera.js.org/tutorials/responsive-images.html
|
|
3205
4442
|
|
|
3206
|
-
|
|
3207
|
-
|
|
4443
|
+
A photo straight from a camera or a phone is several megabytes and thousands
|
|
4444
|
+
of pixels wide, and it carries metadata: the camera model, the time, often
|
|
4445
|
+
the GPS position where it was taken. Put it into a Markdown page as it is,
|
|
4446
|
+
and every visitor downloads all of that, on a phone too.
|
|
4447
|
+
`@nera-static/plugin-images` fixes this at build time. Every local image in
|
|
4448
|
+
your Markdown becomes a `<picture>` with AVIF and WebP in several widths,
|
|
4449
|
+
`srcset`/`sizes`, `width`/`height` and lazy loading, and the published files
|
|
4450
|
+
carry no metadata. Your Markdown does not change.
|
|
3208
4451
|
|
|
3209
|
-
|
|
4452
|
+
Every command, config and output below was run in a fresh `nera new` site
|
|
4453
|
+
with plugin-images 1.0.3, `@nera-static/core` 4.18.3 and
|
|
4454
|
+
`@nera-static/nera` 1.27.2. The photo is a 4000 × 3000 JPEG of 4 MB with
|
|
4455
|
+
camera and GPS data in its EXIF block.
|
|
3210
4456
|
|
|
3211
|
-
|
|
4457
|
+
## 1. Install
|
|
4458
|
+
|
|
4459
|
+
```bash
|
|
4460
|
+
npx nera add images
|
|
4461
|
+
```
|
|
4462
|
+
|
|
4463
|
+
`nera add` installs the package and publishes the plugin's one view, the
|
|
4464
|
+
`picture` mixin, into `theme/views/vendor/plugin-images/`:
|
|
4465
|
+
|
|
4466
|
+
```text
|
|
4467
|
+
✅ Copied picture.pug to …/theme/views/vendor/plugin-images/picture.pug
|
|
4468
|
+
✅ Templates copied to: …/theme/views/vendor/plugin-images
|
|
4469
|
+
✅ Added @nera-static/plugin-images
|
|
4470
|
+
Config: none (the plugin ships no default)
|
|
4471
|
+
Templates: published by the plugin
|
|
4472
|
+
```
|
|
4473
|
+
|
|
4474
|
+
There is nothing else to set up: a `config/images.yaml` is optional, and so
|
|
4475
|
+
is every key in it. Every official starter except `blank`
|
|
4476
|
+
(`nera new --starter …`) already ships the plugin.
|
|
4477
|
+
|
|
4478
|
+
## 2. Before and after
|
|
4479
|
+
|
|
4480
|
+
Put the photo into the site's assets, at
|
|
4481
|
+
`theme/assets/images/photos/pier.jpg`, and use it in a page like any image:
|
|
4482
|
+
|
|
4483
|
+
```markdown:pages/pier.md
|
|
4484
|
+
---
|
|
4485
|
+
layout: pages/default.pug
|
|
4486
|
+
title: The pier
|
|
4487
|
+
description: A photo of the pier at dusk
|
|
4488
|
+
---
|
|
4489
|
+
# The pier
|
|
4490
|
+
|
|
4491
|
+

|
|
4492
|
+
```
|
|
4493
|
+
|
|
4494
|
+
Without the plugin, `nera build` turns this into a plain `<img>` that points
|
|
4495
|
+
at the 4 MB original:
|
|
4496
|
+
|
|
4497
|
+
```html
|
|
4498
|
+
<p><img src="/images/photos/pier.jpg" alt="The pier at dusk, seen from the beach"></p>
|
|
4499
|
+
```
|
|
4500
|
+
|
|
4501
|
+
With the plugin, the first build encodes the variants:
|
|
4502
|
+
|
|
4503
|
+
```text
|
|
4504
|
+
🖼️ plugin-images: 1 image(s), 12 variant(s) encoded
|
|
4505
|
+
```
|
|
4506
|
+
|
|
4507
|
+
and `public/pier.html` holds:
|
|
4508
|
+
|
|
4509
|
+
```html
|
|
4510
|
+
<p>
|
|
4511
|
+
<picture>
|
|
4512
|
+
<source type="image/avif" srcset="/_img/pier-1a5869e3-480.avif 480w, /_img/pier-1a5869e3-800.avif 800w, /_img/pier-1a5869e3-1200.avif 1200w, /_img/pier-1a5869e3-1600.avif 1600w" sizes="100vw">
|
|
4513
|
+
<source type="image/webp" srcset="/_img/pier-987422b0-480.webp 480w, /_img/pier-987422b0-800.webp 800w, /_img/pier-987422b0-1200.webp 1200w, /_img/pier-987422b0-1600.webp 1600w" sizes="100vw"><img src="/_img/pier-10e7e41a-1600.jpg" srcset="/_img/pier-10e7e41a-480.jpg 480w, /_img/pier-10e7e41a-800.jpg 800w, /_img/pier-10e7e41a-1200.jpg 1200w, /_img/pier-10e7e41a-1600.jpg 1600w" sizes="100vw" width="1600" height="1200" alt="The pier at dusk, seen from the beach" loading="eager" fetchpriority="high">
|
|
4514
|
+
</picture>
|
|
4515
|
+
</p>
|
|
4516
|
+
```
|
|
4517
|
+
|
|
4518
|
+
- The browser picks the first format it supports, AVIF, then WebP, and the
|
|
4519
|
+
`<img>` is the fallback. It keeps the source's format (JPEG stays JPEG, PNG
|
|
4520
|
+
stays PNG) and always points at a processed variant, never the original.
|
|
4521
|
+
- The widths are the default `480, 800, 1200, 1600`. A source is never
|
|
4522
|
+
upscaled: a photo 1000 pixels wide gets 480 and 800 only.
|
|
4523
|
+
- `width` and `height` are the largest variant's size, so the browser
|
|
4524
|
+
reserves the space before the image loads and the page does not jump.
|
|
4525
|
+
- The first image on a page loads eagerly with `fetchpriority="high"`, since
|
|
4526
|
+
it is usually the largest thing on the screen. Every later image gets
|
|
4527
|
+
`loading="lazy" decoding="async"`.
|
|
4528
|
+
- `alt` and every other attribute of your image are kept. The plugin never
|
|
4529
|
+
writes an `alt` for you.
|
|
4530
|
+
|
|
4531
|
+
The variants land in `public/_img/`, with a hash of the source and the
|
|
4532
|
+
settings in each name, so a URL changes only when the image does. The
|
|
4533
|
+
variants carry no EXIF, GPS or ICC data: the plugin applies the EXIF
|
|
4534
|
+
orientation and then strips all of it.
|
|
4535
|
+
|
|
4536
|
+
On the plugin's field-test site, a German/English blog, the 32 content images
|
|
4537
|
+
went from 4.2 MB of originals to 0.45 MB of AVIF a phone downloads.
|
|
4538
|
+
|
|
4539
|
+
The plugin leaves alone what it should not touch: SVG and GIF, external
|
|
4540
|
+
`http(s)://` URLs, an `<img>` that already has a `srcset` or sits inside a
|
|
4541
|
+
`<picture>`, and any image with `?skip` on its URL. An image file that does
|
|
4542
|
+
not exist stays a plain `<img>`, and the build says so:
|
|
4543
|
+
|
|
4544
|
+
```text
|
|
4545
|
+
⚠️ plugin-images: /pier.html: image not found, left as is: /images/photos/missing.jpg
|
|
4546
|
+
```
|
|
4547
|
+
|
|
4548
|
+
Images in your Pug **views** are not processed. For those, use frontmatter
|
|
4549
|
+
images and the mixin (step 5).
|
|
4550
|
+
|
|
4551
|
+
## 3. Query parameters
|
|
4552
|
+
|
|
4553
|
+
Add parameters to the image URL to change one image. The parameters never
|
|
4554
|
+
reach the published URLs. This one is at most 800 pixels wide, cropped to
|
|
4555
|
+
16:9 around a point 30 % from the left and 60 % from the top:
|
|
4556
|
+
|
|
4557
|
+
```markdown:pages/pier.md
|
|
4558
|
+

|
|
4559
|
+
```
|
|
4560
|
+
|
|
4561
|
+
```html
|
|
4562
|
+
<picture>
|
|
4563
|
+
<source type="image/avif" srcset="/_img/pier-7a863ccf-480.avif 480w, /_img/pier-7a863ccf-800.avif 800w, /_img/pier-7a863ccf-1600.avif 1600w" sizes="(min-width: 800px) 800px, 100vw">
|
|
4564
|
+
<source type="image/webp" srcset="/_img/pier-f3e554c6-480.webp 480w, /_img/pier-f3e554c6-800.webp 800w, /_img/pier-f3e554c6-1600.webp 1600w" sizes="(min-width: 800px) 800px, 100vw"><img src="/_img/pier-85ac4388-1600.jpg" srcset="/_img/pier-85ac4388-480.jpg 480w, /_img/pier-85ac4388-800.jpg 800w, /_img/pier-85ac4388-1600.jpg 1600w" sizes="(min-width: 800px) 800px, 100vw" width="1600" height="900" alt="The end of the pier" loading="lazy" decoding="async">
|
|
4565
|
+
</picture>
|
|
4566
|
+
```
|
|
4567
|
+
|
|
4568
|
+
`?w=800` keeps the configured widths below 800, adds 800 and 1600 (for
|
|
4569
|
+
screens with twice the pixel density) and sets a matching `sizes`. The crop
|
|
4570
|
+
makes the image 1600 × 900. The parameters:
|
|
4571
|
+
|
|
4572
|
+
| Parameter | What it does | Example |
|
|
4573
|
+
|---|---|---|
|
|
4574
|
+
| `w` | Maximum display width in pixels | `?w=800` |
|
|
4575
|
+
| `h` | Target height; with `w` it crops | `?w=800&h=450` |
|
|
4576
|
+
| `ratio` | Crop to an aspect ratio | `?ratio=16:9` |
|
|
4577
|
+
| `fit` | `cover` (the default for a crop), `contain` or `inside` | `?fit=contain` |
|
|
4578
|
+
| `focus` | Focal point of a crop in percent, or `attention` / `entropy` | `?focus=30,60` |
|
|
4579
|
+
| `q` | Quality for all formats, 1–100 | `?q=60` |
|
|
4580
|
+
| `formats` | Modern formats for this image, or `none` | `?formats=webp` |
|
|
4581
|
+
| `sizes` | `sizes` for this image, URL-encoded | `?sizes=50vw` |
|
|
4582
|
+
| `loading` | `eager` or `lazy`, overriding the first-image rule | `?loading=eager` |
|
|
4583
|
+
| `skip` | Leave this image untouched | `?skip` |
|
|
4584
|
+
|
|
4585
|
+
A parameter the plugin does not know is ignored with a warning, so a typo
|
|
4586
|
+
does not go unnoticed:
|
|
4587
|
+
|
|
4588
|
+
```text
|
|
4589
|
+
⚠️ plugin-images: /pier.html: unknown parameter "width" ignored: /images/photos/pier.jpg?width=800
|
|
4590
|
+
```
|
|
4591
|
+
|
|
4592
|
+
## 4. Captions
|
|
4593
|
+
|
|
4594
|
+
Give an image a Markdown title, and put it alone in its paragraph:
|
|
4595
|
+
|
|
4596
|
+
```markdown:pages/pier.md
|
|
4597
|
+

|
|
4598
|
+
```
|
|
4599
|
+
|
|
4600
|
+
It becomes a `<figure>` with the title as its caption. The `<figure>`
|
|
4601
|
+
replaces the paragraph, since a `<figure>` inside a `<p>` is invalid HTML:
|
|
4602
|
+
|
|
4603
|
+
```html
|
|
4604
|
+
<figure class="nera-image">
|
|
4605
|
+
<picture>
|
|
4606
|
+
<source type="image/avif" srcset="/_img/pier-1a5869e3-480.avif 480w, /_img/pier-1a5869e3-800.avif 800w, /_img/pier-1a5869e3-1200.avif 1200w, /_img/pier-1a5869e3-1600.avif 1600w" sizes="100vw">
|
|
4607
|
+
<source type="image/webp" srcset="/_img/pier-987422b0-480.webp 480w, /_img/pier-987422b0-800.webp 800w, /_img/pier-987422b0-1200.webp 1200w, /_img/pier-987422b0-1600.webp 1600w" sizes="100vw"><img src="/_img/pier-10e7e41a-1600.jpg" srcset="/_img/pier-10e7e41a-480.jpg 480w, /_img/pier-10e7e41a-800.jpg 800w, /_img/pier-10e7e41a-1200.jpg 1200w, /_img/pier-10e7e41a-1600.jpg 1600w" sizes="100vw" width="1600" height="1200" alt="The pier at dusk" loading="lazy" decoding="async">
|
|
4608
|
+
</picture>
|
|
4609
|
+
<figcaption class="nera-image__caption">Usedom, October 2026</figcaption>
|
|
4610
|
+
</figure>
|
|
4611
|
+
```
|
|
4612
|
+
|
|
4613
|
+
The same photo as in step 2 reuses the same variants: nothing is encoded
|
|
4614
|
+
twice. An image inline with text, inside a link or next to another image
|
|
4615
|
+
keeps its `title` and gets no figure. `figure: false` in
|
|
4616
|
+
`config/images.yaml` turns captions off. The classes `nera-image` and
|
|
4617
|
+
`nera-image__caption` are the plugin's public markup, so style them in your
|
|
4618
|
+
own CSS.
|
|
4619
|
+
|
|
4620
|
+
## 5. Frontmatter images and the `+picture` mixin
|
|
4621
|
+
|
|
4622
|
+
A blog post's hero or teaser image usually sits in the frontmatter and is
|
|
4623
|
+
rendered by a view, not by the Markdown. Name it under `image`:
|
|
4624
|
+
|
|
4625
|
+
```markdown:pages/beach.md
|
|
4626
|
+
---
|
|
4627
|
+
layout: pages/post.pug
|
|
4628
|
+
title: A day at the beach
|
|
4629
|
+
description: A post with a hero image
|
|
4630
|
+
image: /images/photos/beach.jpg
|
|
4631
|
+
image_alt: Waves on an empty beach
|
|
4632
|
+
---
|
|
4633
|
+
# A day at the beach
|
|
4634
|
+
|
|
4635
|
+
The hero image above comes from the frontmatter.
|
|
4636
|
+
```
|
|
4637
|
+
|
|
4638
|
+
The plugin encodes the variants for it and puts the finished data into
|
|
4639
|
+
`meta.images.image`: `src`, `srcset`, `sizes`, `width`, `height`, the
|
|
4640
|
+
`sources` per format, and an `og` crop. `meta.image` itself stays the string
|
|
4641
|
+
you wrote, so views and plugins that read it keep working. Query parameters
|
|
4642
|
+
work here too (`image: /images/photos/beach.jpg?ratio=16:9`). More keys
|
|
4643
|
+
than `image` go into `frontmatter_keys` in `config/images.yaml`.
|
|
4644
|
+
|
|
4645
|
+
The mixin `nera add` published renders the entry:
|
|
4646
|
+
|
|
4647
|
+
```pug:theme/views/pages/post.pug
|
|
4648
|
+
extends ../layouts/layout
|
|
4649
|
+
|
|
4650
|
+
block content
|
|
4651
|
+
main#main
|
|
4652
|
+
include /vendor/plugin-images/picture
|
|
4653
|
+
+picture(meta.images && meta.images.image, { alt: meta.image_alt, loading: 'eager' })
|
|
4654
|
+
!= content
|
|
4655
|
+
```
|
|
4656
|
+
|
|
4657
|
+
```html
|
|
4658
|
+
<picture>
|
|
4659
|
+
<source type="image/avif" srcset="/_img/beach-04a0334d-480.avif 480w, /_img/beach-04a0334d-800.avif 800w, /_img/beach-04a0334d-1200.avif 1200w, /_img/beach-04a0334d-1600.avif 1600w" sizes="100vw" />
|
|
4660
|
+
<source type="image/webp" srcset="/_img/beach-2fc7c78b-480.webp 480w, /_img/beach-2fc7c78b-800.webp 800w, /_img/beach-2fc7c78b-1200.webp 1200w, /_img/beach-2fc7c78b-1600.webp 1600w" sizes="100vw" /><img src="/_img/beach-376379b1-1600.jpg" srcset="/_img/beach-376379b1-480.jpg 480w, /_img/beach-376379b1-800.jpg 800w, /_img/beach-376379b1-1200.jpg 1200w, /_img/beach-376379b1-1600.jpg 1600w" sizes="100vw" width="1600" height="1200" alt="Waves on an empty beach" loading="eager" fetchpriority="high" />
|
|
4661
|
+
</picture>
|
|
4662
|
+
```
|
|
4663
|
+
|
|
4664
|
+
A page without the frontmatter key renders nothing there. The mixin's options
|
|
4665
|
+
are `alt`, `class`, `sizes` and `loading` (`lazy` by default; `eager` adds
|
|
4666
|
+
`fetchpriority="high"`). A hero above the content is the page's largest
|
|
4667
|
+
image, so render it with `loading: 'eager'` as above, and set
|
|
4668
|
+
`eager_first: false` in `config/images.yaml`, so the first Markdown image
|
|
4669
|
+
below it does not compete for the same priority.
|
|
4670
|
+
|
|
4671
|
+
### `og:image`
|
|
4672
|
+
|
|
4673
|
+
The `og` entry is a 1200 × 630 JPEG, the size link previews in social
|
|
4674
|
+
networks and chat apps expect. `og:image` must be an absolute URL, so set
|
|
4675
|
+
your origin in `config/app.yaml`:
|
|
4676
|
+
|
|
4677
|
+
```yaml:config/app.yaml
|
|
4678
|
+
origin: https://example.com
|
|
4679
|
+
```
|
|
4680
|
+
|
|
4681
|
+
and add the tags inside the layout's `head`, after the other `meta` tags:
|
|
4682
|
+
|
|
4683
|
+
```pug:theme/views/layouts/layout.pug
|
|
4684
|
+
if meta.images && meta.images.image && meta.images.image.og
|
|
4685
|
+
- const og = meta.images.image.og
|
|
4686
|
+
meta(property="og:image" content=`${app.origin}${app.basePath || ''}${og.src}`)
|
|
4687
|
+
meta(property="og:image:width" content=og.width)
|
|
4688
|
+
meta(property="og:image:height" content=og.height)
|
|
4689
|
+
```
|
|
4690
|
+
|
|
4691
|
+
`public/beach.html` then has:
|
|
4692
|
+
|
|
4693
|
+
```html
|
|
4694
|
+
<meta property="og:image" content="https://example.com/_img/beach-a82641dd-1200.jpg" />
|
|
4695
|
+
<meta property="og:image:width" content="1200" />
|
|
4696
|
+
<meta property="og:image:height" content="630" />
|
|
4697
|
+
```
|
|
4698
|
+
|
|
4699
|
+
`app.basePath` is there for a site served from a subfolder: core rewrites
|
|
4700
|
+
`href` and `src` for `base_path`, but not the `content` of a `<meta>`.
|
|
4701
|
+
|
|
4702
|
+
## 6. Placeholders
|
|
4703
|
+
|
|
4704
|
+
While an image loads, its box is empty. A placeholder fills it:
|
|
4705
|
+
|
|
4706
|
+
```yaml:config/images.yaml
|
|
4707
|
+
placeholder: color
|
|
4708
|
+
```
|
|
4709
|
+
|
|
4710
|
+
sets the image's dominant colour as its background:
|
|
4711
|
+
|
|
4712
|
+
```html
|
|
4713
|
+
<img src="/_img/pier-10e7e41a-1600.jpg" srcset="/_img/pier-10e7e41a-480.jpg 480w, /_img/pier-10e7e41a-800.jpg 800w, /_img/pier-10e7e41a-1200.jpg 1200w, /_img/pier-10e7e41a-1600.jpg 1600w" sizes="100vw" width="1600" height="1200" style="background-color:#383898" alt="The pier at dusk, seen from the beach" loading="eager" fetchpriority="high">
|
|
4714
|
+
```
|
|
4715
|
+
|
|
4716
|
+
`placeholder: blur` sets a tiny blurred WebP instead, inline in the page:
|
|
4717
|
+
|
|
4718
|
+
```html
|
|
4719
|
+
<img src="/_img/pier-10e7e41a-1600.jpg" srcset="/_img/pier-10e7e41a-480.jpg 480w, /_img/pier-10e7e41a-800.jpg 800w, /_img/pier-10e7e41a-1200.jpg 1200w, /_img/pier-10e7e41a-1600.jpg 1600w" sizes="100vw" width="1600" height="1200" style="background-image:url(data:image/webp;base64,UklGRkIAAABXRUJQVlA4IDYAAACwAQCdASoQAAwAAsBMJbACdAEOtNWAAP7xfmtUemnWsBu+y/mBlsjTsVhsr/7FRn95mxzwAAA=);background-size:cover" alt="The pier at dusk, seen from the beach" loading="eager" fetchpriority="high">
|
|
4720
|
+
```
|
|
4721
|
+
|
|
4722
|
+
The build reports them:
|
|
4723
|
+
|
|
4724
|
+
```text
|
|
4725
|
+
🖼️ plugin-images: 4 image(s), 0 variant(s) encoded, 3 placeholder(s) computed
|
|
4726
|
+
```
|
|
4727
|
+
|
|
4728
|
+
Both work for Markdown images and for frontmatter images (the mixin renders
|
|
4729
|
+
the `style`). An image with transparency gets none, because the background
|
|
4730
|
+
would stay visible through it. The default is `none`, because a placeholder
|
|
4731
|
+
is an inline `style` attribute, which a Content Security Policy without
|
|
4732
|
+
`'unsafe-inline'` in `style-src` blocks.
|
|
4733
|
+
|
|
4734
|
+
A value the plugin does not know, or a key it does not know, warns and falls
|
|
4735
|
+
back to the default; neither fails the build:
|
|
4736
|
+
|
|
4737
|
+
```text
|
|
4738
|
+
⚠️ plugin-images: config/images.yaml: invalid placeholder "smudge", using "none"
|
|
4739
|
+
⚠️ plugin-images: config/images.yaml: ignoring unknown key "width"
|
|
4740
|
+
```
|
|
4741
|
+
|
|
4742
|
+
## 7. Keep your originals off the server
|
|
4743
|
+
|
|
4744
|
+
The variants are clean, but by default the original is still published: in
|
|
4745
|
+
step 2, `public/images/photos/pier.jpg` is the 4 MB file with its camera and
|
|
4746
|
+
GPS data, reachable by anyone who guesses the URL. The plugin reads images
|
|
4747
|
+
from the assets folder **regardless of `.neraignore`**, so list the photo
|
|
4748
|
+
folder there:
|
|
4749
|
+
|
|
4750
|
+
```text:.neraignore
|
|
4751
|
+
images/photos
|
|
4752
|
+
```
|
|
4753
|
+
|
|
4754
|
+
The paths are relative to the assets folder. After the next build,
|
|
4755
|
+
`public/` has no `images/` folder at all; the pages still show every photo,
|
|
4756
|
+
from `public/_img/`. The originals stay in your repository.
|
|
4757
|
+
|
|
4758
|
+
Check first what else lives in that folder. `.neraignore` matches exact
|
|
4759
|
+
paths and folder prefixes, no glob patterns, and everything in a listed
|
|
4760
|
+
folder the plugin does not process is no longer published: SVGs, GIFs,
|
|
4761
|
+
files you link for download, and images your views use directly, such as an
|
|
4762
|
+
`img(src=meta.image)` or an `og:image` built from `meta.image`. Render those
|
|
4763
|
+
from `meta.images` (step 5). A folder that holds only photos for your pages is
|
|
4764
|
+
the safe case.
|
|
4765
|
+
|
|
4766
|
+
`nera build --check` looks at the built `public/`, for third-party requests
|
|
4767
|
+
among other things; the [CLI reference](https://nera.js.org/docs/cli.html#checking-the-built-site)
|
|
4768
|
+
describes the checks. For this site it reports:
|
|
4769
|
+
|
|
4770
|
+
```text
|
|
4771
|
+
✓ No problems found.
|
|
4772
|
+
```
|
|
4773
|
+
|
|
4774
|
+
## 8. The cache, locally and in CI
|
|
4775
|
+
|
|
4776
|
+
Encoding AVIF is slow. The plugin therefore keeps every variant in
|
|
4777
|
+
`.nera-cache/images/` and encodes only what is missing. With the test site's
|
|
4778
|
+
four images (three on the pier page, the hero of the beach post), a build
|
|
4779
|
+
with an empty cache reports:
|
|
4780
|
+
|
|
4781
|
+
```text
|
|
4782
|
+
🖼️ plugin-images: 4 image(s), 34 variant(s) encoded
|
|
4783
|
+
```
|
|
4784
|
+
|
|
4785
|
+
and took 5.3 seconds; the next build:
|
|
4786
|
+
|
|
4787
|
+
```text
|
|
4788
|
+
🖼️ plugin-images: 4 image(s), 0 variant(s) encoded
|
|
4789
|
+
```
|
|
4790
|
+
|
|
4791
|
+
took 0.9. On a site with a hundred photos, a cold build takes a minute or
|
|
4792
|
+
more. Variants no page uses any more are removed from the cache
|
|
4793
|
+
(`prune: true`).
|
|
4794
|
+
|
|
4795
|
+
`nera new` lists `.nera-cache` in the site's `.gitignore` (since
|
|
4796
|
+
`@nera-static/nera` 1.4.1), so the cache never lands in your repository. In
|
|
4797
|
+
CI, keep it between runs instead. The deploy workflow `nera publish` writes
|
|
4798
|
+
already does that (since `@nera-static/nera` 1.22.0). In a workflow of your
|
|
4799
|
+
own, add this step before `npm run build`:
|
|
4800
|
+
|
|
4801
|
+
```yaml
|
|
4802
|
+
- uses: actions/cache@v6
|
|
4803
|
+
with:
|
|
4804
|
+
path: .nera-cache
|
|
4805
|
+
key: nera-cache-${{ hashFiles('assets/**', 'theme/assets/**', 'pages/**', 'config/images.yaml', 'package-lock.json') }}
|
|
4806
|
+
restore-keys: nera-cache-
|
|
4807
|
+
```
|
|
4808
|
+
|
|
4809
|
+
The key covers `pages/**` because pages ask for variants (query parameters,
|
|
4810
|
+
frontmatter images), and `package-lock.json` because a theme from npm brings
|
|
4811
|
+
its own images. `actions/cache` saves nothing when the key matches exactly,
|
|
4812
|
+
so a key that misses one of them leaves new variants unsaved, and every build
|
|
4813
|
+
encodes them again.
|
|
4814
|
+
|
|
4815
|
+
## 9. Requirements
|
|
4816
|
+
|
|
4817
|
+
The plugin needs **`@nera-static/core` 4.13.0 or later**: it hands its
|
|
4818
|
+
variants to core through the `getAssets` hook, which copies them into
|
|
4819
|
+
`public/`. Every current `@nera-static/nera` brings a newer core. On an older
|
|
4820
|
+
core the build stops, rather than publish pages that link to images which
|
|
4821
|
+
were never copied. With core 4.12.0:
|
|
4822
|
+
|
|
4823
|
+
```text
|
|
4824
|
+
❌ plugin-images: @nera-static/core 4.12.0 is too old; this plugin needs >= 4.13.0 (the getAssets hook). Without it, pages would link to image files that are never copied to public/. Update with `npm update @nera-static/nera` (or `@nera-static/core`).
|
|
4825
|
+
```
|
|
4826
|
+
|
|
4827
|
+
The build exits with code 1.
|
|
4828
|
+
|
|
4829
|
+
The encoding runs on [sharp](https://sharp.pixelplumbing.com), a native
|
|
4830
|
+
module. It installs a prebuilt binary for your platform (macOS, Linux and
|
|
4831
|
+
Windows, on x64 and arm64), and the site's `package-lock.json` lists the
|
|
4832
|
+
binaries of every platform as optional dependencies, so `npm ci` on a Linux
|
|
4833
|
+
CI runner picks its own even when the lockfile was written on a Mac. Do not
|
|
4834
|
+
install with `--omit=optional`, which leaves the binary out. The plugin needs
|
|
4835
|
+
Node.js 20.18.1 or later.
|
|
4836
|
+
|
|
4837
|
+
The plugin's [README](https://github.com/seebaermichi/nera-plugin-images#readme)
|
|
4838
|
+
and [npm page](https://www.npmjs.com/package/@nera-static/plugin-images) have
|
|
4839
|
+
every config key with its default.
|
|
4840
|
+
|
|
4841
|
+
## Next
|
|
4842
|
+
|
|
4843
|
+
[How this website is built](https://nera.js.org/tutorials/how-this-site-is-built.html) shows the
|
|
4844
|
+
plugins of this site working together.
|
|
4845
|
+
|
|
4846
|
+
# How this website is built
|
|
4847
|
+
|
|
4848
|
+
Source: https://nera.js.org/tutorials/how-this-site-is-built.html
|
|
4849
|
+
|
|
4850
|
+
This whole site is built with Nera. Nothing here is special-cased — it's the same
|
|
4851
|
+
generator and the same public plugins you'd install. Here's the full recipe.
|
|
4852
|
+
|
|
4853
|
+
## Scaffolded like any site
|
|
4854
|
+
|
|
4855
|
+
It started with the nera CLI, which scaffolds a site whose one Nera dependency is
|
|
3212
4856
|
`@nera-static/nera` (it brings the `@nera-static/core` engine):
|
|
3213
4857
|
|
|
3214
4858
|
```bash
|
|
@@ -3261,8 +4905,9 @@ ordering is load-bearing on this site.
|
|
|
3261
4905
|
## Templates we own
|
|
3262
4906
|
|
|
3263
4907
|
Plugins that ship views were published into `theme/views/vendor/` with commands like
|
|
3264
|
-
`npx nera-navigation`.
|
|
3265
|
-
|
|
4908
|
+
`npx nera-navigation`. Today `npx nera add <name>` runs that command for you, in the
|
|
4909
|
+
same step as the install and the copy of the plugin's default config. Those copies
|
|
4910
|
+
are ours to edit and style — nothing important is hidden inside `node_modules`.
|
|
3266
4911
|
|
|
3267
4912
|
## Content is just Markdown
|
|
3268
4913
|
|
|
@@ -3286,7 +4931,7 @@ locally:
|
|
|
3286
4931
|
```bash
|
|
3287
4932
|
npm ci
|
|
3288
4933
|
npm run lint # eslint
|
|
3289
|
-
npm test # node --test on the
|
|
4934
|
+
npm test # node --test on the local plugins' and scripts' tests
|
|
3290
4935
|
npm run validate # nera validate: layouts, includes, frontmatter
|
|
3291
4936
|
npm run build -- --check # nera build --check
|
|
3292
4937
|
```
|
|
@@ -3296,9 +4941,521 @@ legal-notice problems and reports what it finds. Findings are warnings, so they
|
|
|
3296
4941
|
fail the run only for a rule that `config/validate.yaml` promotes to an error.
|
|
3297
4942
|
|
|
3298
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`,
|
|
3299
|
-
`npm run build`,
|
|
3300
|
-
|
|
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.
|
|
3301
4948
|
|
|
3302
4949
|
That's the entire stack: Markdown in, static HTML out, plugins for the rest. If
|
|
3303
4950
|
you've read the other tutorials in this section, you've now seen every piece of it
|
|
3304
4951
|
in isolation — this is just all of them together.
|
|
4952
|
+
|
|
4953
|
+
# Use and customise a theme
|
|
4954
|
+
|
|
4955
|
+
Source: https://nera.js.org/tutorials/use-a-theme.html
|
|
4956
|
+
|
|
4957
|
+
A Nera theme is an npm package: layouts, page types, partials, a stylesheet
|
|
4958
|
+
and a set of design tokens. Your site does not copy it. It installs the
|
|
4959
|
+
package and puts a file of its own next to it only where it wants something
|
|
4960
|
+
different. Every other file still comes from the package, so `npm update`
|
|
4961
|
+
keeps bringing the theme's fixes, like a child theme in WordPress.
|
|
4962
|
+
|
|
4963
|
+
This tutorial uses `@nera-static/theme-business`, the theme of the business
|
|
4964
|
+
and portfolio starters. You change a colour, add a few CSS rules, replace one
|
|
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.
|
|
4971
|
+
|
|
4972
|
+
## 1. Start a site with a theme
|
|
4973
|
+
|
|
4974
|
+
```bash
|
|
4975
|
+
npx @nera-static/nera new my-site --theme business
|
|
4976
|
+
cd my-site
|
|
4977
|
+
```
|
|
4978
|
+
|
|
4979
|
+
```text
|
|
4980
|
+
📦 Creating a new Nera site in …/my-site...
|
|
4981
|
+
✓ Configured project as "my-site"
|
|
4982
|
+
✓ Using theme "business" (@nera-static/theme-business)
|
|
4983
|
+
• pages/imprint.md and pages/privacy.md are placeholders: link them from the theme's layout (theme-blog and theme-business take `footer_links` in config/theme.yaml), or `nera build --check` keeps warning legal-imprint-link and legal-privacy-link.
|
|
4984
|
+
```
|
|
4985
|
+
|
|
4986
|
+
`--theme business` does two things. It adds the package to `package.json`:
|
|
4987
|
+
|
|
4988
|
+
```json
|
|
4989
|
+
"dependencies": {
|
|
4990
|
+
"@nera-static/nera": "^1.29.0",
|
|
4991
|
+
"@nera-static/theme-business": "^1.0.3"
|
|
4992
|
+
}
|
|
4993
|
+
```
|
|
4994
|
+
|
|
4995
|
+
and it names the theme in `config/app.yaml`:
|
|
4996
|
+
|
|
4997
|
+
```yaml:config/app.yaml
|
|
4998
|
+
theme: business
|
|
4999
|
+
```
|
|
5000
|
+
|
|
5001
|
+
`business` is short for `@nera-static/theme-business`. The site gets no
|
|
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/`.
|
|
5005
|
+
|
|
5006
|
+
Want sample pages for services, opening hours and contact as well? The
|
|
5007
|
+
business starter brings the same theme with them:
|
|
5008
|
+
`npx @nera-static/nera new my-site --starter business`.
|
|
5009
|
+
|
|
5010
|
+
## 2. Make the first build clean
|
|
5011
|
+
|
|
5012
|
+
Build with the output checks:
|
|
5013
|
+
|
|
5014
|
+
```bash
|
|
5015
|
+
npx nera build --check
|
|
5016
|
+
```
|
|
5017
|
+
|
|
5018
|
+
```text
|
|
5019
|
+
public/imprint.html
|
|
5020
|
+
:44 warning page has more than one `<h1>` — one main heading per page keeps its outline clear; keep one and make the others `<h2>` (WCAG 1.3.1, best practice) (on 3 pages, e.g. public/imprint.html, public/index.html, public/privacy.html) a11y-h1
|
|
5021
|
+
:33 warning page has no link whose text names the imprint (Impressum, Imprint, Legal notice) — it should be easy to find and directly reachable from every page; link it from the layout, such as in the footer, or, if it is linked under another name, set `legal.imprint` in config/validate.yaml (§ 5 DDG) (on 3 pages, e.g. public/imprint.html, public/index.html, public/privacy.html) legal-imprint-link
|
|
5022
|
+
:33 warning page has no link whose text names the privacy policy (Datenschutz, Privacy, Data protection) — it should be easy to find and directly reachable from every page; link it from the layout, such as in the footer, or, if it is linked under another name, set `legal.privacy` in config/validate.yaml (Art. 13 DSGVO) (on 3 pages, e.g. public/imprint.html, public/index.html, public/privacy.html) legal-privacy-link
|
|
5023
|
+
|
|
5024
|
+
0 error(s), 3 warning(s)
|
|
5025
|
+
```
|
|
5026
|
+
|
|
5027
|
+
Both come from the scaffolded pages, not from the theme:
|
|
5028
|
+
|
|
5029
|
+
- The theme renders the page's `title` as its one `<h1>`, so a page's
|
|
5030
|
+
Markdown starts at `##`. Delete the `# Welcome to Nera`, `# Imprint` and
|
|
5031
|
+
`# Privacy` lines from the three pages.
|
|
5032
|
+
- The footer links the legal pages you list. Create the site's own
|
|
5033
|
+
`config/theme.yaml`:
|
|
5034
|
+
|
|
5035
|
+
```yaml:config/theme.yaml
|
|
5036
|
+
footer_links:
|
|
5037
|
+
- label: Imprint
|
|
5038
|
+
href: /imprint.html
|
|
5039
|
+
- label: Privacy
|
|
5040
|
+
href: /privacy.html
|
|
5041
|
+
```
|
|
5042
|
+
|
|
5043
|
+
Build again:
|
|
5044
|
+
|
|
5045
|
+
```text
|
|
5046
|
+
✓ No problems found.
|
|
5047
|
+
```
|
|
5048
|
+
|
|
5049
|
+
The footer now carries:
|
|
5050
|
+
|
|
5051
|
+
```html
|
|
5052
|
+
<nav class="site-footer__legal" aria-label="Legal"><a href="/imprint.html">Imprint</a><a href="/privacy.html">Privacy</a></nav>
|
|
5053
|
+
```
|
|
5054
|
+
|
|
5055
|
+
Replace the two placeholder pages with your own texts before you publish.
|
|
5056
|
+
|
|
5057
|
+
## 3. How a theme and your site share the work
|
|
5058
|
+
|
|
5059
|
+
Nera looks for every view and every asset in two places, your site first:
|
|
5060
|
+
|
|
5061
|
+
| what | your site | the theme package |
|
|
5062
|
+
|---|---|---|
|
|
5063
|
+
| views | `theme/views/<path>` | `node_modules/@nera-static/theme-business/views/<path>` |
|
|
5064
|
+
| assets | `theme/assets/<path>` | `node_modules/@nera-static/theme-business/assets/<path>` |
|
|
5065
|
+
| settings | `config/theme.yaml` | the package's `config/theme.yaml` |
|
|
5066
|
+
|
|
5067
|
+
A file in your site wins over the theme's file **of the same path**, and only
|
|
5068
|
+
that one file. Everything you do not override comes from the package. Assets
|
|
5069
|
+
are copied theme first, then your site's, so `public/` ends up with both, and
|
|
5070
|
+
yours on top. Your `config/theme.yaml` is merged key by key over the theme's
|
|
5071
|
+
defaults: you set only what you change (lists such as `footer_links` are
|
|
5072
|
+
replaced as a whole).
|
|
5073
|
+
|
|
5074
|
+
The theme's README has a table of what to change where. From cheapest to
|
|
5075
|
+
most expensive:
|
|
5076
|
+
|
|
5077
|
+
| to change | do this | you keep theme updates for |
|
|
5078
|
+
|---|---|---|
|
|
5079
|
+
| a colour, a font, a width | a token in `config/theme.yaml` | everything |
|
|
5080
|
+
| a few CSS rules | `theme/assets/css/custom.css` + `extra_css` | everything |
|
|
5081
|
+
| one partial or page type | copy it to `theme/views/<same path>` | every other file |
|
|
5082
|
+
| the whole page shell | override `layouts/layout.pug` | page types, partials, CSS |
|
|
5083
|
+
|
|
5084
|
+
Sections 4 to 6 go down this table.
|
|
5085
|
+
|
|
5086
|
+
## 4. Change a colour
|
|
5087
|
+
|
|
5088
|
+
Every token in the theme's `config/theme.yaml` becomes a CSS custom property:
|
|
5089
|
+
`tokens.color.accent` becomes `--theme-color-accent`. Change the accent (links,
|
|
5090
|
+
buttons, the top rule) to a dark teal and give the focus outline the old rust
|
|
5091
|
+
colour:
|
|
5092
|
+
|
|
5093
|
+
```yaml:config/theme.yaml
|
|
5094
|
+
tokens:
|
|
5095
|
+
color:
|
|
5096
|
+
accent: '#1c5f74'
|
|
5097
|
+
focus: '#a1400f'
|
|
5098
|
+
footer_links:
|
|
5099
|
+
- label: Imprint
|
|
5100
|
+
href: /imprint.html
|
|
5101
|
+
- label: Privacy
|
|
5102
|
+
href: /privacy.html
|
|
5103
|
+
```
|
|
5104
|
+
|
|
5105
|
+
After `npx nera build`, the `<style>` the theme writes into every page's
|
|
5106
|
+
`<head>` carries your values next to the defaults you did not touch:
|
|
5107
|
+
|
|
5108
|
+
```html
|
|
5109
|
+
<style>
|
|
5110
|
+
:root {
|
|
5111
|
+
--theme-color-bg: #fbf2e3;
|
|
5112
|
+
--theme-color-surface: #f1e0c3;
|
|
5113
|
+
--theme-color-text: #3b2314;
|
|
5114
|
+
--theme-color-muted: #6e4b2e;
|
|
5115
|
+
--theme-color-accent: #1c5f74;
|
|
5116
|
+
--theme-color-accent-text: #ffffff;
|
|
5117
|
+
--theme-color-border: #dcc6a3;
|
|
5118
|
+
--theme-color-focus: #a1400f;
|
|
5119
|
+
…
|
|
5120
|
+
}
|
|
5121
|
+
</style>
|
|
5122
|
+
```
|
|
5123
|
+
|
|
5124
|
+
Keep the contrast when you change colours: the accent is text on the page
|
|
5125
|
+
background and on cards, and the background of buttons. `#1c5f74` reaches
|
|
5126
|
+
6.4:1 on the background, 5.5:1 on the card colour and 7.1:1 under white
|
|
5127
|
+
button text, all above the 4.5:1 that WCAG asks for. The theme's README lists
|
|
5128
|
+
every token and every colour pair it checks.
|
|
5129
|
+
|
|
5130
|
+
## 5. Add your own CSS
|
|
5131
|
+
|
|
5132
|
+
For rules the tokens do not cover, add a stylesheet of your own and let the
|
|
5133
|
+
theme link it. Put it into `theme/assets/css/custom.css`; the rule styles a
|
|
5134
|
+
line you will add in the next section:
|
|
5135
|
+
|
|
5136
|
+
```css:theme/assets/css/custom.css
|
|
5137
|
+
.page-kicker {
|
|
5138
|
+
margin: 0 0 0.25rem;
|
|
5139
|
+
color: var(--theme-color-accent);
|
|
5140
|
+
font-size: 0.875rem;
|
|
5141
|
+
font-weight: 600;
|
|
5142
|
+
letter-spacing: 0.08em;
|
|
5143
|
+
text-transform: uppercase;
|
|
5144
|
+
}
|
|
5145
|
+
```
|
|
5146
|
+
|
|
5147
|
+
and list it under `extra_css` in `config/theme.yaml`:
|
|
5148
|
+
|
|
5149
|
+
```yaml:config/theme.yaml
|
|
5150
|
+
extra_css:
|
|
5151
|
+
- /css/custom.css
|
|
5152
|
+
```
|
|
5153
|
+
|
|
5154
|
+
The theme links it after its own stylesheet and the token `<style>`, so your
|
|
5155
|
+
rules win:
|
|
5156
|
+
|
|
5157
|
+
```html
|
|
5158
|
+
<link rel="stylesheet" href="/css/theme.css">
|
|
5159
|
+
<style>
|
|
5160
|
+
…
|
|
5161
|
+
</style>
|
|
5162
|
+
<link rel="stylesheet" href="/css/custom.css">
|
|
5163
|
+
```
|
|
5164
|
+
|
|
5165
|
+
`public/css/` now holds both `theme.css` (from the package) and `custom.css`
|
|
5166
|
+
(from your site). Use the tokens (`var(--theme-color-accent)`) rather than
|
|
5167
|
+
copied colour values, so a change in section 4 reaches your rules too. The
|
|
5168
|
+
theme lists its public class names in its README; those are the ones that
|
|
5169
|
+
stay stable across minor and patch releases.
|
|
5170
|
+
|
|
5171
|
+
Do not override `theme/assets/css/theme.css` itself: your copy would replace
|
|
5172
|
+
the theme's whole stylesheet, and its fixes would stop reaching you.
|
|
5173
|
+
|
|
5174
|
+
## 6. Override one partial
|
|
5175
|
+
|
|
5176
|
+
Now change markup. The page header of every page except the front page
|
|
5177
|
+
lives in the partial `partials/page-header.pug`. Copy it from the package to
|
|
5178
|
+
the same path in your site:
|
|
5179
|
+
|
|
5180
|
+
```bash
|
|
5181
|
+
mkdir -p theme/views/partials
|
|
5182
|
+
cp node_modules/@nera-static/theme-business/views/partials/page-header.pug theme/views/partials/
|
|
5183
|
+
```
|
|
5184
|
+
|
|
5185
|
+
and add a small line above the title, read from a new `kicker` frontmatter
|
|
5186
|
+
key:
|
|
5187
|
+
|
|
5188
|
+
```pug:theme/views/partials/page-header.pug
|
|
5189
|
+
//- Overrides the theme's partials/page-header.pug: adds a kicker line
|
|
5190
|
+
//- above the page title, from the page's `kicker` frontmatter.
|
|
5191
|
+
header.page__header
|
|
5192
|
+
if meta.kicker
|
|
5193
|
+
p.page-kicker= meta.kicker
|
|
5194
|
+
h1.page__title= meta.title || app.name
|
|
5195
|
+
if meta.lead
|
|
5196
|
+
p.page__lead= meta.lead
|
|
5197
|
+
```
|
|
5198
|
+
|
|
5199
|
+
The class is your own, `page-kicker`, not a name inside the theme's
|
|
5200
|
+
`page__…` block: a later theme release could add a `page__kicker` of its own.
|
|
5201
|
+
Use it on a page:
|
|
5202
|
+
|
|
5203
|
+
```markdown:pages/about.md
|
|
5204
|
+
---
|
|
5205
|
+
layout: pages/default.pug
|
|
5206
|
+
title: About us
|
|
5207
|
+
kicker: Since 1998
|
|
5208
|
+
lead: A small bakery in the middle of Berlin.
|
|
5209
|
+
description: Who we are and how we bake
|
|
5210
|
+
---
|
|
5211
|
+
## Our story
|
|
5212
|
+
|
|
5213
|
+
We bake every loaf by hand.
|
|
5214
|
+
```
|
|
5215
|
+
|
|
5216
|
+
`npx nera build` renders `public/about.html` with your header:
|
|
5217
|
+
|
|
5218
|
+
```html
|
|
5219
|
+
<header class="page__header">
|
|
5220
|
+
<p class="page-kicker">Since 1998</p>
|
|
5221
|
+
<h1 class="page__title">About us</h1>
|
|
5222
|
+
<p class="page__lead">A small bakery in the middle of Berlin.</p>
|
|
5223
|
+
</header>
|
|
5224
|
+
```
|
|
5225
|
+
|
|
5226
|
+
A page without `kicker` renders as before. Every other view, the layout, the
|
|
5227
|
+
footer, the page types, still comes from the package: you took over one file,
|
|
5228
|
+
not the theme.
|
|
5229
|
+
|
|
5230
|
+
A theme often prepares such places for you. theme-business ships empty
|
|
5231
|
+
partials, its *seams*, for plugin output: `partials/head-extra.pug` at the end
|
|
5232
|
+
of `<head>`, `partials/nav-main.pug` in the header navigation,
|
|
5233
|
+
`partials/footer-extra.pug` in the footer and a few more, listed in its
|
|
5234
|
+
README. Overriding a seam costs nothing, since there is no theme markup in it
|
|
5235
|
+
to miss out on. For a page type of your own, put a new file under
|
|
5236
|
+
`theme/views/pages/` that `extends ../layouts/layout.pug`; the README shows
|
|
5237
|
+
one.
|
|
5238
|
+
|
|
5239
|
+
## 7. Updates keep coming
|
|
5240
|
+
|
|
5241
|
+
Update the theme the same way as Nera itself:
|
|
5242
|
+
|
|
5243
|
+
```bash
|
|
5244
|
+
npx nera update
|
|
5245
|
+
```
|
|
5246
|
+
|
|
5247
|
+
```text
|
|
5248
|
+
🔄 Updating Nera packages: @nera-static/nera, @nera-static/theme-business
|
|
5249
|
+
```
|
|
5250
|
+
|
|
5251
|
+
`nera update` runs `npm update` for every `@nera-static/` package in
|
|
5252
|
+
`package.json`, the theme included. Like `npm update`, it stays within each
|
|
5253
|
+
package's range, so a new major version of the theme is never installed
|
|
5254
|
+
behind your back. `npm ls` shows the version you have:
|
|
5255
|
+
|
|
5256
|
+
```bash
|
|
5257
|
+
npm ls @nera-static/theme-business
|
|
5258
|
+
```
|
|
5259
|
+
|
|
5260
|
+
```text
|
|
5261
|
+
my-site@1.0.0 …/my-site
|
|
5262
|
+
└── @nera-static/theme-business@1.0.3
|
|
5263
|
+
```
|
|
5264
|
+
|
|
5265
|
+
An update replaces the files in `node_modules/`, never the ones in your
|
|
5266
|
+
`theme/`. That cuts both ways:
|
|
5267
|
+
|
|
5268
|
+
- Your tokens, `custom.css` and `page-header.pug` survive every update.
|
|
5269
|
+
- Your `page-header.pug` no longer receives the theme's changes to that
|
|
5270
|
+
file. Everything else does.
|
|
5271
|
+
|
|
5272
|
+
After an update, compare each file you override with the theme's new
|
|
5273
|
+
version and take over what you want:
|
|
5274
|
+
|
|
5275
|
+
```bash
|
|
5276
|
+
diff node_modules/@nera-static/theme-business/views/partials/page-header.pug theme/views/partials/page-header.pug
|
|
5277
|
+
```
|
|
5278
|
+
|
|
5279
|
+
```text
|
|
5280
|
+
1,2c1,2
|
|
5281
|
+
< //- The page header of every page type but home (§S3.1 "Header"): the page's
|
|
5282
|
+
< //- one <h1> and its lead.
|
|
5283
|
+
---
|
|
5284
|
+
> //- Overrides the theme's partials/page-header.pug: adds a kicker line
|
|
5285
|
+
> //- above the page title, from the page's `kicker` frontmatter.
|
|
5286
|
+
3a4,5
|
|
5287
|
+
> if meta.kicker
|
|
5288
|
+
> p.page-kicker= meta.kicker
|
|
5289
|
+
```
|
|
5290
|
+
|
|
5291
|
+
Here the only differences are yours. The theme follows semantic versioning
|
|
5292
|
+
over its view paths, tokens, settings and public classes: a minor or patch
|
|
5293
|
+
release keeps your overrides working, and a major one says in its CHANGELOG
|
|
5294
|
+
what to change. The fewer files you override, the less there is to compare.
|
|
5295
|
+
|
|
5296
|
+
## 8. Add a theme to an existing site
|
|
5297
|
+
|
|
5298
|
+
A site created without `--theme` has its own layout, scaffolded by
|
|
5299
|
+
`nera new`. Install the theme and name it in `config/app.yaml`:
|
|
5300
|
+
|
|
5301
|
+
```bash
|
|
5302
|
+
npm install @nera-static/theme-business
|
|
5303
|
+
```
|
|
5304
|
+
|
|
5305
|
+
```yaml:config/app.yaml
|
|
5306
|
+
theme: business
|
|
5307
|
+
```
|
|
5308
|
+
|
|
5309
|
+
`nera validate` then points at the two scaffolded views that are in the way:
|
|
5310
|
+
|
|
5311
|
+
```text
|
|
5312
|
+
theme/views/layouts/layout.pug
|
|
5313
|
+
:1 warning the `nera new` starter file hides the theme's own layouts/layout.pug — delete it to use the theme's, or remove the `nera:scaffold-default` line to keep it on purpose theme-shadowed
|
|
5314
|
+
theme/views/pages/default.pug
|
|
5315
|
+
:1 warning the `nera new` starter file hides the theme's own pages/default.pug — delete it to use the theme's, or remove the `nera:scaffold-default` line to keep it on purpose theme-shadowed
|
|
5316
|
+
|
|
5317
|
+
0 error(s), 2 warning(s)
|
|
5318
|
+
```
|
|
5319
|
+
|
|
5320
|
+
They have the same paths as two of the theme's views, so by the rule of
|
|
5321
|
+
section 3 they would win, and the theme would never show. Their first line,
|
|
5322
|
+
`//- nera:scaffold-default`, marks them as untouched starter files. Delete
|
|
5323
|
+
them:
|
|
5324
|
+
|
|
5325
|
+
```bash
|
|
5326
|
+
rm theme/views/layouts/layout.pug theme/views/pages/default.pug
|
|
5327
|
+
npx nera validate
|
|
5328
|
+
```
|
|
5329
|
+
|
|
5330
|
+
```text
|
|
5331
|
+
✓ No problems found.
|
|
5332
|
+
```
|
|
5333
|
+
|
|
5334
|
+
If you changed one of them and want to keep it, remove its
|
|
5335
|
+
`nera:scaffold-default` line instead: the file is then a deliberate override
|
|
5336
|
+
and the warning goes away. Then fix the headings and the footer links as in
|
|
5337
|
+
section 2.
|
|
5338
|
+
|
|
5339
|
+
A page renders with the theme's page type of the same name as its `layout`.
|
|
5340
|
+
theme-business has `pages/home.pug`, `default.pug`, `contact.pug`,
|
|
5341
|
+
`list.pug` and `gallery.pug`; a page whose `layout` names a view neither your
|
|
5342
|
+
site nor the theme has fails `nera validate` with `layout-unresolved`, which
|
|
5343
|
+
names both places it looked.
|
|
5344
|
+
|
|
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
|
|
5441
|
+
|
|
5442
|
+
A theme of your own is an npm package with the same layout: `views/`,
|
|
5443
|
+
`assets/` and `config/theme.yaml`. `@nera-static/theme-example` is the
|
|
5444
|
+
smallest one, kept small to copy: its README's section
|
|
5445
|
+
[Using it as a blueprint for your own theme](https://github.com/seebaermichi/nera-theme-example#using-it-as-a-blueprint-for-your-own-theme)
|
|
5446
|
+
walks through renaming the package, the fields Nera needs to find it, and the
|
|
5447
|
+
seams that let a site extend it without forking. theme-business shows the
|
|
5448
|
+
same ideas at full size: tokens, seams and a documented contract.
|
|
5449
|
+
|
|
5450
|
+
## Next
|
|
5451
|
+
|
|
5452
|
+
The [theme-business README](https://github.com/seebaermichi/nera-theme-business#readme)
|
|
5453
|
+
has every token, setting, seam and public class. The plugin tutorials, such
|
|
5454
|
+
as [Custom navigation](https://nera.js.org/tutorials/custom-navigation.html), show how to publish
|
|
5455
|
+
a plugin's templates; with theme-business you include them from a seam, as
|
|
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.
|