@nera-static/mcp 0.0.0-stage → 1.0.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/CHANGELOG.md +25 -0
- package/LICENSE +21 -0
- package/README.md +118 -2
- package/bin/nera-mcp.js +114 -0
- package/docs/llms-full.txt +3304 -0
- package/package.json +56 -5
- package/src/catalog.js +145 -0
- package/src/paths.js +115 -0
- package/src/processes.js +152 -0
- package/src/prompts.js +97 -0
- package/src/resources.js +119 -0
- package/src/results.js +66 -0
- package/src/runner.js +261 -0
- package/src/server.js +51 -0
- package/src/tools/cli.js +254 -0
- package/src/tools/files.js +294 -0
- package/src/tools/long-running.js +222 -0
- package/src/tools/sites.js +182 -0
|
@@ -0,0 +1,3304 @@
|
|
|
1
|
+
# Documentation
|
|
2
|
+
|
|
3
|
+
Source: https://nera.js.org/docs/index.html
|
|
4
|
+
|
|
5
|
+
Nera is a lightweight static site generator built on a simple idea: **Markdown in,
|
|
6
|
+
HTML out, with plugins for everything else.** This guide takes you from an empty
|
|
7
|
+
folder to a deployed site.
|
|
8
|
+
|
|
9
|
+
## The shape of a Nera project
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
my-site/
|
|
13
|
+
├── config/ # app.yaml + one <plugin>.yaml per plugin
|
|
14
|
+
├── pages/ # your Markdown content
|
|
15
|
+
├── theme/
|
|
16
|
+
│ ├── views/ # Pug layouts and page templates (vendor/ holds plugin templates)
|
|
17
|
+
│ └── assets/ # CSS, JS, images, fonts — copied verbatim to public/
|
|
18
|
+
├── src/plugins/ # optional local plugins, one folder each
|
|
19
|
+
├── public/ # generated output (never edit by hand)
|
|
20
|
+
├── AGENTS.md # instructions for AI assistants (CLAUDE.md points to it)
|
|
21
|
+
└── package.json # one Nera dependency: @nera-static/nera
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
`nera new` creates everything here except `src/plugins/` and `public/`. Local
|
|
25
|
+
plugins can live in another folder, set with `folders.plugins` in
|
|
26
|
+
`config/app.yaml`. Sites from before the theme system keep `views/` and
|
|
27
|
+
`assets/` at the project root; Nera still builds them, with a deprecation
|
|
28
|
+
warning, until you move both folders under `theme/`.
|
|
29
|
+
|
|
30
|
+
## How a page becomes HTML
|
|
31
|
+
|
|
32
|
+
1. **Load** `config/app.yaml` into the `app` object and list `pages/`.
|
|
33
|
+
2. **Render** each Markdown file, extracting frontmatter into `meta`.
|
|
34
|
+
3. **Apply plugins**, which enrich `app` and `meta`.
|
|
35
|
+
4. **Write** `public/`, running each page through its `layout`.
|
|
36
|
+
|
|
37
|
+
> A page is only rendered if its frontmatter sets a `layout`. Pages without one
|
|
38
|
+
> are silently skipped — this is the single most common "why is my page missing?"
|
|
39
|
+
> `npx nera validate` lists them (`layout-missing`).
|
|
40
|
+
|
|
41
|
+
Continue to **Getting started** to scaffold your first site. Working with an AI
|
|
42
|
+
assistant? Read [Using Nera with AI](https://nera.js.org/docs/using-ai.html).
|
|
43
|
+
|
|
44
|
+
# Getting started
|
|
45
|
+
|
|
46
|
+
Source: https://nera.js.org/docs/getting-started.html
|
|
47
|
+
|
|
48
|
+
## Requirements
|
|
49
|
+
|
|
50
|
+
- **Node.js 22.12 or newer**
|
|
51
|
+
- npm 10.9 or newer (bundled with Node.js 22.12)
|
|
52
|
+
|
|
53
|
+
## Scaffold a site
|
|
54
|
+
|
|
55
|
+
`nera new` scaffolds a new site whose one Nera dependency is
|
|
56
|
+
`@nera-static/nera`, which brings the `@nera-static/core` engine — no clone, no
|
|
57
|
+
vendored source:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npx @nera-static/nera new my-site
|
|
61
|
+
cd my-site
|
|
62
|
+
npm run dev
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`npm run dev` renders the site and starts a live-reloading preview on
|
|
66
|
+
`http://localhost:3000`. Already in the folder the site should live in? `npx
|
|
67
|
+
@nera-static/nera new .` scaffolds into the current, empty folder.
|
|
68
|
+
|
|
69
|
+
Rather start from a ready-to-edit site? `--starter <name>` scaffolds from a
|
|
70
|
+
starter kit such as `blog` or `business`; see
|
|
71
|
+
[Starter kits](https://nera.js.org/docs/cli.html#starter-kits).
|
|
72
|
+
|
|
73
|
+
## Build for production
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npm run build
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
This deletes and regenerates `public/`. Deploy that folder to any static host.
|
|
80
|
+
|
|
81
|
+
## Update later
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
npx nera update
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`nera update` bumps the site's Nera packages with `npm update` and refreshes
|
|
88
|
+
Nera's part of `AGENTS.md`, leaving your `pages/`, `config/` and `theme/`
|
|
89
|
+
untouched. From `@nera-static/nera` 1.15.0 on, it also raises their `^` ranges
|
|
90
|
+
in `package.json` (and `package-lock.json`) to the versions it installed, so
|
|
91
|
+
`^1.0.0` becomes, say, `^1.15.0`; it never crosses a major version. How an AI assistant uses `AGENTS.md` is explained in
|
|
92
|
+
[Using Nera with AI](https://nera.js.org/docs/using-ai.html).
|
|
93
|
+
|
|
94
|
+
# Core concepts
|
|
95
|
+
|
|
96
|
+
Source: https://nera.js.org/docs/core-concepts.html
|
|
97
|
+
|
|
98
|
+
## The four-stage pipeline
|
|
99
|
+
|
|
100
|
+
Every build runs the same fixed pipeline: **load app data → render pages →
|
|
101
|
+
apply plugins → write output.** Understanding these four stages explains almost
|
|
102
|
+
everything about how Nera behaves.
|
|
103
|
+
|
|
104
|
+
## `app` vs `meta`
|
|
105
|
+
|
|
106
|
+
Two data objects reach your templates:
|
|
107
|
+
|
|
108
|
+
- **`app`** — global values from `config/app.yaml`, available on every page.
|
|
109
|
+
- **`meta`** — per-page values: your frontmatter, plus derived keys like
|
|
110
|
+
`meta.href`, `meta.dirname`, `meta.filename` and `meta.createdAt`.
|
|
111
|
+
|
|
112
|
+
Plugins add to both — for example, `plugin-navigation` sets `app.nav`, and
|
|
113
|
+
`plugin-tags` sets `meta.tagLinks`.
|
|
114
|
+
|
|
115
|
+
## Layouts
|
|
116
|
+
|
|
117
|
+
Layouts are Pug files under `theme/views/`. A page's `layout` frontmatter picks one:
|
|
118
|
+
|
|
119
|
+
```markdown
|
|
120
|
+
---
|
|
121
|
+
layout: pages/docs.pug
|
|
122
|
+
title: My page
|
|
123
|
+
---
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
The path is relative to `theme/views/`, so `pages/docs.pug` is
|
|
127
|
+
`theme/views/pages/docs.pug`.
|
|
128
|
+
|
|
129
|
+
If `config/app.yaml` sets `theme:` (a package such as `@nera-static/theme-example`,
|
|
130
|
+
or a local folder), the layouts come from that theme, and a file in your own
|
|
131
|
+
`theme/views/` or `theme/assets/` replaces the theme's file at the same path —
|
|
132
|
+
override one template without copying the rest. `npx @nera-static/nera new
|
|
133
|
+
my-site --theme example` starts a site that way.
|
|
134
|
+
|
|
135
|
+
## Translations
|
|
136
|
+
|
|
137
|
+
`config/app.yaml` holds a `translations` map. In a layout, `t('key')` resolves
|
|
138
|
+
`app.translations[meta.lang || app.lang][key]`, falling back to the key itself —
|
|
139
|
+
so missing translations are visible, not silent.
|
|
140
|
+
|
|
141
|
+
# Writing content
|
|
142
|
+
|
|
143
|
+
Source: https://nera.js.org/docs/writing-content.html
|
|
144
|
+
|
|
145
|
+
## A content file
|
|
146
|
+
|
|
147
|
+
Each page is a Markdown file under `pages/` with a YAML frontmatter block:
|
|
148
|
+
|
|
149
|
+
```markdown
|
|
150
|
+
---
|
|
151
|
+
layout: pages/default.pug
|
|
152
|
+
title: About
|
|
153
|
+
description: What this page is about.
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
# About
|
|
157
|
+
|
|
158
|
+
Your content goes here.
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Who writes the title
|
|
162
|
+
|
|
163
|
+
`title` is data, not output. Whether it reaches the page is up to the layout, so
|
|
164
|
+
check before repeating it in the body:
|
|
165
|
+
|
|
166
|
+
- If the layout renders `meta.title` itself, **leave the heading out of the
|
|
167
|
+
Markdown** — writing `# About` as well puts the title on the page twice.
|
|
168
|
+
- If it doesn't, the body's own `#` heading is the page's only title, as in the
|
|
169
|
+
example above.
|
|
170
|
+
|
|
171
|
+
On this site `pages/default.pug` and `pages/docs.pug` render no title, so those
|
|
172
|
+
pages open with a heading. The tutorial, tutorials-index, plugins and tag-overview
|
|
173
|
+
layouts do render it, so their Markdown starts straight into the prose.
|
|
174
|
+
|
|
175
|
+
## Frontmatter is data
|
|
176
|
+
|
|
177
|
+
Everything in frontmatter lands on `meta`. Use it for titles, descriptions, tags,
|
|
178
|
+
ordering — anything a layout or plugin should read.
|
|
179
|
+
|
|
180
|
+
> YAML types are preserved: numbers stay numbers, booleans stay booleans. Guard on
|
|
181
|
+
> `meta.x != null`, not `if (meta.x)`, so a legitimate `0` or `false` survives.
|
|
182
|
+
|
|
183
|
+
## Derived meta values
|
|
184
|
+
|
|
185
|
+
Nera adds these automatically:
|
|
186
|
+
|
|
187
|
+
| Key | Meaning |
|
|
188
|
+
| --- | --- |
|
|
189
|
+
| `meta.href` | URL path of the generated HTML file |
|
|
190
|
+
| `meta.dirname` | Directory the page lives in |
|
|
191
|
+
| `meta.filename` | Source filename |
|
|
192
|
+
| `meta.createdAt` | `createdAt` or `date` from the frontmatter, else the file's creation time |
|
|
193
|
+
|
|
194
|
+
Set `createdAt` (or `date`) in the frontmatter of anything sorted by date, such
|
|
195
|
+
as posts. A fresh checkout in CI gives every file the same creation time, so
|
|
196
|
+
without it the order is lost on the build server.
|
|
197
|
+
|
|
198
|
+
## Folders become URLs
|
|
199
|
+
|
|
200
|
+
`pages/docs/getting-started.md` → `/docs/getting-started.html`. Nesting folders
|
|
201
|
+
nests URLs — no routing config required.
|
|
202
|
+
|
|
203
|
+
# Plugins
|
|
204
|
+
|
|
205
|
+
Source: https://nera.js.org/docs/plugins.html
|
|
206
|
+
|
|
207
|
+
## Installing
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
npm install @nera-static/plugin-navigation
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Any dependency whose name starts with `@nera-static/plugin-` is discovered and
|
|
214
|
+
applied automatically — no registration step. (`@nera-static/plugin-utils` is a
|
|
215
|
+
helper library, not a plugin, and is skipped.)
|
|
216
|
+
|
|
217
|
+
A plugin for one site only needs no package: put it in
|
|
218
|
+
`src/plugins/<name>/index.js`, or set another folder with `folders.plugins` in
|
|
219
|
+
`config/app.yaml`. See [Write your own local plugin](https://nera.js.org/tutorials/write-a-local-plugin.html).
|
|
220
|
+
|
|
221
|
+
## The hook contract
|
|
222
|
+
|
|
223
|
+
A plugin is an ESM module exporting up to three hooks, `getAppData`,
|
|
224
|
+
`getMetaData` and `getAssets` (below):
|
|
225
|
+
|
|
226
|
+
```js
|
|
227
|
+
export function getAppData({ app, pagesData }) {
|
|
228
|
+
return { ...app, myKey: 'value' } // must return a plain object
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function getMetaData({ app, pagesData }) {
|
|
232
|
+
return pagesData // must return an array
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
`getAppData` runs first; `getMetaData` sees the `app` it returned. Core awaits
|
|
237
|
+
every hook (since core 4.3.0; older versions silently replaced `app` with a
|
|
238
|
+
Promise), but **synchronous stays the safe default** — it is what the published
|
|
239
|
+
plugins do.
|
|
240
|
+
|
|
241
|
+
A plugin that produces files (generated images, for example) also exports
|
|
242
|
+
`getAssets` (core ≥ 4.13.0). It runs after every plugin's `getAppData` and
|
|
243
|
+
`getMetaData`, sees the final `app` and `pagesData`, and returns what to copy into
|
|
244
|
+
`public/`:
|
|
245
|
+
|
|
246
|
+
```js
|
|
247
|
+
export function getAssets({ app, pagesData }) {
|
|
248
|
+
return [{ from: '/abs/path/to/files', to: '_img' }]
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
`from` is an absolute file or folder, `to` a path inside `public/`. Core copies
|
|
253
|
+
these after the theme's assets and before your own, so your `theme/assets/` still wins
|
|
254
|
+
on a name clash. Invalid entries are skipped with a warning.
|
|
255
|
+
|
|
256
|
+
## Config lives in your project
|
|
257
|
+
|
|
258
|
+
Every plugin reads `config/<name>.yaml` from **your** site, not from the package.
|
|
259
|
+
The YAML shipped inside the package is documentation; copy it into your `config/`
|
|
260
|
+
and edit. Missing keys fall back to sensible defaults.
|
|
261
|
+
|
|
262
|
+
## Ordering
|
|
263
|
+
|
|
264
|
+
`config/plugin-order.yaml` controls execution order: names under `start:` run
|
|
265
|
+
first, then everything else alphabetically, then names under `end:`. Search runs
|
|
266
|
+
last so it indexes the final page data.
|
|
267
|
+
|
|
268
|
+
## Templates
|
|
269
|
+
|
|
270
|
+
Plugins that ship views expose a publish command:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
npx nera-navigation # copies templates into theme/views/vendor/plugin-navigation/
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Then `include` them from your layouts. Publishing **skips if the folder already
|
|
277
|
+
exists** — delete it (or pass `--force`) to pull in template updates.
|
|
278
|
+
|
|
279
|
+
# Deployment
|
|
280
|
+
|
|
281
|
+
Source: https://nera.js.org/docs/deployment.html
|
|
282
|
+
|
|
283
|
+
Nera outputs a plain `public/` folder — deploy it anywhere that serves static
|
|
284
|
+
files.
|
|
285
|
+
|
|
286
|
+
## Build
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
npm run build
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Host it
|
|
293
|
+
|
|
294
|
+
- **Netlify / Vercel** — build command `npm run build`, publish directory
|
|
295
|
+
`public`.
|
|
296
|
+
- **GitHub Pages** — build in GitHub Actions and deploy `public/` with
|
|
297
|
+
`actions/upload-pages-artifact` and `actions/deploy-pages`, as this site does.
|
|
298
|
+
- **Any static host / CDN** — upload the contents of `public/`.
|
|
299
|
+
|
|
300
|
+
## Cache busting
|
|
301
|
+
|
|
302
|
+
Browsers cache stylesheets, scripts and fonts, so after a deploy visitors may
|
|
303
|
+
keep seeing the old CSS or JS until they force a reload. Turn on content hashing
|
|
304
|
+
in `config/app.yaml` (requires `@nera-static/core` 4.11 or newer):
|
|
305
|
+
|
|
306
|
+
```yaml
|
|
307
|
+
asset_hashing: true
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
On every build Nera appends `?v=<hash>` to each local asset URL — stylesheets,
|
|
311
|
+
scripts, images, `srcset`, the search index and `url(…)` references inside CSS
|
|
312
|
+
such as fonts. The hash comes from the file's content, so a URL changes exactly
|
|
313
|
+
when its file does and stays cacheable otherwise. Your templates keep plain
|
|
314
|
+
paths like `/css/main.css`; never add `?v=` by hand.
|
|
315
|
+
|
|
316
|
+
Page links, external URLs and URLs that already have a query string are left
|
|
317
|
+
alone, and it works together with `base_path`. Without the key the build output
|
|
318
|
+
is unchanged.
|
|
319
|
+
|
|
320
|
+
## Before you launch
|
|
321
|
+
|
|
322
|
+
- Set `origin` in `config/app.yaml` to your real domain so canonical URLs are
|
|
323
|
+
correct (see [Canonical links for SEO](https://nera.js.org/tutorials/canonical-links-seo.html)).
|
|
324
|
+
- Add an `.neraignore` at the project root to keep source-only assets out of the
|
|
325
|
+
build.
|
|
326
|
+
|
|
327
|
+
> `public/` is deleted and rebuilt on every render — never edit it by hand, and
|
|
328
|
+
> never commit it as source.
|
|
329
|
+
|
|
330
|
+
# CLI reference
|
|
331
|
+
|
|
332
|
+
Source: https://nera.js.org/docs/cli.html
|
|
333
|
+
|
|
334
|
+
## The `nera` CLI (`@nera-static/nera`)
|
|
335
|
+
|
|
336
|
+
One command scaffolds, builds, previews, updates and validates a site. Scaffold
|
|
337
|
+
a new one with:
|
|
338
|
+
|
|
339
|
+
```bash
|
|
340
|
+
npx @nera-static/nera new <project-name>
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
`nera new .` scaffolds into the current, empty folder instead, and
|
|
344
|
+
`--theme <name>` starts the site from a theme. `--starter <name>` starts it
|
|
345
|
+
from a ready-to-edit starter kit instead (`blank`, `blog`, `business` or
|
|
346
|
+
`portfolio`; not together with `--theme`), and `--name "<site name>"` and
|
|
347
|
+
`--lang <code>` set `name` and `lang` in `config/app.yaml`:
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
npx @nera-static/nera new my-blog --starter blog --name "My Blog" --lang de
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
`--no-install` skips the `npm install` at the end; run it yourself later.
|
|
354
|
+
|
|
355
|
+
On a terminal, without `--starter` or `--yes`, `nera new` asks what you are
|
|
356
|
+
building, the site name and the language; with `--yes`, or without a terminal,
|
|
357
|
+
it never asks. [Starter kits](#starter-kits) below has the details.
|
|
358
|
+
|
|
359
|
+
A scaffolded site depends on `@nera-static/nera`, so run these from inside it
|
|
360
|
+
with `npx`, e.g. `npx nera validate`. The scaffold also wires `build`, `dev` and
|
|
361
|
+
`serve` to npm scripts, e.g. `npm run dev`:
|
|
362
|
+
|
|
363
|
+
| Command | What it does |
|
|
364
|
+
| --- | --- |
|
|
365
|
+
| `nera build` | Build `pages/` → `public/`; with `--check`, check the result too |
|
|
366
|
+
| `nera dev` | Build + live-reload preview on `:3000` |
|
|
367
|
+
| `nera serve` | Serve `public/` without rebuilding |
|
|
368
|
+
| `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
|
+
| `nera validate` | Check layouts, includes and YAML before publishing |
|
|
370
|
+
| `nera check` | Check the built `public/` for accessibility, privacy and legal-notice problems |
|
|
371
|
+
| `nera publish` | Publish the site on GitHub Pages or Netlify: sign in with GitHub, create the repository, push and print the live URL |
|
|
372
|
+
|
|
373
|
+
**Publishing with `nera publish`.** `nera publish` takes a site from its
|
|
374
|
+
folder to a live URL through GitHub: it signs you in with the "Nera Static"
|
|
375
|
+
GitHub App, creates the repository (or reuses the one in
|
|
376
|
+
`config/publish.yaml`), generates `.github/workflows/deploy.yml`, pushes and
|
|
377
|
+
follows the Actions run. The host is GitHub Pages (`--target github-pages`,
|
|
378
|
+
the default): it switches Pages on with the GitHub Actions build type, sets
|
|
379
|
+
`base_path` in `config/app.yaml` for a project page (`/<repo>`; none for a
|
|
380
|
+
`<user>.github.io` repository or a custom domain) and prints the live URL.
|
|
381
|
+
`--domain <host>` sets a custom domain in the Pages settings, checks its DNS
|
|
382
|
+
and prints the records to set when they are missing or wrong. The other flags
|
|
383
|
+
are `--repo <name>` (default: the folder name), `--private` (GitHub Pages
|
|
384
|
+
serves a private repository only on a paid GitHub plan), `--yes`, `--json`
|
|
385
|
+
and `--sign-out` (removes the stored GitHub and Netlify sign-ins).
|
|
386
|
+
|
|
387
|
+
**Netlify** (`--target netlify`) is the host for a business site, since
|
|
388
|
+
Netlify's terms allow commercial sites on the free plan. GitHub Actions still
|
|
389
|
+
builds the site, and Netlify's own build never runs. `nera publish` signs you
|
|
390
|
+
in to Netlify in the browser (the page offers sign-up when you have no
|
|
391
|
+
account), creates the Netlify site (or reuses the one in
|
|
392
|
+
`config/publish.yaml`), stores `NETLIFY_AUTH_TOKEN` and `NETLIFY_SITE_ID` as
|
|
393
|
+
encrypted repository secrets, removes `base_path` and prints the
|
|
394
|
+
`<name>.netlify.app` address. `--domain <host>` sets the custom domain on the
|
|
395
|
+
Netlify site and checks its DNS the same way: an `A` record `75.2.60.5` for
|
|
396
|
+
an apex domain, a `CNAME` to `<name>.netlify.app` for a subdomain. Netlify's
|
|
397
|
+
free plan has 300 credits a month and a production deploy costs 15, so about
|
|
398
|
+
20 deploys a month; `nera publish` warns from 80 % of that budget. Every push
|
|
399
|
+
to `main` deploys, so batch your changes. To host somewhere else,
|
|
400
|
+
build the site and upload the contents of `public/` to any static host, as
|
|
401
|
+
[Deployment](https://nera.js.org/docs/deployment.html) describes.
|
|
402
|
+
|
|
403
|
+
**Choosing and changing the host.** On a terminal, without `--target` and
|
|
404
|
+
without a target in `config/publish.yaml`, `nera publish` asks "Is this a site
|
|
405
|
+
for a business?": yes recommends Netlify, no (or Enter) recommends GitHub
|
|
406
|
+
Pages, and you can pick either. With `--yes`, `--json` or without a terminal
|
|
407
|
+
nothing is asked and GitHub Pages is the default. The choice is kept in
|
|
408
|
+
`config/publish.yaml`. `nera publish --target <other>` later moves the site:
|
|
409
|
+
it sets up the new host and swaps the workflow's deploy job, but leaves the
|
|
410
|
+
old host untouched and prints how to remove the site there (and the unused
|
|
411
|
+
Netlify secrets). A custom domain still points at the old host until you run
|
|
412
|
+
with `--domain <host>` and change its DNS records. `--json` reports the old
|
|
413
|
+
host as `movedFrom`.
|
|
414
|
+
|
|
415
|
+
### Starter kits
|
|
416
|
+
|
|
417
|
+
A starter kit is a whole ready-to-edit site: sample pages, config, optional
|
|
418
|
+
site-level `theme/` overrides, assets and the theme and plugins it depends on.
|
|
419
|
+
`nera new --starter` copies its `pages/`, `config/`, `theme/`, `assets/`,
|
|
420
|
+
`plugins/` and `.neraignore` over the base template, adds its `dependencies`
|
|
421
|
+
to the site's `package.json`, applies `--name` and `--lang`, installs, and
|
|
422
|
+
prints the `## First steps` section of the starter's README (nothing, when it
|
|
423
|
+
has none). After that the site owns the files: a starter has no update path,
|
|
424
|
+
though the theme it depends on still updates through npm.
|
|
425
|
+
|
|
426
|
+
`--name "<site name>"` and `--lang <code>` set `name:` and `lang:` in
|
|
427
|
+
`config/app.yaml`, with or without a starter. A new language gets a copy of
|
|
428
|
+
the current language's `translations:` entry, ready to translate, so no page
|
|
429
|
+
shows a raw translation key.
|
|
430
|
+
|
|
431
|
+
`--starter` takes:
|
|
432
|
+
|
|
433
|
+
- a starter name: `blank`, `blog`, `business` or `portfolio`, short for
|
|
434
|
+
`@nera-static/starter-blank` and so on;
|
|
435
|
+
- a package name: `@acme/starter-shop`, or unscoped `nera-starter-shop`;
|
|
436
|
+
- a GitHub URL: `https://github.com/owner/repo` (optionally `.git`, `#ref`),
|
|
437
|
+
or `github:owner/repo#ref`;
|
|
438
|
+
- a local path: `./my-starter`, `../my-starter` or an absolute path.
|
|
439
|
+
|
|
440
|
+
Packages and GitHub repositories are downloaded with
|
|
441
|
+
`npm pack --ignore-scripts`, so no script of the starter runs. A starter is a
|
|
442
|
+
package whose `package.json` has a `nera.starter` field
|
|
443
|
+
(`{ "label": "…", "description": "…" }`); anything else is refused before
|
|
444
|
+
anything is written. A starter that sets `theme:` in its `config/app.yaml`
|
|
445
|
+
leaves out the scaffold's starter templates, as `--theme` does.
|
|
446
|
+
|
|
447
|
+
Run `nera new my-site` on a terminal and it asks instead:
|
|
448
|
+
|
|
449
|
+
```text
|
|
450
|
+
What are you building?
|
|
451
|
+
1) Empty — the base template, no starter
|
|
452
|
+
2) …
|
|
453
|
+
Choose 1–2 [1]:
|
|
454
|
+
Site name [My Nera Site]:
|
|
455
|
+
Language [en]:
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
The list comes from the npm registry (packages with the keyword
|
|
459
|
+
`nera-starter`, official `@nera-static/` ones first), or from a short list
|
|
460
|
+
bundled with the CLI when the registry cannot be reached. Enter accepts the
|
|
461
|
+
default. Every question has a flag (`--starter`, `--name`, `--lang`); with
|
|
462
|
+
`--yes`, or without a terminal (scripts, CI, AI agents), nothing is asked and
|
|
463
|
+
`nera new` scaffolds the base template.
|
|
464
|
+
|
|
465
|
+
The official starters:
|
|
466
|
+
|
|
467
|
+
| Starter | What you get |
|
|
468
|
+
| --- | --- |
|
|
469
|
+
| `blank` | One accessible layout, no theme |
|
|
470
|
+
| `blog` | A blog on `@nera-static/theme-blog` with tags, an archive, an Atom feed and a sitemap |
|
|
471
|
+
| `business` | A small-business site on `@nera-static/theme-business` with services, opening hours and a contact form |
|
|
472
|
+
| `portfolio` | A designer's portfolio on `@nera-static/theme-business` with projects in image galleries, an about page and a contact form |
|
|
473
|
+
|
|
474
|
+
### Checking the built site
|
|
475
|
+
|
|
476
|
+
`nera validate` reads your sources. `nera check` reads what the build produced —
|
|
477
|
+
the page a visitor gets, with its layout, navigation, footer, scripts,
|
|
478
|
+
stylesheets and fonts — and looks for problems a parser can find there:
|
|
479
|
+
|
|
480
|
+
```bash
|
|
481
|
+
nera build --check # build, then check — the one command for CI
|
|
482
|
+
nera check # check an existing public/ without rebuilding
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
Run `nera build` first; without `public/`, `nera check` stops with "run
|
|
486
|
+
`nera build` first". A problem in a template is reported once, with the number
|
|
487
|
+
of pages it appears on.
|
|
488
|
+
|
|
489
|
+
Every finding is a **warning** by default, so the command exits `0`. It exits
|
|
490
|
+
`1` only when a rule you promoted to `error` fires — that is how you make it a
|
|
491
|
+
CI gate.
|
|
492
|
+
|
|
493
|
+
**These are hints, not legal advice.** A clean run is not proof of compliance:
|
|
494
|
+
automated checks find only part of the accessibility problems (about a third
|
|
495
|
+
of WCAG failures). Colour contrast, visible focus and whether a law applies to
|
|
496
|
+
your site are not checked. Every report ends with that reminder.
|
|
497
|
+
|
|
498
|
+
| rule | default | basis |
|
|
499
|
+
| --- | --- | --- |
|
|
500
|
+
| `a11y-html-lang` | warning | WCAG 3.1.1 |
|
|
501
|
+
| `a11y-title` | warning | WCAG 2.4.2 |
|
|
502
|
+
| `a11y-h1` | warning | WCAG 1.3.1 |
|
|
503
|
+
| `a11y-heading-skip` | warning | WCAG 1.3.1 |
|
|
504
|
+
| `a11y-img-alt` | warning | WCAG 1.1.1 |
|
|
505
|
+
| `a11y-form-label` | warning | WCAG 1.3.1, 4.1.2 |
|
|
506
|
+
| `a11y-link-name` | warning | WCAG 2.4.4, 4.1.2 |
|
|
507
|
+
| `a11y-main` | warning | WCAG 1.3.1 |
|
|
508
|
+
| `a11y-skip-link` | warning | WCAG 2.4.1 |
|
|
509
|
+
| `a11y-nav-name` | warning | WCAG 1.3.1 |
|
|
510
|
+
| `a11y-duplicate-id` | warning | WCAG 4.1.2 |
|
|
511
|
+
| `a11y-viewport-zoom` | warning | WCAG 1.4.4 |
|
|
512
|
+
| `a11y-link-lang` | off (opt-in) | WCAG 3.1.2 |
|
|
513
|
+
| `a11y-target-blank` | off (opt-in) | WCAG 3.2.5 (AAA) |
|
|
514
|
+
| `a11y-reduced-motion` | off (opt-in) | WCAG 2.3.3 (AAA) |
|
|
515
|
+
| `privacy-third-party` | warning | Art. 6 DSGVO |
|
|
516
|
+
| `privacy-consent-leak` | warning | § 25 TDDDG |
|
|
517
|
+
| `privacy-insecure` | warning | Art. 32 DSGVO |
|
|
518
|
+
| `privacy-storage` | off (opt-in) | § 25 TDDDG |
|
|
519
|
+
| `legal-imprint-link` | warning | § 5 DDG |
|
|
520
|
+
| `legal-privacy-link` | warning | Art. 13 DSGVO |
|
|
521
|
+
| `legal-outdated-law` | warning | DDG, TDDDG, MStV |
|
|
522
|
+
|
|
523
|
+
Configure the checks in `config/validate.yaml` (optional — without it the
|
|
524
|
+
defaults above apply):
|
|
525
|
+
|
|
526
|
+
```yaml
|
|
527
|
+
rules:
|
|
528
|
+
a11y-img-alt: error # promote: the check fails
|
|
529
|
+
a11y-target-blank: warning # enable an opt-in rule
|
|
530
|
+
a11y-skip-link: off # disable
|
|
531
|
+
legal:
|
|
532
|
+
imprint: # per language, the page every page links to
|
|
533
|
+
de: /de/impressum.html
|
|
534
|
+
en: /en/imprint.html
|
|
535
|
+
privacy:
|
|
536
|
+
de: /de/datenschutz.html
|
|
537
|
+
en: /en/privacy.html
|
|
538
|
+
privacy:
|
|
539
|
+
allowed_hosts: # third-party hosts you have accounted for
|
|
540
|
+
- cdn.example.org
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
To silence a rule on one page, list it in the page's frontmatter as
|
|
544
|
+
`validate_ignore: [a11y-h1]`.
|
|
545
|
+
|
|
546
|
+
To silence a rule on whole files or folders, list them under `ignore`. This
|
|
547
|
+
works for `nera validate` too — for example for `layout-missing` on content
|
|
548
|
+
fragments that another page pulls in, or on drafts, which have no `layout` on
|
|
549
|
+
purpose:
|
|
550
|
+
|
|
551
|
+
```yaml
|
|
552
|
+
ignore:
|
|
553
|
+
layout-missing:
|
|
554
|
+
- pages/*/references # a folder covers everything below it
|
|
555
|
+
- pages/de/blog/drafts # * stands for one folder name
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
Paths are relative to the site root. Requires `@nera-static/validate` 1.3.0,
|
|
559
|
+
which `npm update` brings into an existing site.
|
|
560
|
+
|
|
561
|
+
**Your own host.** To tell your resources from third-party ones,
|
|
562
|
+
`privacy-third-party` reads `origin` from `config/app.yaml`, else `app_origin`
|
|
563
|
+
from `config/canonical-links.yaml` (with and without `www.`). With neither set,
|
|
564
|
+
only relative URLs count as your own.
|
|
565
|
+
|
|
566
|
+
**Consent-gated resources.** A script or embed in the markup of
|
|
567
|
+
`@nera-static/plugin-consent` (`type="text/plain"` with `data-src`, or
|
|
568
|
+
`data-consent-src` instead of `src`) loads nothing on page view, so
|
|
569
|
+
`privacy-third-party` does not report it. An element marked `data-consent`
|
|
570
|
+
that still loads is what `privacy-consent-leak` reports. The tutorial
|
|
571
|
+
[Add a consent banner — or none](https://nera.js.org/tutorials/consent-banner.html) shows both.
|
|
572
|
+
|
|
573
|
+
**Imprint and privacy links in German and English only.** Without `legal`
|
|
574
|
+
config, the links are found by their text — *Impressum*, *Imprint*, *Legal
|
|
575
|
+
notice*, *Datenschutz*, *Privacy*, *Data protection* — and only on German and
|
|
576
|
+
English pages. For any other language, name the pages under
|
|
577
|
+
`legal.imprint.<lang>` and `legal.privacy.<lang>`.
|
|
578
|
+
|
|
579
|
+
The full rule descriptions are in the
|
|
580
|
+
[`@nera-static/validate` README](https://github.com/seebaermichi/nera-validate#checking-the-built-output).
|
|
581
|
+
|
|
582
|
+
### Instructions for AI assistants
|
|
583
|
+
|
|
584
|
+
Every scaffolded site carries an `AGENTS.md` — the file Codex, Cursor, Copilot
|
|
585
|
+
and other assistants read first — and a `CLAUDE.md` holding the single line
|
|
586
|
+
`@AGENTS.md`, so Claude Code loads the same text. `AGENTS.md` ends with a
|
|
587
|
+
**Notes for this site** section for your own instructions, below the marker
|
|
588
|
+
line `<!-- nera:site-notes … -->`. Keep that line in place: the part above it
|
|
589
|
+
is Nera's, the part below it is yours.
|
|
590
|
+
|
|
591
|
+
From `@nera-static/nera` 1.7.0 on, `nera update` keeps both files current, with
|
|
592
|
+
no extra flag. After updating the packages (and after `nera update --migrate`)
|
|
593
|
+
it:
|
|
594
|
+
|
|
595
|
+
- creates `AGENTS.md` and `CLAUDE.md` when they are missing, so an older site
|
|
596
|
+
gets them too;
|
|
597
|
+
- replaces only the part of `AGENTS.md` above the marker line with the text from
|
|
598
|
+
the installed `@nera-static/nera`; the marker line and your notes below it
|
|
599
|
+
stay exactly as they are;
|
|
600
|
+
- leaves an `AGENTS.md` without the marker line alone and prints a hint — copy
|
|
601
|
+
the marker line from the template directly above your own notes to opt in;
|
|
602
|
+
- never touches an existing `CLAUDE.md`.
|
|
603
|
+
|
|
604
|
+
A file is written only when its content changes, so running `nera update` again
|
|
605
|
+
changes nothing.
|
|
606
|
+
|
|
607
|
+
### Migrating an older (cloned) site
|
|
608
|
+
|
|
609
|
+
Sites created before the CLI were git clones that vendored the engine under
|
|
610
|
+
`src/`. Inside such a site, run `nera update --migrate` — it adds the
|
|
611
|
+
`@nera-static/nera` dependency, rewrites the scripts, removes the vendored
|
|
612
|
+
`src/` engine, and installs, leaving your `pages/`, `config/` and `theme/`
|
|
613
|
+
untouched.
|
|
614
|
+
|
|
615
|
+
## Plugin publish commands
|
|
616
|
+
|
|
617
|
+
Each template-shipping plugin exposes a bin to copy its Pug into
|
|
618
|
+
`theme/views/vendor/`, e.g.:
|
|
619
|
+
|
|
620
|
+
```bash
|
|
621
|
+
npx nera-navigation
|
|
622
|
+
npx nera-tags
|
|
623
|
+
npx nera-search --force # overwrite existing published templates
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
# Using Nera with AI
|
|
627
|
+
|
|
628
|
+
Source: https://nera.js.org/docs/using-ai.html
|
|
629
|
+
|
|
630
|
+
AI assistants know Eleventy, Hugo and Astro well, and Nera hardly at all. Left
|
|
631
|
+
alone, they guess — and guess wrong: pretty URLs, a missing `layout`, edits in
|
|
632
|
+
`public/`. Nera gives them the facts in two ways: an instruction file in every
|
|
633
|
+
site, and its docs as plain Markdown.
|
|
634
|
+
|
|
635
|
+
## What every site ships
|
|
636
|
+
|
|
637
|
+
A site created with `npx @nera-static/nera new` (from `@nera-static/nera`
|
|
638
|
+
1.6.0 on) contains two files for AI assistants:
|
|
639
|
+
|
|
640
|
+
- **`AGENTS.md`** — the instruction file read by Codex, Cursor, GitHub Copilot,
|
|
641
|
+
Gemini CLI and other assistants. It says what Nera is (and that it is not
|
|
642
|
+
Eleventy, Hugo, Astro or Jekyll), maps the folders, lists the commands, names
|
|
643
|
+
the usual traps — a page needs `layout`, URLs end in `.html`, `public/` is
|
|
644
|
+
wiped on every build — and says to look in the plugin catalog before writing
|
|
645
|
+
a feature. From 1.8.0 on it also links Nera's docs for AI (see below).
|
|
646
|
+
- **`CLAUDE.md`** — one line, `@AGENTS.md`, so Claude Code loads the same text.
|
|
647
|
+
|
|
648
|
+
`AGENTS.md` ends with a **Notes for this site** section below the marker line
|
|
649
|
+
`<!-- nera:site-notes … -->`. That part is yours: write down the audience, the
|
|
650
|
+
tone, the languages, pages that must not change and where the site is hosted.
|
|
651
|
+
The part above the marker is Nera's.
|
|
652
|
+
|
|
653
|
+
**An existing site?** From `@nera-static/nera` 1.7.0 on, `npx nera update`
|
|
654
|
+
creates `AGENTS.md` and `CLAUDE.md` when they are missing and refreshes only
|
|
655
|
+
Nera's part of `AGENTS.md`, so your notes stay. The details are in the
|
|
656
|
+
[CLI reference](https://nera.js.org/docs/cli.html), under "Instructions for AI assistants".
|
|
657
|
+
|
|
658
|
+
## The Nera skill
|
|
659
|
+
|
|
660
|
+
From `@nera-static/nera` 1.10.0 on, every new site also contains the **Nera
|
|
661
|
+
skill**, an Agent Skill: a `SKILL.md` with the workflow and the checks to run,
|
|
662
|
+
plus short recipes for a business site, a blog, a portfolio, a contact form,
|
|
663
|
+
search, images, a second language and a custom domain. Assistants that support
|
|
664
|
+
skills load it when a task is about Nera. It sits in two folders:
|
|
665
|
+
|
|
666
|
+
- `.agents/skills/nera/` — read by Codex, Cursor, GitHub Copilot and Gemini CLI;
|
|
667
|
+
- `.claude/skills/nera/` — read by Claude Code.
|
|
668
|
+
|
|
669
|
+
Both folders are Nera's: `npx nera update` adds them to an existing site and
|
|
670
|
+
keeps them in step with the installed version, so commit them but do not edit
|
|
671
|
+
them. Write your own notes in `AGENTS.md` instead.
|
|
672
|
+
|
|
673
|
+
**claude.ai and Claude Desktop** install skills by upload. Download
|
|
674
|
+
[`nera-skill.zip`](https://nera.js.org/downloads/nera-skill.zip) — the same skill a new site
|
|
675
|
+
gets — and upload it in the skills section of the settings.
|
|
676
|
+
|
|
677
|
+
## Per assistant
|
|
678
|
+
|
|
679
|
+
Open the site's folder in the assistant — the folder with `package.json` and
|
|
680
|
+
`AGENTS.md` — so it finds the instructions.
|
|
681
|
+
|
|
682
|
+
- **Claude Code** reads `CLAUDE.md`, which pulls in `AGENTS.md`.
|
|
683
|
+
- **OpenAI Codex** reads `AGENTS.md`.
|
|
684
|
+
- **Cursor**, **GitHub Copilot** and other coding assistants that support the
|
|
685
|
+
`AGENTS.md` convention read it too.
|
|
686
|
+
- **Chat assistants without access to your files** (claude.ai, ChatGPT and the
|
|
687
|
+
like) never see `AGENTS.md`. Give them Nera's docs in the prompt instead —
|
|
688
|
+
see the next section.
|
|
689
|
+
|
|
690
|
+
## Docs for AI
|
|
691
|
+
|
|
692
|
+
nera.js.org publishes its docs for assistants, in English:
|
|
693
|
+
|
|
694
|
+
- [`https://nera.js.org/llms.txt`](https://nera.js.org/llms.txt) — an index of
|
|
695
|
+
the docs, following the llms.txt convention;
|
|
696
|
+
- [`https://nera.js.org/llms-full.txt`](https://nera.js.org/llms-full.txt) —
|
|
697
|
+
all English docs and tutorials in one Markdown file;
|
|
698
|
+
- a raw Markdown file beside every English docs and tutorials page, e.g.
|
|
699
|
+
[`/docs/cli.md`](https://nera.js.org/docs/cli.md) next to `/docs/cli.html`.
|
|
700
|
+
|
|
701
|
+
Paste one of these URLs into a chat assistant's prompt, or attach the file. The
|
|
702
|
+
docs are English only on purpose: models read them well and answer in your
|
|
703
|
+
language.
|
|
704
|
+
|
|
705
|
+
## The workflow
|
|
706
|
+
|
|
707
|
+
1. Ask for one change at a time.
|
|
708
|
+
2. Let the assistant edit the files.
|
|
709
|
+
3. It runs `npx nera validate`, then `npx nera build --check`, and fixes what
|
|
710
|
+
they report. `AGENTS.md` tells it to; say so in the prompt if it does not.
|
|
711
|
+
With `--json` (from 1.9.0 on) both print their findings for machines.
|
|
712
|
+
4. Preview with `npm run dev` on `http://localhost:3000`.
|
|
713
|
+
5. Review the diff (`git diff`) before you publish.
|
|
714
|
+
|
|
715
|
+
## Example prompts
|
|
716
|
+
|
|
717
|
+
Create a new site — there is no `AGENTS.md` yet, so name the command and the
|
|
718
|
+
docs:
|
|
719
|
+
|
|
720
|
+
```text
|
|
721
|
+
Create a new Nera site in the folder "bakery" with
|
|
722
|
+
npx @nera-static/nera new bakery, then read its AGENTS.md before changing
|
|
723
|
+
anything. Nera's docs are at https://nera.js.org/llms.txt.
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
Add a page:
|
|
727
|
+
|
|
728
|
+
```text
|
|
729
|
+
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 if the site has no menu yet). Then run
|
|
732
|
+
npx nera validate and npx nera build --check and fix what they report.
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
Add a contact form with the plugin:
|
|
736
|
+
|
|
737
|
+
```text
|
|
738
|
+
Add a contact form to the contact page with @nera-static/plugin-contact-form.
|
|
739
|
+
Install it, copy its template with its command, include it in the page
|
|
740
|
+
template and set my address in config/contact-form.yaml. Do not write a form
|
|
741
|
+
by hand.
|
|
742
|
+
```
|
|
743
|
+
|
|
744
|
+
Add a second language:
|
|
745
|
+
|
|
746
|
+
```text
|
|
747
|
+
Add German as a second language. Put the German pages under pages/de/, set
|
|
748
|
+
lang: de in their frontmatter, move the interface text into translations in
|
|
749
|
+
config/app.yaml and use t('key') in the templates.
|
|
750
|
+
```
|
|
751
|
+
|
|
752
|
+
Fix what `nera validate` reports:
|
|
753
|
+
|
|
754
|
+
```text
|
|
755
|
+
Run npx nera validate and fix every error and warning it reports. Explain each
|
|
756
|
+
fix in one line. Then run npx nera build --check.
|
|
757
|
+
```
|
|
758
|
+
|
|
759
|
+
In a chat assistant without file access:
|
|
760
|
+
|
|
761
|
+
```text
|
|
762
|
+
Read https://nera.js.org/llms-full.txt — the docs of the Nera static site
|
|
763
|
+
generator. Then explain how I add a blog section with tags to my Nera site,
|
|
764
|
+
with the files I need to create and their content.
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
## What's planned
|
|
768
|
+
|
|
769
|
+
Planned, not available yet: an **MCP server** for Nera — a local one for
|
|
770
|
+
Claude Desktop, Claude Code and Cursor, and a hosted connector for claude.ai
|
|
771
|
+
and ChatGPT that works on your GitHub repository.
|
|
772
|
+
|
|
773
|
+
# Build a blog with Nera
|
|
774
|
+
|
|
775
|
+
Source: https://nera.js.org/tutorials/build-a-blog.html
|
|
776
|
+
|
|
777
|
+
In this tutorial you'll scaffold a Nera site, write two posts, and turn the home
|
|
778
|
+
page into a blog index that lists them newest-first. Every file is shown in
|
|
779
|
+
full, so you can follow along step by step.
|
|
780
|
+
|
|
781
|
+
## 1. Scaffold the site
|
|
782
|
+
|
|
783
|
+
```bash
|
|
784
|
+
npx @nera-static/nera new my-blog
|
|
785
|
+
cd my-blog
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
`nera new` creates the site and installs its dependencies. You'll touch three
|
|
789
|
+
places: `pages/` for your content (it starts with `pages/index.md`, plus
|
|
790
|
+
`pages/imprint.md` and `pages/privacy.md` — placeholders to replace before you
|
|
791
|
+
publish), `theme/views/` for the Pug templates (`layouts/layout.pug` is the HTML
|
|
792
|
+
shell, `pages/default.pug` renders a page into it), and `config/` for settings.
|
|
793
|
+
|
|
794
|
+
Want a finished blog to edit instead? The blog starter sets one up with a
|
|
795
|
+
theme, sample posts, tags, an archive, a feed and a sitemap:
|
|
796
|
+
|
|
797
|
+
```bash
|
|
798
|
+
npx @nera-static/nera new my-blog --starter blog
|
|
799
|
+
```
|
|
800
|
+
|
|
801
|
+
Its files won't match the steps below: this tutorial builds a simpler blog by
|
|
802
|
+
hand, to show how the pieces fit together.
|
|
803
|
+
|
|
804
|
+
## 2. Write posts
|
|
805
|
+
|
|
806
|
+
Posts are Markdown files in `pages/posts/`. Create `pages/posts/hello-world.md`:
|
|
807
|
+
|
|
808
|
+
```markdown
|
|
809
|
+
---
|
|
810
|
+
layout: pages/default.pug
|
|
811
|
+
title: Hello world
|
|
812
|
+
description: My first post.
|
|
813
|
+
createdAt: 2026-10-01
|
|
814
|
+
---
|
|
815
|
+
|
|
816
|
+
# Hello world
|
|
817
|
+
|
|
818
|
+
Welcome to my new Nera blog.
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
And a second one, `pages/posts/second-post.md`:
|
|
822
|
+
|
|
823
|
+
```markdown
|
|
824
|
+
---
|
|
825
|
+
layout: pages/default.pug
|
|
826
|
+
title: My second post
|
|
827
|
+
description: What I learned this week.
|
|
828
|
+
createdAt: 2026-10-08
|
|
829
|
+
---
|
|
830
|
+
|
|
831
|
+
# My second post
|
|
832
|
+
|
|
833
|
+
A week in, and the blog lists this post first.
|
|
834
|
+
```
|
|
835
|
+
|
|
836
|
+
A page renders only if it names a `layout`. The `title` and `description` show
|
|
837
|
+
up in the list, and `createdAt` is the post's date. Always set it: without it,
|
|
838
|
+
Nera falls back to the file's creation time, which on a fresh checkout — on a CI
|
|
839
|
+
build server, say — is the same for every file, so the order would be arbitrary.
|
|
840
|
+
|
|
841
|
+
## 3. List the posts on the home page
|
|
842
|
+
|
|
843
|
+
`@nera-static/plugin-simple-page-list` collects the pages of a folder into a
|
|
844
|
+
sorted list. Install it and publish its template:
|
|
845
|
+
|
|
846
|
+
```bash
|
|
847
|
+
npm install @nera-static/plugin-simple-page-list
|
|
848
|
+
npx nera-simple-page-list
|
|
849
|
+
```
|
|
850
|
+
|
|
851
|
+
Nera picks up the plugin from your `package.json` on its own. The second command
|
|
852
|
+
copies the template to
|
|
853
|
+
`theme/views/vendor/plugin-simple-page-list/simple-page-list.pug`.
|
|
854
|
+
|
|
855
|
+
Tell the plugin which folder to list and how to sort it. Create
|
|
856
|
+
`config/simple-page-list.yaml`:
|
|
857
|
+
|
|
858
|
+
```yaml
|
|
859
|
+
page_path: /posts
|
|
860
|
+
more_link_text: Read more
|
|
861
|
+
sortBy: date
|
|
862
|
+
sortOrder: descending
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
`page_path` gives you one flat list in `app.pageList`, which is all a blog with
|
|
866
|
+
one section needs. `sortBy: date` reads a post's `date` from the frontmatter and
|
|
867
|
+
falls back to `createdAt`, so your posts sort by the dates you just set.
|
|
868
|
+
|
|
869
|
+
Now a page template that renders the page's own content and the list below it.
|
|
870
|
+
Create `theme/views/pages/blog.pug`:
|
|
871
|
+
|
|
872
|
+
```pug
|
|
873
|
+
extends ../layouts/layout
|
|
874
|
+
|
|
875
|
+
block content
|
|
876
|
+
main#main
|
|
877
|
+
!= content
|
|
878
|
+
include /vendor/plugin-simple-page-list/simple-page-list
|
|
879
|
+
```
|
|
880
|
+
|
|
881
|
+
The two `content`s are unrelated. `block content` fills the slot of that name
|
|
882
|
+
in `layouts/layout.pug`. `!= content` outputs the page's Markdown, which Nera
|
|
883
|
+
has already rendered to HTML; `!=` leaves it unescaped, so it arrives as markup.
|
|
884
|
+
The leading slash makes the include path start at `theme/views/`, wherever the
|
|
885
|
+
template sits.
|
|
886
|
+
|
|
887
|
+
Finally, make the home page use it. Replace `pages/index.md` with:
|
|
888
|
+
|
|
889
|
+
```markdown
|
|
890
|
+
---
|
|
891
|
+
layout: pages/blog.pug
|
|
892
|
+
title: My blog
|
|
893
|
+
description: Notes and posts, newest first.
|
|
894
|
+
---
|
|
895
|
+
|
|
896
|
+
# My blog
|
|
897
|
+
|
|
898
|
+
Welcome! Here is everything I have written so far.
|
|
899
|
+
```
|
|
900
|
+
|
|
901
|
+
This is the template you published — yours to edit:
|
|
902
|
+
|
|
903
|
+
```pug
|
|
904
|
+
//- Handles both shapes `getAppData` can produce:
|
|
905
|
+
//- flat — `app.pageList` is an array (config uses `page_path`)
|
|
906
|
+
//- grouped — `app.pageList` is keyed by path (config uses `page_paths`)
|
|
907
|
+
//- The flat branch emits exactly the markup this template has always emitted,
|
|
908
|
+
//- so published copies keep rendering identically.
|
|
909
|
+
mixin pageListItems(pages)
|
|
910
|
+
each page in pages
|
|
911
|
+
article.page-list__item
|
|
912
|
+
header.page-list__header
|
|
913
|
+
h3.page-list__item-title
|
|
914
|
+
a.page-list__link(href=page.href) #{page.title}
|
|
915
|
+
if page.description
|
|
916
|
+
p.page-list__description #{page.description}
|
|
917
|
+
footer.page-list__footer
|
|
918
|
+
a.page-list__more-link(href=page.href) #{page.moreLinkText}
|
|
919
|
+
|
|
920
|
+
-
|
|
921
|
+
var pageList = app.pageList
|
|
922
|
+
var isFlat = Array.isArray(pageList)
|
|
923
|
+
var groups = []
|
|
924
|
+
|
|
925
|
+
if (isFlat) {
|
|
926
|
+
groups = pageList.length ? [{ key: null, pages: pageList }] : []
|
|
927
|
+
} else if (pageList && typeof pageList === 'object') {
|
|
928
|
+
groups = Object.keys(pageList)
|
|
929
|
+
.filter(function (key) {
|
|
930
|
+
return Array.isArray(pageList[key]) && pageList[key].length > 0
|
|
931
|
+
})
|
|
932
|
+
.map(function (key) {
|
|
933
|
+
return { key: key, pages: pageList[key] }
|
|
934
|
+
})
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
if groups.length > 0
|
|
938
|
+
section.page-list
|
|
939
|
+
h2.page-list__title Recent Pages
|
|
940
|
+
if isFlat
|
|
941
|
+
+pageListItems(groups[0].pages)
|
|
942
|
+
else
|
|
943
|
+
each group in groups
|
|
944
|
+
div.page-list__group
|
|
945
|
+
h3.page-list__group-title #{group.key}
|
|
946
|
+
+pageListItems(group.pages)
|
|
947
|
+
```
|
|
948
|
+
|
|
949
|
+
Each post becomes an `article` with its title, description and a "Read more"
|
|
950
|
+
link, under the heading "Recent Pages". To change the heading or the markup, edit
|
|
951
|
+
this file — it is your copy now. Running `npx nera-simple-page-list` again skips
|
|
952
|
+
the folder because it already exists; `npx nera-simple-page-list --force`
|
|
953
|
+
overwrites it with the shipped version and discards your edits.
|
|
954
|
+
|
|
955
|
+
Prefer to write the list yourself? See
|
|
956
|
+
[Write your own local plugin](https://nera.js.org/tutorials/write-a-local-plugin.html).
|
|
957
|
+
|
|
958
|
+
## 4. Grow it
|
|
959
|
+
|
|
960
|
+
- **Tags:** give posts `tags:` and get a page per tag with
|
|
961
|
+
[Tag your content](https://nera.js.org/tutorials/tag-your-content.html).
|
|
962
|
+
- **Previous/next links:** link each post to its neighbours in `pages/posts/` with
|
|
963
|
+
[Add prev/next links between pages](https://nera.js.org/tutorials/prev-next-pagination.html).
|
|
964
|
+
- **Sitemap:** set your site's origin as in
|
|
965
|
+
[Add canonical links for SEO](https://nera.js.org/tutorials/canonical-links-seo.html), then add
|
|
966
|
+
`@nera-static/plugin-sitemap` from the [plugin catalog](https://nera.js.org/plugins/index.html).
|
|
967
|
+
- **Images and code:** `@nera-static/plugin-images` (responsive images) and
|
|
968
|
+
`@nera-static/plugin-code-blocks` (syntax highlighting) are in the
|
|
969
|
+
[plugin catalog](https://nera.js.org/plugins/index.html) too.
|
|
970
|
+
|
|
971
|
+
## 5. Preview and build
|
|
972
|
+
|
|
973
|
+
```bash
|
|
974
|
+
npm run dev
|
|
975
|
+
```
|
|
976
|
+
|
|
977
|
+
Open `http://localhost:3000`: the home page lists "My second post" above "Hello
|
|
978
|
+
world", and each title links to its post. The preview rebuilds when you save a
|
|
979
|
+
file.
|
|
980
|
+
|
|
981
|
+
When you're ready to publish, build the site once:
|
|
982
|
+
|
|
983
|
+
```bash
|
|
984
|
+
npm run build
|
|
985
|
+
```
|
|
986
|
+
|
|
987
|
+
The finished blog is in `public/` — upload that folder to any static host.
|
|
988
|
+
|
|
989
|
+
# Build a navigation with active states
|
|
990
|
+
|
|
991
|
+
Source: https://nera.js.org/tutorials/custom-navigation.html
|
|
992
|
+
|
|
993
|
+
`@nera-static/plugin-navigation` turns a YAML list into a navigation menu and marks
|
|
994
|
+
the link for the current page — no JavaScript required.
|
|
995
|
+
|
|
996
|
+
## 1. Install and publish the template
|
|
997
|
+
|
|
998
|
+
```bash
|
|
999
|
+
npm install @nera-static/plugin-navigation
|
|
1000
|
+
npx nera-navigation
|
|
1001
|
+
```
|
|
1002
|
+
|
|
1003
|
+
The second command copies the nav templates into
|
|
1004
|
+
`theme/views/vendor/plugin-navigation/`, where you can edit them freely.
|
|
1005
|
+
|
|
1006
|
+
## 2. Define the menu
|
|
1007
|
+
|
|
1008
|
+
Create `config/navigation.yaml`. A single flat menu looks like this:
|
|
1009
|
+
|
|
1010
|
+
```yaml
|
|
1011
|
+
active_class: nav__link--active
|
|
1012
|
+
active_path_class: nav__link--active-path
|
|
1013
|
+
nav_class: nav
|
|
1014
|
+
|
|
1015
|
+
elements:
|
|
1016
|
+
- href: /index.html
|
|
1017
|
+
name: Home
|
|
1018
|
+
- href: /docs/index.html
|
|
1019
|
+
name: Docs
|
|
1020
|
+
```
|
|
1021
|
+
|
|
1022
|
+
All three class keys are optional, and the values above are their defaults, so this
|
|
1023
|
+
example renders the same as one without them. `active_class` goes on the link to the
|
|
1024
|
+
current page, `active_path_class` on a section link — one pointing at a folder's index,
|
|
1025
|
+
such as `/docs/index.html` or `/docs/` — when the current page sits in that folder or below
|
|
1026
|
+
(the site root never counts). `nav_class` is the BEM block name the other classes derive
|
|
1027
|
+
from: `nav_class: mainmenu` renames the whole family to `.mainmenu`, `.mainmenu--list`,
|
|
1028
|
+
`.mainmenu__item`, `.mainmenu__link`, `.mainmenu__link--active` and
|
|
1029
|
+
`.mainmenu__link--active-path`. The two state keys override just their own class, so
|
|
1030
|
+
when you rename, drop them — left as above, they keep `nav__link--active`.
|
|
1031
|
+
|
|
1032
|
+
Every entry needs an `href`: one without it is skipped with a warning, and the build
|
|
1033
|
+
still succeeds.
|
|
1034
|
+
|
|
1035
|
+
> Upgrading from 2.x? Publishing skips an existing `theme/views/vendor/plugin-navigation/`,
|
|
1036
|
+
> so the old templates stay and `nav_class` seems to do nothing. Run
|
|
1037
|
+
> `npx nera-navigation --force` once — it overwrites that folder, so if you edited your
|
|
1038
|
+
> copy, save your changes first and carry them over.
|
|
1039
|
+
|
|
1040
|
+
Need more than one menu? Nest them under names — each becomes
|
|
1041
|
+
`app.nav.<name>.elements`:
|
|
1042
|
+
|
|
1043
|
+
```yaml
|
|
1044
|
+
elements:
|
|
1045
|
+
main:
|
|
1046
|
+
- href: /index.html
|
|
1047
|
+
name: Home
|
|
1048
|
+
- href: /docs/index.html
|
|
1049
|
+
name: Docs
|
|
1050
|
+
footer:
|
|
1051
|
+
- href: /about.html
|
|
1052
|
+
name: About
|
|
1053
|
+
```
|
|
1054
|
+
|
|
1055
|
+
The plugin exposes everything under `app.nav`.
|
|
1056
|
+
|
|
1057
|
+
## 3. Render it in a layout
|
|
1058
|
+
|
|
1059
|
+
Include the published partial and call its mixin:
|
|
1060
|
+
|
|
1061
|
+
```pug
|
|
1062
|
+
include /vendor/plugin-navigation/partials/link-list-navigation
|
|
1063
|
+
|
|
1064
|
+
header.site-header
|
|
1065
|
+
if app.nav && app.nav.main
|
|
1066
|
+
nav.nav--main(aria-label='Main menu')
|
|
1067
|
+
+linkListNav(app.nav.main.elements)
|
|
1068
|
+
```
|
|
1069
|
+
|
|
1070
|
+
The plugin adds the active class from section 2 (`nav__link--active` by default) to
|
|
1071
|
+
the link matching the current page, and the active-path class
|
|
1072
|
+
(`nav__link--active-path`) to the section link the page sits in, so styling the
|
|
1073
|
+
current section is just CSS. The `nav` with its `aria-label` makes the menu a named
|
|
1074
|
+
navigation landmark for screen readers. The leading `/` in the include resolves from
|
|
1075
|
+
`theme/views/`, wherever the including file sits.
|
|
1076
|
+
|
|
1077
|
+
> Prefer a different shape? The plugin also ships `simple-navigation` and
|
|
1078
|
+
> `pipe-separated-navigation` partials — same data, different markup.
|
|
1079
|
+
|
|
1080
|
+
This site uses exactly this setup for its header and footer — see
|
|
1081
|
+
[`config/navigation.yaml`](https://github.com/seebaermichi/nera-website/blob/main/config/navigation.yaml) in the source.
|
|
1082
|
+
|
|
1083
|
+
# Tag your content and get topic pages for free
|
|
1084
|
+
|
|
1085
|
+
Source: https://nera.js.org/tutorials/tag-your-content.html
|
|
1086
|
+
|
|
1087
|
+
`@nera-static/plugin-tags` reads a `tags:` field from your frontmatter, then builds
|
|
1088
|
+
a browsable overview page for every tag automatically.
|
|
1089
|
+
|
|
1090
|
+
## 1. Install and publish templates
|
|
1091
|
+
|
|
1092
|
+
```bash
|
|
1093
|
+
npm install @nera-static/plugin-tags
|
|
1094
|
+
npx nera-tags
|
|
1095
|
+
```
|
|
1096
|
+
|
|
1097
|
+
## 2. Tag some pages
|
|
1098
|
+
|
|
1099
|
+
Add a comma-separated `tags` value to any page's frontmatter:
|
|
1100
|
+
|
|
1101
|
+
```markdown
|
|
1102
|
+
---
|
|
1103
|
+
layout: pages/tutorial.pug
|
|
1104
|
+
title: Add client-side search
|
|
1105
|
+
tags: plugins, search
|
|
1106
|
+
---
|
|
1107
|
+
```
|
|
1108
|
+
|
|
1109
|
+
Tags are slugified and case-folded, so `Web Dev`, `web dev` and `WEB DEV` all map to
|
|
1110
|
+
one page at `/tags/web-dev.html`.
|
|
1111
|
+
|
|
1112
|
+
## 3. Configure (optional)
|
|
1113
|
+
|
|
1114
|
+
`config/tags.yaml` — every key is optional:
|
|
1115
|
+
|
|
1116
|
+
```yaml
|
|
1117
|
+
meta_property_name: tags
|
|
1118
|
+
tag_overview_path: '/tags'
|
|
1119
|
+
tag_separator: ','
|
|
1120
|
+
tag_overview_layout: pages/tag-overview.pug
|
|
1121
|
+
```
|
|
1122
|
+
|
|
1123
|
+
The `tag_overview_layout` points at a layout that renders the published overview
|
|
1124
|
+
template. Create `theme/views/pages/tag-overview.pug`:
|
|
1125
|
+
|
|
1126
|
+
```pug
|
|
1127
|
+
extends ../layouts/layout
|
|
1128
|
+
|
|
1129
|
+
block content
|
|
1130
|
+
.container
|
|
1131
|
+
include ../vendor/plugin-tags/pages/tag-overview
|
|
1132
|
+
```
|
|
1133
|
+
|
|
1134
|
+
## 4. Show tags on a page
|
|
1135
|
+
|
|
1136
|
+
The plugin gives each page a `meta.tagLinks` list. Include the published partial in
|
|
1137
|
+
your article layout:
|
|
1138
|
+
|
|
1139
|
+
```pug
|
|
1140
|
+
if meta.tagLinks
|
|
1141
|
+
include ../vendor/plugin-tags/partials/tag-links
|
|
1142
|
+
```
|
|
1143
|
+
|
|
1144
|
+
And for a site-wide cloud, `app.tagCloud` drives the `tag-cloud` partial:
|
|
1145
|
+
|
|
1146
|
+
```pug
|
|
1147
|
+
if app.tagCloud
|
|
1148
|
+
include ../vendor/plugin-tags/partials/tag-cloud
|
|
1149
|
+
```
|
|
1150
|
+
|
|
1151
|
+
## 5. Per-language tags (optional)
|
|
1152
|
+
|
|
1153
|
+
By default every tag lives in one namespace, so a multilingual site merges all
|
|
1154
|
+
languages into one overview page. Set `group_by_lang` to give each language its
|
|
1155
|
+
own:
|
|
1156
|
+
|
|
1157
|
+
```yaml
|
|
1158
|
+
group_by_lang: true
|
|
1159
|
+
```
|
|
1160
|
+
|
|
1161
|
+
Tags are then collected per `meta.lang`, and the language code prefixes the whole
|
|
1162
|
+
`tag_overview_path`. With `tag_overview_path: '/tutorials/tags'` you get:
|
|
1163
|
+
|
|
1164
|
+
```
|
|
1165
|
+
/tutorials/tags/<slug>.html # default language
|
|
1166
|
+
/de/tutorials/tags/<slug>.html # German pages only
|
|
1167
|
+
/es/tutorials/tags/<slug>.html # Spanish pages only
|
|
1168
|
+
```
|
|
1169
|
+
|
|
1170
|
+
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, add
|
|
1172
|
+
`prefix_default_lang: true` so it gets a segment too. Pages without a `meta.lang`
|
|
1173
|
+
fall into the default language rather than a bucket of their own, so a
|
|
1174
|
+
single-language site is unaffected by any of this.
|
|
1175
|
+
|
|
1176
|
+
Chips and clouds follow along on their own: `meta.tagLinks` links within the
|
|
1177
|
+
page's own language, and each page gets a `meta.tagCloud` scoped to it. Watch one
|
|
1178
|
+
detail — `app.tagCloud` still exists, but with grouping on it holds the *default*
|
|
1179
|
+
language's cloud. Guarding on it is fine; reading it directly to render a cloud
|
|
1180
|
+
is not, because a German page would show English tags. The shipped `tag-cloud`
|
|
1181
|
+
partial already prefers `meta.tagCloud` and falls back to `app.tagCloud`, so use
|
|
1182
|
+
the partial rather than looping yourself. `app.tagCloudByLang` has every
|
|
1183
|
+
language, keyed by code, if you need them all at once.
|
|
1184
|
+
|
|
1185
|
+
Generated overview pages also carry their own `meta.lang`, so `t()` inside the
|
|
1186
|
+
overview layout resolves in that page's language.
|
|
1187
|
+
|
|
1188
|
+
Render, and every tag now has its own page — no manual index maintenance. The
|
|
1189
|
+
tutorial you're reading is tagged this way; the chips above link to the generated
|
|
1190
|
+
tag pages. This site runs with `group_by_lang: true`, so those chips lead to the
|
|
1191
|
+
tag pages for whichever language you are reading.
|
|
1192
|
+
|
|
1193
|
+
# Add client-side search
|
|
1194
|
+
|
|
1195
|
+
Source: https://nera.js.org/tutorials/add-search.html
|
|
1196
|
+
|
|
1197
|
+
`@nera-static/plugin-search` builds a JSON index at render time and ships a small
|
|
1198
|
+
client script — no server required.
|
|
1199
|
+
|
|
1200
|
+
## 1. Install
|
|
1201
|
+
|
|
1202
|
+
```bash
|
|
1203
|
+
npm install @nera-static/plugin-search
|
|
1204
|
+
```
|
|
1205
|
+
|
|
1206
|
+
## 2. Publish the template
|
|
1207
|
+
|
|
1208
|
+
```bash
|
|
1209
|
+
npx nera-search
|
|
1210
|
+
```
|
|
1211
|
+
|
|
1212
|
+
This copies the search box into `theme/views/vendor/plugin-search/` and the client into
|
|
1213
|
+
`theme/assets/js/search.js`.
|
|
1214
|
+
|
|
1215
|
+
Both copies are yours from then on. Running `npx nera-search` again skips the
|
|
1216
|
+
template if the `vendor/plugin-search/` folder exists and the client if
|
|
1217
|
+
`search.js` exists, so it never discards your edits — and a template change in a
|
|
1218
|
+
new release never reaches your site on its own. To refresh after an upgrade, run
|
|
1219
|
+
`npx nera-search --force`, but only if you never edited the copies: it overwrites
|
|
1220
|
+
both. If you did, diff them against the package and merge the changes by hand
|
|
1221
|
+
(the plugin README's *Template Publishing* section explains how).
|
|
1222
|
+
|
|
1223
|
+
## 3. Configure
|
|
1224
|
+
|
|
1225
|
+
`config/search.yaml` controls which fields are indexed. The file is optional;
|
|
1226
|
+
these are the defaults:
|
|
1227
|
+
|
|
1228
|
+
```yaml
|
|
1229
|
+
fields:
|
|
1230
|
+
- title
|
|
1231
|
+
- excerpt
|
|
1232
|
+
- content
|
|
1233
|
+
- href
|
|
1234
|
+
strip_html: true
|
|
1235
|
+
output_filename: search-index.json
|
|
1236
|
+
```
|
|
1237
|
+
|
|
1238
|
+
`fields` replaces the default list rather than extending it, so keep `content`
|
|
1239
|
+
(the page body) and `href` (the result link). Any other frontmatter key works if
|
|
1240
|
+
your pages define it — the starter page `nera new` scaffolds has a `description`
|
|
1241
|
+
but no `excerpt`, so add `description` if you want it indexed; a field a page
|
|
1242
|
+
lacks is simply left off its entry.
|
|
1243
|
+
|
|
1244
|
+
To keep part of a page out of the index, mark it with `data-search-ignore`: the
|
|
1245
|
+
element and everything inside it is dropped from `content`.
|
|
1246
|
+
`@nera-static/plugin-code-blocks` (1.1.0 and later) marks its code-block bar this
|
|
1247
|
+
way, so file names and the Copy button stay out of your results. In Markdown,
|
|
1248
|
+
write the attribute on raw HTML:
|
|
1249
|
+
|
|
1250
|
+
```html
|
|
1251
|
+
<aside data-search-ignore>Not part of the index.</aside>
|
|
1252
|
+
```
|
|
1253
|
+
|
|
1254
|
+
## 4. Add a search page
|
|
1255
|
+
|
|
1256
|
+
The search box is Pug, so it belongs in a view, not in the Markdown. Create
|
|
1257
|
+
`theme/views/pages/search.pug` on top of the layout `nera new` scaffolds:
|
|
1258
|
+
|
|
1259
|
+
```pug
|
|
1260
|
+
extends ../layouts/layout
|
|
1261
|
+
|
|
1262
|
+
block content
|
|
1263
|
+
main
|
|
1264
|
+
article!= content
|
|
1265
|
+
include /vendor/plugin-search/search.pug
|
|
1266
|
+
```
|
|
1267
|
+
|
|
1268
|
+
The leading slash resolves the include from `theme/views/`. Then point a page at
|
|
1269
|
+
the view — a page without `layout` is neither rendered nor indexed:
|
|
1270
|
+
|
|
1271
|
+
```markdown
|
|
1272
|
+
---
|
|
1273
|
+
title: Search
|
|
1274
|
+
layout: pages/search.pug
|
|
1275
|
+
---
|
|
1276
|
+
|
|
1277
|
+
# Search
|
|
1278
|
+
|
|
1279
|
+
Search across the documentation.
|
|
1280
|
+
```
|
|
1281
|
+
|
|
1282
|
+
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:
|
|
1284
|
+
|
|
1285
|
+
```yaml
|
|
1286
|
+
show_title: false
|
|
1287
|
+
```
|
|
1288
|
+
|
|
1289
|
+
If your page has no heading of its own, leave `show_title` out and the template's
|
|
1290
|
+
`h1` is the page heading.
|
|
1291
|
+
|
|
1292
|
+
The template's texts go through `t()`: `search_title` (the heading, default
|
|
1293
|
+
`Search`), `search_placeholder` (default `Search...`) and `search_label`, the
|
|
1294
|
+
input's accessible name (default `Search`). Translate them under `translations`
|
|
1295
|
+
in `config/app.yaml`, for example for German:
|
|
1296
|
+
|
|
1297
|
+
```yaml
|
|
1298
|
+
translations:
|
|
1299
|
+
de:
|
|
1300
|
+
search_title: Suche
|
|
1301
|
+
search_placeholder: Suchen…
|
|
1302
|
+
search_label: Suche
|
|
1303
|
+
```
|
|
1304
|
+
|
|
1305
|
+
Finally, make sure search runs **last** in `config/plugin-order.yaml` so it
|
|
1306
|
+
indexes final page data, including pages other plugins generate:
|
|
1307
|
+
|
|
1308
|
+
```yaml
|
|
1309
|
+
plugin-order:
|
|
1310
|
+
- end:
|
|
1311
|
+
- plugin-search
|
|
1312
|
+
```
|
|
1313
|
+
|
|
1314
|
+
## 5. Per-language search (optional)
|
|
1315
|
+
|
|
1316
|
+
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 give each language
|
|
1318
|
+
an index of its own:
|
|
1319
|
+
|
|
1320
|
+
```yaml
|
|
1321
|
+
group_by_lang: true
|
|
1322
|
+
```
|
|
1323
|
+
|
|
1324
|
+
Pages are grouped by `meta.lang`, and the language code goes before the
|
|
1325
|
+
extension of `output_filename`. The default language keeps the plain filename:
|
|
1326
|
+
|
|
1327
|
+
```
|
|
1328
|
+
/search-index.json # default language
|
|
1329
|
+
/search-index.de.json # German pages only
|
|
1330
|
+
/search-index.es.json # Spanish pages only
|
|
1331
|
+
```
|
|
1332
|
+
|
|
1333
|
+
Pages without a `meta.lang` fall into the default language — `lang` in
|
|
1334
|
+
`config/app.yaml` — so a single-language site is unaffected by any of this.
|
|
1335
|
+
|
|
1336
|
+
Every page then carries `meta.searchIndexPath`, the index for its own language.
|
|
1337
|
+
The published `search.pug` passes it to the client as `data-search-index` and
|
|
1338
|
+
`search.js` fetches that URL, so your own markup needs no change. Watch one
|
|
1339
|
+
detail — `app.searchIndexPath` still exists, but with grouping on it points at
|
|
1340
|
+
the *default* language's index, so building the attribute from it would search
|
|
1341
|
+
English from a German page. `app.searchIndexPaths` has every language keyed by
|
|
1342
|
+
code, and each index entry carries its `lang`.
|
|
1343
|
+
|
|
1344
|
+
Because search runs last (step 4), pages other plugins generate land in the
|
|
1345
|
+
right language too — the tag pages from `plugin-tags` among them.
|
|
1346
|
+
|
|
1347
|
+
Render, and you have working search. This site's [Search page](https://nera.js.org/search.html) is
|
|
1348
|
+
built from the same parts, with two differences: its Markdown has no heading, so
|
|
1349
|
+
it keeps the template's `h1`, translated with the three keys in English, German
|
|
1350
|
+
and Spanish; and it sets `group_by_lang: true`, so the box returns only pages in
|
|
1351
|
+
the language you are reading.
|
|
1352
|
+
|
|
1353
|
+
# Add prev/next links between pages
|
|
1354
|
+
|
|
1355
|
+
Source: https://nera.js.org/tutorials/prev-next-pagination.html
|
|
1356
|
+
|
|
1357
|
+
`@nera-static/plugin-page-pagination` links each page to its previous and next
|
|
1358
|
+
**sibling** — pages in the same directory — in an order you control. Perfect for
|
|
1359
|
+
docs and multi-part tutorials.
|
|
1360
|
+
|
|
1361
|
+
## 1. Install and publish the template
|
|
1362
|
+
|
|
1363
|
+
```bash
|
|
1364
|
+
npm install @nera-static/plugin-page-pagination
|
|
1365
|
+
npx nera-page-pagination
|
|
1366
|
+
```
|
|
1367
|
+
|
|
1368
|
+
## 2. Order the pages
|
|
1369
|
+
|
|
1370
|
+
By default the plugin reads a `pagination_order` number from each page:
|
|
1371
|
+
|
|
1372
|
+
```markdown
|
|
1373
|
+
---
|
|
1374
|
+
title: Getting started
|
|
1375
|
+
pagination_order: 2
|
|
1376
|
+
---
|
|
1377
|
+
```
|
|
1378
|
+
|
|
1379
|
+
Pages are ordered by `pagination_order` first, then by creation date, then by
|
|
1380
|
+
path — so a page without an explicit order still lands somewhere stable.
|
|
1381
|
+
|
|
1382
|
+
> Ordering starts at `0` if you want it to: the plugin treats `0` as a real value,
|
|
1383
|
+
> not "missing". Change the key name in `config/page-pagination.yaml` with
|
|
1384
|
+
> `order_property` if you prefer.
|
|
1385
|
+
|
|
1386
|
+
## 3. Render the links
|
|
1387
|
+
|
|
1388
|
+
The plugin adds `meta.pagePagination` with `.previous` and `.next`. Include the
|
|
1389
|
+
published template, guarded so it's hidden when there's nowhere to go:
|
|
1390
|
+
|
|
1391
|
+
```pug
|
|
1392
|
+
if meta.pagePagination && (meta.pagePagination.previous || meta.pagePagination.next)
|
|
1393
|
+
include ../vendor/plugin-page-pagination/page-pagination
|
|
1394
|
+
```
|
|
1395
|
+
|
|
1396
|
+
## Why "siblings only" matters
|
|
1397
|
+
|
|
1398
|
+
Pagination is scoped per directory, so `pages/docs/*.md` paginate among themselves
|
|
1399
|
+
and `pages/tutorials/*.md` among themselves — they never bleed into each other. Put
|
|
1400
|
+
a sequence in its own folder and it just works. This site's docs use exactly this.
|
|
1401
|
+
|
|
1402
|
+
# Open external links in a new tab
|
|
1403
|
+
|
|
1404
|
+
Source: https://nera.js.org/tutorials/external-links-new-tab.html
|
|
1405
|
+
|
|
1406
|
+
`@nera-static/plugin-link-attributes` post-processes your rendered HTML and adds
|
|
1407
|
+
attributes to outbound links — so every external link opens in a new tab, safely,
|
|
1408
|
+
without you touching the Markdown.
|
|
1409
|
+
|
|
1410
|
+
## 1. Install
|
|
1411
|
+
|
|
1412
|
+
```bash
|
|
1413
|
+
npm install @nera-static/plugin-link-attributes
|
|
1414
|
+
```
|
|
1415
|
+
|
|
1416
|
+
No template to publish — this plugin only transforms content. Its one setting
|
|
1417
|
+
lives in a config file.
|
|
1418
|
+
|
|
1419
|
+
## 2. Configure
|
|
1420
|
+
|
|
1421
|
+
`config/link-attributes.yaml` lists the attributes to add. The quick way to get
|
|
1422
|
+
it is the plugin's own command, which writes the defaults shown below:
|
|
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:
|
|
1431
|
+
|
|
1432
|
+
```yaml
|
|
1433
|
+
attributes:
|
|
1434
|
+
- target="_blank"
|
|
1435
|
+
- rel="noopener noreferrer"
|
|
1436
|
+
```
|
|
1437
|
+
|
|
1438
|
+
Without any `attributes` the plugin leaves your pages unchanged — no file, no new
|
|
1439
|
+
tabs.
|
|
1440
|
+
|
|
1441
|
+
The plugin targets only links whose `href` starts with `http` or `www`, so your
|
|
1442
|
+
internal links (`/docs/...`) are left alone, and an attribute a link already has
|
|
1443
|
+
is never overwritten. The `rel="noopener noreferrer"` is worth keeping — it closes
|
|
1444
|
+
the tab-nabbing hole that bare `target="_blank"` opens.
|
|
1445
|
+
|
|
1446
|
+
## 3. The one gotcha: layout links
|
|
1447
|
+
|
|
1448
|
+
The plugin rewrites links inside your **Markdown content**, not links you write
|
|
1449
|
+
directly in Pug layouts (a header "GitHub" button, a footer link). Add the same
|
|
1450
|
+
attributes to those by hand:
|
|
1451
|
+
|
|
1452
|
+
```pug
|
|
1453
|
+
a.site-header__cta(href=app.repo_url, target="_blank", rel="noopener noreferrer") GitHub
|
|
1454
|
+
```
|
|
1455
|
+
|
|
1456
|
+
Render, and every outbound link — in content and in your layout — opens in a new
|
|
1457
|
+
tab. This site does exactly this; try any GitHub link.
|
|
1458
|
+
|
|
1459
|
+
# Add canonical links for SEO
|
|
1460
|
+
|
|
1461
|
+
Source: https://nera.js.org/tutorials/canonical-links-seo.html
|
|
1462
|
+
|
|
1463
|
+
Search engines want a single canonical URL per page, and on a multilingual site
|
|
1464
|
+
they want to know which pages are translations of each other.
|
|
1465
|
+
`@nera-static/plugin-canonical-links` emits the `<link rel="canonical">` tag on
|
|
1466
|
+
every page and `hreflang` alternate tags between translations. Get these wrong and
|
|
1467
|
+
nothing breaks visibly — the page renders fine, and the mistake only shows up in a
|
|
1468
|
+
search console weeks later. So check the output, as this tutorial does at every step.
|
|
1469
|
+
|
|
1470
|
+
## 1. Install and publish the template
|
|
1471
|
+
|
|
1472
|
+
```bash
|
|
1473
|
+
npm install @nera-static/plugin-canonical-links
|
|
1474
|
+
npx nera-canonical-links
|
|
1475
|
+
```
|
|
1476
|
+
|
|
1477
|
+
The second command copies `index.pug` and its `partials/` to
|
|
1478
|
+
`theme/views/vendor/plugin-canonical-links/`. It skips if that folder already
|
|
1479
|
+
exists, so your edits are safe; `npx nera-canonical-links --force` overwrites them
|
|
1480
|
+
with the shipped templates after an upgrade.
|
|
1481
|
+
|
|
1482
|
+
## 2. Set your origin
|
|
1483
|
+
|
|
1484
|
+
Canonical URLs are absolute, so the plugin needs your site's origin. Set it once in
|
|
1485
|
+
`config/app.yaml`:
|
|
1486
|
+
|
|
1487
|
+
```yaml
|
|
1488
|
+
origin: https://example.com
|
|
1489
|
+
```
|
|
1490
|
+
|
|
1491
|
+
That is all the configuration a single-language site needs — **the plugin's own
|
|
1492
|
+
config file is optional**. If you do create `config/canonical-links.yaml`, its
|
|
1493
|
+
`app_origin` is used as a fallback when `app.yaml` has no `origin`; when both are
|
|
1494
|
+
set, `origin` in `app.yaml` wins. A trailing slash is stripped either way.
|
|
1495
|
+
|
|
1496
|
+
With no origin at all, the plugin emits no canonical or alternate links and prints
|
|
1497
|
+
one warning during the build:
|
|
1498
|
+
|
|
1499
|
+
```text
|
|
1500
|
+
⚠️ plugin-canonical-links: no origin configured, so no canonical links were generated.
|
|
1501
|
+
Set `origin` in config/app.yaml, or `app_origin` in config/canonical-links.yaml.
|
|
1502
|
+
```
|
|
1503
|
+
|
|
1504
|
+
If your site is served from a subdirectory, `base_path` in `config/app.yaml` is
|
|
1505
|
+
part of the URL too. Canonical and alternate URLs are built as origin + base path
|
|
1506
|
+
+ page path:
|
|
1507
|
+
|
|
1508
|
+
```yaml
|
|
1509
|
+
origin: https://example.com
|
|
1510
|
+
base_path: /docs/
|
|
1511
|
+
```
|
|
1512
|
+
|
|
1513
|
+
```html
|
|
1514
|
+
<link href="https://example.com/docs/getting-started.html" rel="canonical" />
|
|
1515
|
+
```
|
|
1516
|
+
|
|
1517
|
+
Without `base_path` the output is unchanged. Versions before 2.2.3 left the base
|
|
1518
|
+
path out and pointed search engines at a URL that does not exist.
|
|
1519
|
+
|
|
1520
|
+
## 3. Emit the tags
|
|
1521
|
+
|
|
1522
|
+
The plugin sets `meta.canonicalLink` on every page. Include the published template
|
|
1523
|
+
in your layout's `<head>`:
|
|
1524
|
+
|
|
1525
|
+
```pug
|
|
1526
|
+
head
|
|
1527
|
+
include /vendor/plugin-canonical-links/index
|
|
1528
|
+
```
|
|
1529
|
+
|
|
1530
|
+
The leading slash makes the path root-absolute: it resolves against `theme/views/`,
|
|
1531
|
+
wherever the including file sits. The relative form
|
|
1532
|
+
`include ../vendor/plugin-canonical-links/index` does the same, but only from a
|
|
1533
|
+
layout in `theme/views/layouts/` — use it on Nera core 4.1–4.2, where the
|
|
1534
|
+
root-absolute form is not available yet. A bare `include vendor/…` (no slash, no
|
|
1535
|
+
`../`) looks in `theme/views/layouts/vendor/` and fails the build.
|
|
1536
|
+
|
|
1537
|
+
Build and view the source of `pages/getting-started.md` — you'll see:
|
|
1538
|
+
|
|
1539
|
+
```html
|
|
1540
|
+
<link href="https://example.com/getting-started.html" rel="canonical" />
|
|
1541
|
+
```
|
|
1542
|
+
|
|
1543
|
+
## 4. Link translations with hreflang
|
|
1544
|
+
|
|
1545
|
+
Alternate-language links need three things. First, list your languages in
|
|
1546
|
+
`config/canonical-links.yaml`:
|
|
1547
|
+
|
|
1548
|
+
```yaml
|
|
1549
|
+
page_identifier: slug
|
|
1550
|
+
available_languages:
|
|
1551
|
+
- en
|
|
1552
|
+
- de
|
|
1553
|
+
```
|
|
1554
|
+
|
|
1555
|
+
`page_identifier` names the frontmatter key that marks two pages as translations
|
|
1556
|
+
of each other; `slug` is the default, so you can leave the line out. Second, every
|
|
1557
|
+
page sets its `lang`. Third, translations share an identical `slug`:
|
|
1558
|
+
|
|
1559
|
+
```markdown
|
|
1560
|
+
---
|
|
1561
|
+
title: Getting started
|
|
1562
|
+
slug: getting-started
|
|
1563
|
+
lang: en
|
|
1564
|
+
---
|
|
1565
|
+
```
|
|
1566
|
+
|
|
1567
|
+
```markdown
|
|
1568
|
+
---
|
|
1569
|
+
title: Erste Schritte
|
|
1570
|
+
slug: getting-started
|
|
1571
|
+
lang: de
|
|
1572
|
+
---
|
|
1573
|
+
```
|
|
1574
|
+
|
|
1575
|
+
With the English page at `pages/getting-started.md` and the German one at
|
|
1576
|
+
`pages/de/getting-started.md`, the build gives the English page:
|
|
1577
|
+
|
|
1578
|
+
```html
|
|
1579
|
+
<link href="https://example.com/getting-started.html" rel="canonical" />
|
|
1580
|
+
<link href="https://example.com/de/getting-started.html" hreflang="de" rel="alternate" />
|
|
1581
|
+
```
|
|
1582
|
+
|
|
1583
|
+
and the German page:
|
|
1584
|
+
|
|
1585
|
+
```html
|
|
1586
|
+
<link href="https://example.com/de/getting-started.html" rel="canonical" />
|
|
1587
|
+
<link href="https://example.com/getting-started.html" hreflang="en" rel="alternate" />
|
|
1588
|
+
```
|
|
1589
|
+
|
|
1590
|
+
Each page points at its translations, not at itself. All of this fails silently:
|
|
1591
|
+
|
|
1592
|
+
- Without `available_languages` you get canonical links only, and
|
|
1593
|
+
`meta.alternateLinks` is an empty array.
|
|
1594
|
+
- A page without `lang` gets its canonical link but no alternates.
|
|
1595
|
+
- A page without a `slug` is never matched to anything.
|
|
1596
|
+
|
|
1597
|
+
If you write your own template instead of the published one, read
|
|
1598
|
+
`meta.alternateLinks` — a list of `{ href, hreflang, rel }` — and guard for both
|
|
1599
|
+
keys being absent when no origin is set.
|
|
1600
|
+
|
|
1601
|
+
## 5. Cover pages from other plugins
|
|
1602
|
+
|
|
1603
|
+
Some plugins create pages while they run — `@nera-static/plugin-tags` builds its
|
|
1604
|
+
tag overview pages that way (see [Tag your content](https://nera.js.org/tutorials/tag-your-content.html)).
|
|
1605
|
+
Plugins run in alphabetical order, and `plugin-canonical-links` comes before
|
|
1606
|
+
`plugin-tags`, so those tag pages are built after it has finished and get **no
|
|
1607
|
+
canonical link**. Move it to the end in `config/plugin-order.yaml` (Nera core
|
|
1608
|
+
4.2.0 or newer):
|
|
1609
|
+
|
|
1610
|
+
```yaml
|
|
1611
|
+
plugin-order:
|
|
1612
|
+
- end:
|
|
1613
|
+
- plugin-canonical-links
|
|
1614
|
+
```
|
|
1615
|
+
|
|
1616
|
+
Now every tag page carries one:
|
|
1617
|
+
|
|
1618
|
+
```html
|
|
1619
|
+
<link href="https://example.com/tags/seo.html" rel="canonical" />
|
|
1620
|
+
```
|
|
1621
|
+
|
|
1622
|
+
Generated pages have no `slug`, so they get a canonical link and no alternates.
|
|
1623
|
+
|
|
1624
|
+
The sitemap plugin, [`@nera-static/plugin-sitemap`](https://www.npmjs.com/package/@nera-static/plugin-sitemap),
|
|
1625
|
+
reads the same origin (`origin` in `app.yaml`, else `app_origin`) and the same
|
|
1626
|
+
`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.
|
|
1628
|
+
|
|
1629
|
+
This site uses the plugin as well, set up as this tutorial describes:
|
|
1630
|
+
`origin: https://nera.js.org` in `config/app.yaml`, the root-absolute include in its layout,
|
|
1631
|
+
and `plugin-canonical-links` under `end:` in `config/plugin-order.yaml`. Its
|
|
1632
|
+
`config/canonical-links.yaml` lists only `en` and `de` as languages — Spanish is
|
|
1633
|
+
left out until a native-speaker review is done, so no page carries an
|
|
1634
|
+
`hreflang="es"` alternate yet. View the source of this page to see the result.
|
|
1635
|
+
|
|
1636
|
+
# Write your own local plugin
|
|
1637
|
+
|
|
1638
|
+
Source: https://nera.js.org/tutorials/write-a-local-plugin.html
|
|
1639
|
+
|
|
1640
|
+
You don't need to publish to npm to extend Nera. Any module at
|
|
1641
|
+
`src/plugins/<name>/index.js` is discovered and applied automatically — that is
|
|
1642
|
+
the default, and a site made with `nera new` has no setting for it. To keep
|
|
1643
|
+
local plugins elsewhere, set `folders.plugins` in `config/app.yaml` — this site
|
|
1644
|
+
uses `plugins/`:
|
|
1645
|
+
|
|
1646
|
+
```yaml
|
|
1647
|
+
folders:
|
|
1648
|
+
plugins: ./plugins
|
|
1649
|
+
```
|
|
1650
|
+
|
|
1651
|
+
Let's build a real one: a plugin that collects every tutorial into a list for an
|
|
1652
|
+
index page — a simplified version of the plugin that powers this site — and then
|
|
1653
|
+
publishes the same list as `tutorials.json`.
|
|
1654
|
+
|
|
1655
|
+
## The contract
|
|
1656
|
+
|
|
1657
|
+
A plugin exports any of three hooks:
|
|
1658
|
+
|
|
1659
|
+
```js
|
|
1660
|
+
export function getAppData({ app, pagesData }) {
|
|
1661
|
+
// must return a plain object — becomes the new `app`
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
export function getMetaData({ app, pagesData }) {
|
|
1665
|
+
// must return an array — becomes the new `pagesData`
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
export function getAssets({ app, pagesData }) {
|
|
1669
|
+
// must return an array of { from, to } — files core copies into public/
|
|
1670
|
+
}
|
|
1671
|
+
```
|
|
1672
|
+
|
|
1673
|
+
`getAppData` runs first; `getMetaData` sees the `app` it returned. `getAssets`
|
|
1674
|
+
(core ≥ 4.13.0) runs once every plugin is done with the other two. Nera awaits
|
|
1675
|
+
all hooks (since core 4.3.0; older versions silently replaced `app` with a
|
|
1676
|
+
Promise), but **synchronous stays the safe default** — it is what the published
|
|
1677
|
+
plugins do.
|
|
1678
|
+
|
|
1679
|
+
A hook that returns the wrong type does not stop the build: core prints a warning
|
|
1680
|
+
such as `⚠️ Plugin "tutorials-list" getAppData returned invalid format, skipping
|
|
1681
|
+
replace.` and keeps the old data. When a plugin seems to do nothing, read the
|
|
1682
|
+
build log first. "The hook contract" in the [plugin docs](https://nera.js.org/docs/plugins.html#the-hook-contract) has
|
|
1683
|
+
the short version.
|
|
1684
|
+
|
|
1685
|
+
## Build it
|
|
1686
|
+
|
|
1687
|
+
Create `src/plugins/tutorials-list/index.js`:
|
|
1688
|
+
|
|
1689
|
+
```js
|
|
1690
|
+
export function getAppData({ app, pagesData }) {
|
|
1691
|
+
if (!app || typeof app !== 'object') return app
|
|
1692
|
+
if (!Array.isArray(pagesData)) return app
|
|
1693
|
+
|
|
1694
|
+
const tutorials = pagesData
|
|
1695
|
+
.filter(({ meta }) => {
|
|
1696
|
+
const href = meta?.href || ''
|
|
1697
|
+
return href.startsWith('/tutorials/') && href !== '/tutorials/index.html'
|
|
1698
|
+
})
|
|
1699
|
+
.map(({ meta }) => ({
|
|
1700
|
+
href: meta.href,
|
|
1701
|
+
title: meta.title || meta.href,
|
|
1702
|
+
description: meta.description || '',
|
|
1703
|
+
createdAt: meta.createdAt,
|
|
1704
|
+
}))
|
|
1705
|
+
.sort((a, b) => {
|
|
1706
|
+
const da = new Date(a.createdAt).getTime()
|
|
1707
|
+
const db = new Date(b.createdAt).getTime()
|
|
1708
|
+
if (!Number.isNaN(da) && !Number.isNaN(db) && da !== db) return db - da
|
|
1709
|
+
return String(a.href).localeCompare(String(b.href))
|
|
1710
|
+
})
|
|
1711
|
+
|
|
1712
|
+
return { ...app, tutorials }
|
|
1713
|
+
}
|
|
1714
|
+
```
|
|
1715
|
+
|
|
1716
|
+
That's the whole plugin. It reads every page, keeps the ones under `/tutorials/`,
|
|
1717
|
+
and returns a new `app` with a sorted `tutorials` array.
|
|
1718
|
+
|
|
1719
|
+
## Use it in a layout
|
|
1720
|
+
|
|
1721
|
+
`app.tutorials` is now available in every view:
|
|
1722
|
+
|
|
1723
|
+
```pug
|
|
1724
|
+
if app.tutorials && app.tutorials.length
|
|
1725
|
+
ul.tutorials__list
|
|
1726
|
+
each post in app.tutorials
|
|
1727
|
+
li.tutorials__item
|
|
1728
|
+
a.tutorials__link(href=post.href)
|
|
1729
|
+
h2 #{ post.title }
|
|
1730
|
+
p #{ post.description }
|
|
1731
|
+
```
|
|
1732
|
+
|
|
1733
|
+
## Hand over a file with `getAssets`
|
|
1734
|
+
|
|
1735
|
+
Now publish the same list as `/tutorials.json`. Writing it into `public/` from a
|
|
1736
|
+
hook does not work: plugins run *before* core deletes and re-creates `public/`,
|
|
1737
|
+
so the file is gone by the end of the build. Write it into
|
|
1738
|
+
`.nera-cache/tutorials-list/` instead (`nera new` puts `.nera-cache` in
|
|
1739
|
+
`.gitignore`) and return it from `getAssets`. Add this to the same file:
|
|
1740
|
+
|
|
1741
|
+
```js
|
|
1742
|
+
import fs from 'fs'
|
|
1743
|
+
import path from 'path'
|
|
1744
|
+
|
|
1745
|
+
// getAppData from above stays as it is
|
|
1746
|
+
|
|
1747
|
+
export function getAssets({ app }) {
|
|
1748
|
+
if (!Array.isArray(app?.tutorials)) return []
|
|
1749
|
+
|
|
1750
|
+
const dir = path.resolve(process.cwd(), '.nera-cache/tutorials-list')
|
|
1751
|
+
const from = path.join(dir, 'tutorials.json')
|
|
1752
|
+
|
|
1753
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
1754
|
+
fs.writeFileSync(from, `${JSON.stringify(app.tutorials, null, 4)}\n`)
|
|
1755
|
+
|
|
1756
|
+
return [{ from, to: 'tutorials.json' }]
|
|
1757
|
+
}
|
|
1758
|
+
```
|
|
1759
|
+
|
|
1760
|
+
Each entry is `{ from, to }`: `from` is an **absolute** path to a file or folder,
|
|
1761
|
+
`to` a path **relative to `public/`** — the target file for a file, the folder
|
|
1762
|
+
its contents go into for a folder (`''` is `public/` itself). `getAssets` sees
|
|
1763
|
+
the final `app`, so `app.tutorials` from your own `getAppData` is already there.
|
|
1764
|
+
|
|
1765
|
+
After `nera build`, `public/tutorials.json` holds the list, newest first:
|
|
1766
|
+
|
|
1767
|
+
```json
|
|
1768
|
+
[
|
|
1769
|
+
{
|
|
1770
|
+
"href": "/tutorials/second.html",
|
|
1771
|
+
"title": "Second tutorial",
|
|
1772
|
+
"description": "The newer one.",
|
|
1773
|
+
"createdAt": "2026-08-01T00:00:00.000Z"
|
|
1774
|
+
},
|
|
1775
|
+
{
|
|
1776
|
+
"href": "/tutorials/first.html",
|
|
1777
|
+
"title": "First tutorial",
|
|
1778
|
+
"description": "The older one.",
|
|
1779
|
+
"createdAt": "2026-07-01T00:00:00.000Z"
|
|
1780
|
+
}
|
|
1781
|
+
]
|
|
1782
|
+
```
|
|
1783
|
+
|
|
1784
|
+
Core copies the files in the order theme → plugins → site, so a file of the same
|
|
1785
|
+
name in your own `theme/assets/` still wins. The copy happens before `base_path`
|
|
1786
|
+
and asset hashing, so both cover plugin files too. An entry with a relative
|
|
1787
|
+
`from` or a `to` outside `public/` is skipped with a warning, such as
|
|
1788
|
+
`⚠️ Plugin "tutorials-list" getAssets entry skipped: "from" must be an absolute
|
|
1789
|
+
path (…)`. For real-world examples, see this site's
|
|
1790
|
+
[`llms-txt`](https://github.com/seebaermichi/nera-website/tree/main/plugins/llms-txt)
|
|
1791
|
+
and [`skill-zip`](https://github.com/seebaermichi/nera-website/tree/main/plugins/skill-zip)
|
|
1792
|
+
plugins.
|
|
1793
|
+
|
|
1794
|
+
## Why return a *new* object
|
|
1795
|
+
|
|
1796
|
+
Nera threads each hook's return value into the next. Returning `{ ...app, tutorials }`
|
|
1797
|
+
(rather than mutating `app`) keeps that data flow predictable — the same reason the
|
|
1798
|
+
built-in plugins do it. From here, the same pattern builds related-posts lists,
|
|
1799
|
+
author pages, "recently updated" widgets — anything derived from your content.
|
|
1800
|
+
|
|
1801
|
+
# Reusable content blocks with plugin-stacks
|
|
1802
|
+
|
|
1803
|
+
Source: https://nera.js.org/tutorials/reusable-content-blocks.html
|
|
1804
|
+
|
|
1805
|
+
Some content belongs to no single page: a call to action under every article,
|
|
1806
|
+
a newsletter box, the feature grid on a homepage. `@nera-static/plugin-stacks`
|
|
1807
|
+
lets you write such a block once, as a Markdown file in `pages/`, and place it
|
|
1808
|
+
in any view through `app.stacks`. Several blocks that form one section become a
|
|
1809
|
+
**stack group**, ordered and split by language.
|
|
1810
|
+
|
|
1811
|
+
## 1. Install
|
|
1812
|
+
|
|
1813
|
+
```bash
|
|
1814
|
+
npm install @nera-static/plugin-stacks
|
|
1815
|
+
```
|
|
1816
|
+
|
|
1817
|
+
Nera finds the plugin on its own. It needs no config file: stacks are defined
|
|
1818
|
+
in frontmatter.
|
|
1819
|
+
|
|
1820
|
+
## 2. What makes a page a stack
|
|
1821
|
+
|
|
1822
|
+
A stack is a Markdown file under `pages/` whose frontmatter sets
|
|
1823
|
+
**`type: stack`** and a `slug` or a `title`. Where the file lives does not
|
|
1824
|
+
matter. A `pages/stacks/` folder simply keeps the blocks together:
|
|
1825
|
+
|
|
1826
|
+
```markdown:pages/stacks/newsletter.md
|
|
1827
|
+
---
|
|
1828
|
+
type: stack
|
|
1829
|
+
title: Newsletter signup
|
|
1830
|
+
---
|
|
1831
|
+
Get **one email a month** with what changed.
|
|
1832
|
+
```
|
|
1833
|
+
|
|
1834
|
+
Note what is missing: **`layout`**. Nera writes a page to `public/` only if
|
|
1835
|
+
its frontmatter has a layout, so a stack without one stays a fragment that
|
|
1836
|
+
other pages embed, not a page of its own. `nera validate` and
|
|
1837
|
+
`nera build --check` know this: since `@nera-static/validate` 1.6.1 they no
|
|
1838
|
+
longer warn `layout-missing` for a page with `type: stack`.
|
|
1839
|
+
|
|
1840
|
+
## 3. Use a single stack
|
|
1841
|
+
|
|
1842
|
+
Every stack lands in `app.stacks`, keyed by its slug, with the same
|
|
1843
|
+
`{ content, meta }` shape as a page: `content` is the rendered HTML, `meta` the
|
|
1844
|
+
whole frontmatter. Without an explicit `slug`, the key is the title lowercased,
|
|
1845
|
+
with spaces replaced by **underscores**: `Newsletter signup` becomes
|
|
1846
|
+
`newsletter_signup`.
|
|
1847
|
+
|
|
1848
|
+
Place it in a view, guarded so a missing stack does not break the page:
|
|
1849
|
+
|
|
1850
|
+
```pug:theme/views/pages/default.pug
|
|
1851
|
+
extends ../layouts/layout
|
|
1852
|
+
|
|
1853
|
+
block content
|
|
1854
|
+
main#main
|
|
1855
|
+
!= content
|
|
1856
|
+
if app.stacks.newsletter_signup
|
|
1857
|
+
aside.newsletter!= app.stacks.newsletter_signup.content
|
|
1858
|
+
```
|
|
1859
|
+
|
|
1860
|
+
The aside then holds
|
|
1861
|
+
`<p>Get <strong>one email a month</strong> with what changed.</p>`.
|
|
1862
|
+
|
|
1863
|
+
Only spaces are replaced: a title with punctuation produces a key that dot
|
|
1864
|
+
access cannot read. Set an explicit `slug` for such titles, or whenever you want
|
|
1865
|
+
a key that does not change when the title does. Slugs are one namespace for the
|
|
1866
|
+
whole site; if two stacks end up with the same one, the later one wins and the
|
|
1867
|
+
plugin warns.
|
|
1868
|
+
|
|
1869
|
+
## 4. Render a stack through a template
|
|
1870
|
+
|
|
1871
|
+
A stack can bring its own markup. Publish the plugin's default template:
|
|
1872
|
+
|
|
1873
|
+
```bash
|
|
1874
|
+
npx nera-stacks
|
|
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:
|
|
1880
|
+
|
|
1881
|
+
```markdown:pages/stacks/call-to-action.md
|
|
1882
|
+
---
|
|
1883
|
+
type: stack
|
|
1884
|
+
slug: call_to_action
|
|
1885
|
+
title: Ready to start?
|
|
1886
|
+
description: One command scaffolds a site.
|
|
1887
|
+
stack_layout: theme/views/vendor/plugin-stacks/stack-template.pug
|
|
1888
|
+
---
|
|
1889
|
+
Run `npx @nera-static/nera new my-site` and you are live in minutes.
|
|
1890
|
+
```
|
|
1891
|
+
|
|
1892
|
+
`app.stacks.call_to_action.content` now holds the template's output, not the
|
|
1893
|
+
bare Markdown:
|
|
1894
|
+
|
|
1895
|
+
```html
|
|
1896
|
+
<section class="stack">
|
|
1897
|
+
<header class="stack__header">
|
|
1898
|
+
<h2 class="stack__title">Ready to start?</h2>
|
|
1899
|
+
<p class="stack__description">One command scaffolds a site.</p>
|
|
1900
|
+
</header>
|
|
1901
|
+
<article class="stack__content">
|
|
1902
|
+
<p>Run <code>npx @nera-static/nera new my-site</code> and you are live in minutes.</p>
|
|
1903
|
+
</article>
|
|
1904
|
+
</section>
|
|
1905
|
+
```
|
|
1906
|
+
|
|
1907
|
+
The template reads the stack as `stack.meta` and `stack.content`, so you can
|
|
1908
|
+
edit your copy or write your own. The BEM classes are the plugin's public
|
|
1909
|
+
contract: style them from your CSS. Publishing skips a folder that already
|
|
1910
|
+
exists, so after a plugin update `npx nera-stacks --force` fetches the new
|
|
1911
|
+
template and overwrites your edits.
|
|
1912
|
+
|
|
1913
|
+
## 5. Stack groups
|
|
1914
|
+
|
|
1915
|
+
A feature grid is a *list* of blocks. Give each block its own stack page, put
|
|
1916
|
+
them into the same **`stack_group`**, and set their order with
|
|
1917
|
+
**`stack_order`**:
|
|
1918
|
+
|
|
1919
|
+
```markdown:pages/stacks/home-features/01-markdown.md
|
|
1920
|
+
---
|
|
1921
|
+
type: stack
|
|
1922
|
+
stack_group: home_features
|
|
1923
|
+
stack_order: 1
|
|
1924
|
+
lang: en
|
|
1925
|
+
title: Markdown in, HTML out
|
|
1926
|
+
---
|
|
1927
|
+
Author content in Markdown with YAML frontmatter.
|
|
1928
|
+
```
|
|
1929
|
+
|
|
1930
|
+
The plugin then adds two keys:
|
|
1931
|
+
|
|
1932
|
+
- **`app.stackGroups[<group>]`** — every stack of the group, in order.
|
|
1933
|
+
- **`app.stackGroupsByLang[<group>][<lang>]`** — the same, split by `lang`. A
|
|
1934
|
+
stack without `lang` counts as the site's `app.lang`.
|
|
1935
|
+
|
|
1936
|
+
Each entry is `{ content, meta }` again, so a view loops over it:
|
|
1937
|
+
|
|
1938
|
+
```pug
|
|
1939
|
+
- const features = app.stackGroupsByLang?.home_features?.[meta.lang || app.lang] || []
|
|
1940
|
+
each feature in features
|
|
1941
|
+
.feature
|
|
1942
|
+
h2.feature__title #{ feature.meta.title }
|
|
1943
|
+
.feature__body!= feature.content
|
|
1944
|
+
```
|
|
1945
|
+
|
|
1946
|
+
On a single-language site, `each feature in app.stackGroups.home_features || []`
|
|
1947
|
+
is enough.
|
|
1948
|
+
|
|
1949
|
+
Stacks with a numeric `stack_order` come first, ascending; the rest follow in
|
|
1950
|
+
build order. A grouped stack needs neither a `slug` nor a `title`, and it stays
|
|
1951
|
+
**out of `app.stacks`** unless it sets an explicit `slug`. In a test site with
|
|
1952
|
+
three grouped stacks, of which only one had a `slug: feature_plugins`,
|
|
1953
|
+
`app.stacks` held exactly that one next to the two ungrouped stacks:
|
|
1954
|
+
`call_to_action`, `feature_plugins`, `newsletter_signup`. That keeps the same
|
|
1955
|
+
section in three languages from colliding on title-derived keys.
|
|
1956
|
+
|
|
1957
|
+
## 6. A real example: this site's feature grid
|
|
1958
|
+
|
|
1959
|
+
The four boxes on the [nera.js.org homepage](https://nera.js.org/index.html) are a stack group.
|
|
1960
|
+
Each box is one file in `pages/stacks/home-features/`, with translations in
|
|
1961
|
+
`pages/de/stacks/home-features/` and `pages/es/stacks/home-features/`:
|
|
1962
|
+
|
|
1963
|
+
```markdown:pages/stacks/home-features/01-markdown.md
|
|
1964
|
+
---
|
|
1965
|
+
type: stack
|
|
1966
|
+
stack_group: home_features
|
|
1967
|
+
stack_order: 1
|
|
1968
|
+
lang: en
|
|
1969
|
+
title: Markdown in, HTML out
|
|
1970
|
+
---
|
|
1971
|
+
|
|
1972
|
+
Author content in Markdown with YAML frontmatter. Nera renders each page through a Pug layout you control and writes plain, fast HTML.
|
|
1973
|
+
```
|
|
1974
|
+
|
|
1975
|
+
The homepage view picks the boxes for the current language and numbers them
|
|
1976
|
+
from their position in the list:
|
|
1977
|
+
|
|
1978
|
+
```pug:theme/views/pages/home.pug
|
|
1979
|
+
- const features = app.stackGroupsByLang?.home_features?.[curLang] || []
|
|
1980
|
+
if features.length
|
|
1981
|
+
.home-body__grid
|
|
1982
|
+
each feature, i in features
|
|
1983
|
+
.home-body__feature
|
|
1984
|
+
p.home-body__feature-num #{ String(i + 1).padStart(2, '0') }
|
|
1985
|
+
h2.home-body__feature-title #{ feature.meta.title }
|
|
1986
|
+
.home-body__feature-desc!= feature.content
|
|
1987
|
+
```
|
|
1988
|
+
|
|
1989
|
+
`curLang` is set in the site's base layout from `meta.lang`. Adding a fifth
|
|
1990
|
+
box is one new Markdown file per language, with no change to the view.
|
|
1991
|
+
|
|
1992
|
+
## 7. Pitfall: stack pages are still pages
|
|
1993
|
+
|
|
1994
|
+
A stack has no layout, so it is never built, but it stays in the page list
|
|
1995
|
+
every other plugin sees. In a test site with stacks in `pages/stacks/`, the
|
|
1996
|
+
plugins behaved like this:
|
|
1997
|
+
|
|
1998
|
+
| plugin | sees stack pages? | what to do |
|
|
1999
|
+
|---|---|---|
|
|
2000
|
+
| `plugin-search` | no — pages without `layout` are left out of the index | nothing |
|
|
2001
|
+
| `plugin-page-pagination` | no — a page without `layout` is never a previous/next target | nothing |
|
|
2002
|
+
| `plugin-navigation` | no — it lists only the `href`s in `config/navigation.yaml` | nothing |
|
|
2003
|
+
| `plugin-statistics` | **yes** — it counts every Markdown file under `pages/` | keep the counted keys (`tags`, `category`, …) off stack pages |
|
|
2004
|
+
| `plugin-simple-page-list` | **yes** — with `page_path: /stacks`, it listed every stack with an `href` like `/stacks/newsletter.html` that was never built | keep stacks out of listed folders, or exclude them with `exclude_pages` |
|
|
2005
|
+
|
|
2006
|
+
The `exclude_pages` entries use the stack's would-be page URL:
|
|
2007
|
+
|
|
2008
|
+
```yaml:config/simple-page-list.yaml
|
|
2009
|
+
page_path: /blog
|
|
2010
|
+
exclude_pages:
|
|
2011
|
+
- /blog/newsletter.html
|
|
2012
|
+
```
|
|
2013
|
+
|
|
2014
|
+
A folder of its own, like `pages/stacks/`, is the simpler fix: no listed path
|
|
2015
|
+
matches it, so nothing needs excluding.
|
|
2016
|
+
|
|
2017
|
+
## Next
|
|
2018
|
+
|
|
2019
|
+
[How this website is built](https://nera.js.org/tutorials/how-this-site-is-built.html) shows how
|
|
2020
|
+
plugin-stacks works together with the other plugins on this site. To merge
|
|
2021
|
+
whole sections into one scrolling page instead, see
|
|
2022
|
+
[Build a one-page site](https://nera.js.org/tutorials/one-page-site.html).
|
|
2023
|
+
|
|
2024
|
+
# Add a consent banner — or none — with plugin-consent
|
|
2025
|
+
|
|
2026
|
+
Source: https://nera.js.org/tutorials/consent-banner.html
|
|
2027
|
+
|
|
2028
|
+
A consent banner asks visitors to agree before something on the site that
|
|
2029
|
+
needs their consent runs: an analytics script, a YouTube video, a map. A site
|
|
2030
|
+
that loads none of that has nothing to ask. `@nera-static/plugin-consent`
|
|
2031
|
+
covers both cases: it shows a short info notice (or nothing) on a site without
|
|
2032
|
+
such services, and a banner with a settings dialog on a site with them, and it
|
|
2033
|
+
keeps every configured script and embed inert until the visitor agrees.
|
|
2034
|
+
|
|
2035
|
+
Every command, config and output below was run in a fresh `nera new` site with
|
|
2036
|
+
plugin-consent 1.0.2 and `@nera-static/validate` 1.6.2.
|
|
2037
|
+
|
|
2038
|
+
## 1. Do you need a banner at all?
|
|
2039
|
+
|
|
2040
|
+
Start with what your site loads from other hosts. Every font, video, map or
|
|
2041
|
+
script from a third-party server sends the visitor's IP address there, and
|
|
2042
|
+
much of it sets cookies. The first option is not a banner but **not loading it
|
|
2043
|
+
from elsewhere**:
|
|
2044
|
+
|
|
2045
|
+
- serve fonts from your own site (this site's IBM Plex lives in
|
|
2046
|
+
`theme/assets/fonts/`),
|
|
2047
|
+
- serve a video file from your own host with `<video>`, or link to the video
|
|
2048
|
+
instead of embedding it,
|
|
2049
|
+
- run the statistics tool yourself, or do without one.
|
|
2050
|
+
|
|
2051
|
+
Self-hosting removes the third-party request. It does not by itself settle
|
|
2052
|
+
whether a tool that stores something on the visitor's device needs consent;
|
|
2053
|
+
that depends on what it stores and why. The background, in more depth:
|
|
2054
|
+
[Do I need a cookie banner?](https://michael-becker-berlin.de/en/blog/2026/10/do-i-need-a-cookie-banner.html)
|
|
2055
|
+
|
|
2056
|
+
If nothing is left that needs consent, you need no banner. You can still
|
|
2057
|
+
install the plugin: without a `config/consent.yaml`, or with one that lists no
|
|
2058
|
+
categories, it is in **notice mode** and renders a short notice:
|
|
2059
|
+
|
|
2060
|
+
```html
|
|
2061
|
+
<section class="nera-consent nera-consent--notice" data-consent-notice="data-consent-notice" data-consent-revision="1" aria-labelledby="nera-consent-notice-text" hidden="hidden">
|
|
2062
|
+
<p class="nera-consent__text" id="nera-consent-notice-text">This site uses only technically necessary cookies. <a class="nera-consent__link" href="/privacy.html">Privacy policy</a></p>
|
|
2063
|
+
<div class="nera-consent__actions"><button class="nera-consent__button" type="button" data-consent-dismiss="data-consent-dismiss">Got it</button></div>
|
|
2064
|
+
</section>
|
|
2065
|
+
```
|
|
2066
|
+
|
|
2067
|
+
The runtime shows it until the visitor clicks "Got it". If you do not want
|
|
2068
|
+
even that, set `notice: false`:
|
|
2069
|
+
|
|
2070
|
+
```yaml:config/consent.yaml
|
|
2071
|
+
privacy_url: /privacy.html
|
|
2072
|
+
notice: false
|
|
2073
|
+
```
|
|
2074
|
+
|
|
2075
|
+
`app.consent.mode` is then `'none'`, and the views render nothing at all. Once
|
|
2076
|
+
you add a category, `notice: false` no longer applies, and the build says so:
|
|
2077
|
+
|
|
2078
|
+
```text
|
|
2079
|
+
⚠️ plugin-consent: config/consent.yaml: ignoring notice: false, the site has categories and shows the banner
|
|
2080
|
+
```
|
|
2081
|
+
|
|
2082
|
+
## 2. Install and wire the layout
|
|
2083
|
+
|
|
2084
|
+
```bash
|
|
2085
|
+
npm install @nera-static/plugin-consent
|
|
2086
|
+
npx nera-consent-config
|
|
2087
|
+
npx nera-consent
|
|
2088
|
+
```
|
|
2089
|
+
|
|
2090
|
+
`npx nera-consent-config` copies the documented `config/consent.yaml`, every
|
|
2091
|
+
example commented out, so the site starts in notice mode. `npx nera-consent`
|
|
2092
|
+
copies the five views (`banner`, `settings`, `notice`, `head`, `embed`). On a
|
|
2093
|
+
site scaffolded with `nera new`, they land in
|
|
2094
|
+
`theme/views/vendor/plugin-consent/`. Both commands skip a file or folder that
|
|
2095
|
+
already exists; `--force` overwrites it, and your edits with it.
|
|
2096
|
+
|
|
2097
|
+
Plugins cannot touch your layout, so this is the one manual step. Add the
|
|
2098
|
+
stylesheet, the `head` view and the runtime inside `<head>`, a settings link
|
|
2099
|
+
in the footer, and the three other views at the end of `<body>`:
|
|
2100
|
+
|
|
2101
|
+
```pug:theme/views/layouts/layout.pug
|
|
2102
|
+
<!DOCTYPE html>
|
|
2103
|
+
html(lang=app.lang)
|
|
2104
|
+
head
|
|
2105
|
+
meta(charset="UTF-8")
|
|
2106
|
+
meta(name="viewport", content="width=device-width, initial-scale=1.0")
|
|
2107
|
+
title #{ meta.title } | #{ app.name }
|
|
2108
|
+
link(rel='stylesheet' href='/_nera/consent.css')
|
|
2109
|
+
include /vendor/plugin-consent/head
|
|
2110
|
+
script(src='/_nera/consent.js' defer)
|
|
2111
|
+
|
|
2112
|
+
body
|
|
2113
|
+
a.skip-link(href="#main") #{ t('skip_to_content') }
|
|
2114
|
+
block content
|
|
2115
|
+
footer
|
|
2116
|
+
a(href="/imprint.html") #{ t('imprint') }
|
|
2117
|
+
= ' · '
|
|
2118
|
+
a(href="/privacy.html") #{ t('privacy') }
|
|
2119
|
+
= ' · '
|
|
2120
|
+
a(href='/privacy.html' data-consent-open) Privacy settings
|
|
2121
|
+
include /vendor/plugin-consent/banner
|
|
2122
|
+
include /vendor/plugin-consent/settings
|
|
2123
|
+
include /vendor/plugin-consent/notice
|
|
2124
|
+
```
|
|
2125
|
+
|
|
2126
|
+
(The scaffold's other `meta` tags and its `style` block stay as they are; they
|
|
2127
|
+
are left out here.)
|
|
2128
|
+
|
|
2129
|
+
- `consent.css` and `consent.js` are copied to `public/_nera/` on every build,
|
|
2130
|
+
in every mode. The runtime needs `defer`.
|
|
2131
|
+
- `banner`, `settings` and `notice` each render only in their own mode, so
|
|
2132
|
+
include all three.
|
|
2133
|
+
- Any element with `data-consent-open` opens the settings dialog, where the
|
|
2134
|
+
visitor can change or withdraw a choice at any time. On a link, the `href` is
|
|
2135
|
+
the fallback for a page without the dialog or without JavaScript.
|
|
2136
|
+
|
|
2137
|
+
The plugin needs `@nera-static/core` 4.13.0 or later, which every current
|
|
2138
|
+
`@nera-static/nera` brings.
|
|
2139
|
+
|
|
2140
|
+
## 3. Gate a YouTube embed
|
|
2141
|
+
|
|
2142
|
+
Paste the embed code into a page as usual:
|
|
2143
|
+
|
|
2144
|
+
```markdown:pages/video.md
|
|
2145
|
+
---
|
|
2146
|
+
layout: pages/default.pug
|
|
2147
|
+
title: Our video
|
|
2148
|
+
description: A page with an embedded video
|
|
2149
|
+
---
|
|
2150
|
+
# Our video
|
|
2151
|
+
|
|
2152
|
+
<iframe src="https://www.youtube-nocookie.com/embed/abc123" title="Our video" width="560" height="315" allowfullscreen></iframe>
|
|
2153
|
+
```
|
|
2154
|
+
|
|
2155
|
+
Then describe the service in `config/consent.yaml`, in one category:
|
|
2156
|
+
|
|
2157
|
+
```yaml:config/consent.yaml
|
|
2158
|
+
revision: 1
|
|
2159
|
+
privacy_url: /privacy.html
|
|
2160
|
+
|
|
2161
|
+
categories:
|
|
2162
|
+
- id: media
|
|
2163
|
+
services:
|
|
2164
|
+
- name: YouTube
|
|
2165
|
+
provider: Google Ireland Limited, Dublin
|
|
2166
|
+
purpose: Shows embedded videos.
|
|
2167
|
+
privacy_url: https://policies.google.com/privacy
|
|
2168
|
+
hosts: [youtube.com, youtube-nocookie.com]
|
|
2169
|
+
cookies:
|
|
2170
|
+
- name: VISITOR_INFO1_LIVE
|
|
2171
|
+
duration: 6 months
|
|
2172
|
+
purpose: Estimates the visitor's bandwidth.
|
|
2173
|
+
```
|
|
2174
|
+
|
|
2175
|
+
- `id: media` is one of four ids with a built-in label and description in
|
|
2176
|
+
English and German (`analytics`, `media`, `marketing`, `functional`); any
|
|
2177
|
+
other id needs a `label`.
|
|
2178
|
+
- `name`, `provider` and `purpose` are required; a service without them is
|
|
2179
|
+
dropped with a warning.
|
|
2180
|
+
- `hosts` are bare host names. An `<iframe>` whose `src` host equals one of them
|
|
2181
|
+
or is a subdomain of it is gated: `www.youtube-nocookie.com` matches
|
|
2182
|
+
`youtube-nocookie.com`.
|
|
2183
|
+
- `cookies` are listed in the settings dialog. The entry above is an example:
|
|
2184
|
+
list what the provider documents.
|
|
2185
|
+
|
|
2186
|
+
With a category configured, the site is in banner mode. After `nera build`,
|
|
2187
|
+
the iframe in `public/video.html` has no `src` left; its URL moved to
|
|
2188
|
+
`data-consent-src`, and a placeholder follows it:
|
|
2189
|
+
|
|
2190
|
+
```html
|
|
2191
|
+
<div class="nera-consent-embed" data-consent-embed data-consent="media"><iframe data-consent="media" data-consent-src="https://www.youtube-nocookie.com/embed/abc123" title="Our video" width="560" height="315" allowfullscreen hidden></iframe>
|
|
2192
|
+
<div class="nera-consent-embed__placeholder">
|
|
2193
|
+
<p class="nera-consent-embed__text">This content is provided by YouTube. Loading it connects to <strong>Google Ireland Limited, Dublin</strong>.</p><button class="nera-consent-embed__load" type="button" data-consent-load>Load YouTube</button><a class="nera-consent-embed__privacy" href="https://policies.google.com/privacy" rel="noopener">Privacy policy of the provider</a><button class="nera-consent-embed__settings" type="button" data-consent-open>Privacy settings</button>
|
|
2194
|
+
</div>
|
|
2195
|
+
</div>
|
|
2196
|
+
```
|
|
2197
|
+
|
|
2198
|
+
In a browser, the test page made no request to another host until a click.
|
|
2199
|
+
"Load YouTube" loaded this one embed and stored nothing; "Accept all" in the
|
|
2200
|
+
banner stored the choice and loaded every gated element. The banner itself
|
|
2201
|
+
puts Accept all, Reject all and Settings on the first layer, in that fixed
|
|
2202
|
+
order and one shared style:
|
|
2203
|
+
|
|
2204
|
+
```html
|
|
2205
|
+
<section class="nera-consent" data-consent-banner="data-consent-banner" data-consent-revision="1" data-consent-categories="media" aria-labelledby="nera-consent-title" hidden="hidden">
|
|
2206
|
+
<h2 class="nera-consent__title" id="nera-consent-title">Cookies and external content</h2>
|
|
2207
|
+
<p class="nera-consent__text">This site can load content and services from third parties. They only load if you agree. You can change your choice at any time in the settings. <a class="nera-consent__link" href="/privacy.html">Privacy policy</a></p>
|
|
2208
|
+
<div class="nera-consent__actions"><button class="nera-consent__button" type="button" data-consent-accept-all="data-consent-accept-all">Accept all</button><button class="nera-consent__button" type="button" data-consent-reject-all="data-consent-reject-all">Reject all</button><button class="nera-consent__button" type="button" data-consent-open="data-consent-open">Settings</button></div>
|
|
2209
|
+
</section>
|
|
2210
|
+
```
|
|
2211
|
+
|
|
2212
|
+
`<embed>`, `<object>`, `<video>` and `<audio>` from a configured host are
|
|
2213
|
+
gated the same way. Two places the build does not reach:
|
|
2214
|
+
|
|
2215
|
+
- An iframe written directly into a **Pug view** is not rewritten. Use the
|
|
2216
|
+
mixin from the published `embed` view there; it renders the same
|
|
2217
|
+
placeholder:
|
|
2218
|
+
|
|
2219
|
+
```pug
|
|
2220
|
+
include /vendor/plugin-consent/embed
|
|
2221
|
+
|
|
2222
|
+
+consent-embed({
|
|
2223
|
+
category: 'media',
|
|
2224
|
+
service: 'YouTube',
|
|
2225
|
+
src: 'https://www.youtube-nocookie.com/embed/abc123',
|
|
2226
|
+
attributes: { title: 'Our video', width: 560, height: 315, allowfullscreen: true },
|
|
2227
|
+
})
|
|
2228
|
+
```
|
|
2229
|
+
|
|
2230
|
+
`category` and `service` must name a configured service, or the build fails
|
|
2231
|
+
rather than render a live iframe.
|
|
2232
|
+
- A gated `<video>`, `<audio>` or `<embed>` written inline in a Markdown
|
|
2233
|
+
paragraph ends up inside a `<p>`, which the browser splits around the
|
|
2234
|
+
placeholder. Put its opening tag alone on a line, after a blank line.
|
|
2235
|
+
|
|
2236
|
+
## 4. Gate an analytics script
|
|
2237
|
+
|
|
2238
|
+
A script you configure under a service's `scripts` is emitted by the `head`
|
|
2239
|
+
view, inert. Add a second category:
|
|
2240
|
+
|
|
2241
|
+
```yaml:config/consent.yaml
|
|
2242
|
+
revision: 2
|
|
2243
|
+
privacy_url: /privacy.html
|
|
2244
|
+
|
|
2245
|
+
categories:
|
|
2246
|
+
- id: media
|
|
2247
|
+
# … YouTube as above
|
|
2248
|
+
- id: analytics
|
|
2249
|
+
services:
|
|
2250
|
+
- name: Matomo
|
|
2251
|
+
provider: Example GmbH, Berlin
|
|
2252
|
+
purpose: Counts visits without profiles.
|
|
2253
|
+
cookies:
|
|
2254
|
+
- name: _pk_id
|
|
2255
|
+
duration: 13 months
|
|
2256
|
+
purpose: Recognises returning visitors.
|
|
2257
|
+
scripts:
|
|
2258
|
+
- inline: |
|
|
2259
|
+
var _paq = window._paq = window._paq || [];
|
|
2260
|
+
_paq.push(['trackPageView']);
|
|
2261
|
+
- src: https://matomo.example.com/matomo.js
|
|
2262
|
+
async: true
|
|
2263
|
+
```
|
|
2264
|
+
|
|
2265
|
+
Each script entry has exactly one of `src` and `inline`. In the built `<head>`,
|
|
2266
|
+
both are `type="text/plain"`, which the browser does not run, and the URL sits
|
|
2267
|
+
in `data-src`:
|
|
2268
|
+
|
|
2269
|
+
```html
|
|
2270
|
+
<link rel="stylesheet" href="/_nera/consent.css" />
|
|
2271
|
+
<script type="text/plain" data-consent="analytics">var _paq = window._paq = window._paq || [];
|
|
2272
|
+
_paq.push(['trackPageView']);
|
|
2273
|
+
</script>
|
|
2274
|
+
<script type="text/plain" data-consent="analytics" data-src="https://matomo.example.com/matomo.js" async="async"></script>
|
|
2275
|
+
<script src="/_nera/consent.js" defer="defer"></script>
|
|
2276
|
+
```
|
|
2277
|
+
|
|
2278
|
+
Once the visitor grants `analytics`, the runtime activates them in document
|
|
2279
|
+
order. In the test site, `matomo.example.com/matomo.js` was requested only
|
|
2280
|
+
after "Accept all".
|
|
2281
|
+
|
|
2282
|
+
You can write the same form **by hand**, in a view or right in a page's
|
|
2283
|
+
Markdown; the runtime treats it alike:
|
|
2284
|
+
|
|
2285
|
+
```html
|
|
2286
|
+
<script type="text/plain" data-consent="analytics" data-src="https://stats.example.org/counter.js" defer></script>
|
|
2287
|
+
```
|
|
2288
|
+
|
|
2289
|
+
`data-consent` names the category, `data-src` holds the URL, and every other
|
|
2290
|
+
attribute (`async`, `defer`, `integrity`, …) is copied to the activated script.
|
|
2291
|
+
|
|
2292
|
+
Note **`revision: 2`**. A visitor's stored choice carries the revision it was
|
|
2293
|
+
made under; when the built revision is higher, the banner shows again. Adding
|
|
2294
|
+
a service or a category to a site that already shows the banner does not ask
|
|
2295
|
+
returning visitors again by itself, so bump `revision` whenever you do. In the
|
|
2296
|
+
test site, a choice stored under revision 2 brought the banner back as soon as
|
|
2297
|
+
the site was rebuilt with `revision: 3`.
|
|
2298
|
+
|
|
2299
|
+
Withdrawal in the settings dialog is stored at once but takes effect from the
|
|
2300
|
+
next page load: a script that already ran cannot be unloaded.
|
|
2301
|
+
|
|
2302
|
+
## 5. List your services on the privacy page
|
|
2303
|
+
|
|
2304
|
+
Your privacy page should name the services you use. The plugin puts them into
|
|
2305
|
+
`app.consent`, per language under `app.consent.locales`, with the texts already
|
|
2306
|
+
resolved. Give the privacy page its own view:
|
|
2307
|
+
|
|
2308
|
+
```pug:theme/views/pages/privacy.pug
|
|
2309
|
+
extends ../layouts/layout
|
|
2310
|
+
|
|
2311
|
+
block content
|
|
2312
|
+
main#main
|
|
2313
|
+
!= content
|
|
2314
|
+
- const consentLocale = app.consent.locales[meta.lang || app.lang] || app.consent.locales.en
|
|
2315
|
+
each category in consentLocale.categories
|
|
2316
|
+
h2= category.label
|
|
2317
|
+
each service in category.services
|
|
2318
|
+
h3= service.name
|
|
2319
|
+
p #{service.provider}: #{service.purpose}
|
|
2320
|
+
if service.privacyUrl
|
|
2321
|
+
p
|
|
2322
|
+
a(href=service.privacyUrl rel='noopener') #{consentLocale.texts.service_privacy}
|
|
2323
|
+
if service.cookies.length
|
|
2324
|
+
table
|
|
2325
|
+
thead
|
|
2326
|
+
tr
|
|
2327
|
+
th(scope='col')= consentLocale.texts.cookie_name
|
|
2328
|
+
th(scope='col')= consentLocale.texts.cookie_duration
|
|
2329
|
+
th(scope='col')= consentLocale.texts.cookie_purpose
|
|
2330
|
+
tbody
|
|
2331
|
+
each cookie in service.cookies
|
|
2332
|
+
tr
|
|
2333
|
+
td= cookie.name
|
|
2334
|
+
td= cookie.duration
|
|
2335
|
+
td= cookie.purpose
|
|
2336
|
+
```
|
|
2337
|
+
|
|
2338
|
+
and point `pages/privacy.md` at it with `layout: pages/privacy.pug`. The table
|
|
2339
|
+
then comes from the same config as the banner and cannot drift from it:
|
|
2340
|
+
|
|
2341
|
+
```html
|
|
2342
|
+
<h2>External media</h2>
|
|
2343
|
+
<h3>YouTube</h3>
|
|
2344
|
+
<p>Google Ireland Limited, Dublin: Shows embedded videos.</p>
|
|
2345
|
+
<p><a href="https://policies.google.com/privacy" rel="noopener">Privacy policy of the provider</a></p>
|
|
2346
|
+
<table>
|
|
2347
|
+
<thead>
|
|
2348
|
+
<tr>
|
|
2349
|
+
<th scope="col">Name</th>
|
|
2350
|
+
<th scope="col">Duration</th>
|
|
2351
|
+
<th scope="col">Purpose</th>
|
|
2352
|
+
</tr>
|
|
2353
|
+
</thead>
|
|
2354
|
+
<tbody>
|
|
2355
|
+
<tr>
|
|
2356
|
+
<td>VISITOR_INFO1_LIVE</td>
|
|
2357
|
+
<td>6 months</td>
|
|
2358
|
+
<td>Estimates the visitor's bandwidth.</td>
|
|
2359
|
+
</tr>
|
|
2360
|
+
</tbody>
|
|
2361
|
+
</table>
|
|
2362
|
+
<h2>Statistics</h2>
|
|
2363
|
+
…
|
|
2364
|
+
```
|
|
2365
|
+
|
|
2366
|
+
The rest of the privacy policy, who you are, what your host logs, the
|
|
2367
|
+
visitor's rights, is still yours to write.
|
|
2368
|
+
|
|
2369
|
+
## 6. Theme and translate
|
|
2370
|
+
|
|
2371
|
+
Every color and size of banner, dialog and placeholder is a `--nera-consent-*`
|
|
2372
|
+
custom property, so your own stylesheet can set them anywhere:
|
|
2373
|
+
|
|
2374
|
+
```css:theme/assets/css/site.css
|
|
2375
|
+
:root {
|
|
2376
|
+
--nera-consent-font: system-ui, sans-serif;
|
|
2377
|
+
--nera-consent-bg: #fffbeb;
|
|
2378
|
+
--nera-consent-fg: #1c1917;
|
|
2379
|
+
--nera-consent-button-bg: #92400e;
|
|
2380
|
+
--nera-consent-button-fg: #ffffff;
|
|
2381
|
+
--nera-consent-radius: 0;
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
@media (prefers-color-scheme: dark) {
|
|
2385
|
+
:root {
|
|
2386
|
+
--nera-consent-bg: #1c1917;
|
|
2387
|
+
--nera-consent-fg: #fafaf9;
|
|
2388
|
+
--nera-consent-button-bg: #fbbf24;
|
|
2389
|
+
--nera-consent-button-fg: #1c1917;
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
```
|
|
2393
|
+
|
|
2394
|
+
Link it in the layout (`link(rel='stylesheet' href='/css/site.css')`). The
|
|
2395
|
+
plugin's README has the full table of properties. Accept all, Reject all and
|
|
2396
|
+
Settings share one set of button properties on purpose: there is no way to
|
|
2397
|
+
make one of them stand out. The defaults reach a contrast of at least 4.5:1;
|
|
2398
|
+
keep that when you change them.
|
|
2399
|
+
|
|
2400
|
+
The texts come in English and German. Every text resolves per page language
|
|
2401
|
+
(`meta.lang || app.lang`), first hit wins: `texts.<lang>` in
|
|
2402
|
+
`config/consent.yaml`, then `consent.<key>` in your `app.translations`, then
|
|
2403
|
+
the built-in text. A Spanish page, for example:
|
|
2404
|
+
|
|
2405
|
+
```yaml:config/consent.yaml
|
|
2406
|
+
texts:
|
|
2407
|
+
es:
|
|
2408
|
+
banner_title: Cookies y contenido externo
|
|
2409
|
+
accept_all: Aceptar todo
|
|
2410
|
+
reject_all: Rechazar todo
|
|
2411
|
+
settings: Ajustes
|
|
2412
|
+
```
|
|
2413
|
+
|
|
2414
|
+
or, next to your other translations:
|
|
2415
|
+
|
|
2416
|
+
```yaml:config/app.yaml
|
|
2417
|
+
translations:
|
|
2418
|
+
es:
|
|
2419
|
+
consent.placeholder_load: Cargar {service}
|
|
2420
|
+
consent.banner_text: Este sitio puede cargar contenido y servicios de terceros. Solo se cargan si das tu consentimiento.
|
|
2421
|
+
```
|
|
2422
|
+
|
|
2423
|
+
A key you do not translate falls back to English: on the Spanish test page,
|
|
2424
|
+
the banner's privacy link still read "Privacy policy". The README lists every
|
|
2425
|
+
key. A category's `label` and `description`, and a service's `purpose`, take
|
|
2426
|
+
one text per language the same way:
|
|
2427
|
+
|
|
2428
|
+
```yaml
|
|
2429
|
+
- id: analytics
|
|
2430
|
+
label:
|
|
2431
|
+
en: Statistics
|
|
2432
|
+
es: Estadísticas
|
|
2433
|
+
```
|
|
2434
|
+
|
|
2435
|
+
## 7. What `nera build --check` reports
|
|
2436
|
+
|
|
2437
|
+
`nera build --check` checks the built `public/` for privacy problems, among
|
|
2438
|
+
others. The output below is from `@nera-static/validate` 1.6.2, the version
|
|
2439
|
+
`@nera-static/nera` 1.17.0 brings. Later releases may report gated markup
|
|
2440
|
+
differently.
|
|
2441
|
+
|
|
2442
|
+
**Before gating**, with the plain iframe in `pages/video.md`, no categories,
|
|
2443
|
+
and the analytics script as a plain tag in the layout's `head`:
|
|
2444
|
+
|
|
2445
|
+
```pug
|
|
2446
|
+
script(src='https://matomo.example.com/matomo.js' async)
|
|
2447
|
+
```
|
|
2448
|
+
|
|
2449
|
+
`privacy-third-party` reports both:
|
|
2450
|
+
|
|
2451
|
+
```text
|
|
2452
|
+
public/imprint.html
|
|
2453
|
+
:24 warning loads matomo.example.com — a third-party request that sends the visitor's IP address; self-host the resource, gate the element with `data-consent` (the markup of @nera-static/plugin-consent) so it loads only after the visitor agrees, or name the host in the privacy policy and list the host under `privacy.allowed_hosts` in config/validate.yaml once it is accounted for (Art. 6 DSGVO) (on 4 pages, e.g. public/imprint.html, public/index.html, public/privacy.html, …) privacy-third-party
|
|
2454
|
+
public/video.html
|
|
2455
|
+
:30 warning loads a YouTube embed from www.youtube-nocookie.com — a third-party request that sends the visitor's IP address; consider a click-to-load placeholder (Art. 6 DSGVO, § 25 TDDDG), e.g. gate the element with `data-consent` (the markup of @nera-static/plugin-consent), or list the host under `privacy.allowed_hosts` in config/validate.yaml once it is accounted for
|
|
2456
|
+
|
|
2457
|
+
0 error(s), 2 warning(s)
|
|
2458
|
+
```
|
|
2459
|
+
|
|
2460
|
+
The hint "gate the element with `data-consent`" appears when a host's first
|
|
2461
|
+
use in a file is an element the plugin can gate: a script, iframe, embed,
|
|
2462
|
+
object, video or audio. Images, `<link>`s and CSS keep the plain message.
|
|
2463
|
+
|
|
2464
|
+
**After gating**, with the config from steps 3 and 4 and the hand-written tag
|
|
2465
|
+
in `pages/stats.md`:
|
|
2466
|
+
|
|
2467
|
+
```text
|
|
2468
|
+
✓ No problems found.
|
|
2469
|
+
```
|
|
2470
|
+
|
|
2471
|
+
Validate does not read a `<script>` whose `type` is not JavaScript as a
|
|
2472
|
+
resource, and an iframe or media element with `data-consent` and only
|
|
2473
|
+
`data-consent-*` loading attributes loads nothing, so the gated markup gives
|
|
2474
|
+
no `privacy-third-party` finding.
|
|
2475
|
+
|
|
2476
|
+
**A tag that is marked but still loads** is what `privacy-consent-leak`
|
|
2477
|
+
reports. Leave out `type="text/plain"` and keep `src` in the hand-written tag:
|
|
2478
|
+
|
|
2479
|
+
```html:pages/stats.md
|
|
2480
|
+
<script data-consent="analytics" src="https://stats.example.org/counter.js" defer></script>
|
|
2481
|
+
```
|
|
2482
|
+
|
|
2483
|
+
and the check finds it twice:
|
|
2484
|
+
|
|
2485
|
+
```text
|
|
2486
|
+
public/stats.html
|
|
2487
|
+
:33 warning loads stats.example.org — a third-party request that sends the visitor's IP address; self-host the resource, gate the element with `data-consent` (the markup of @nera-static/plugin-consent) so it loads only after the visitor agrees, or name the host in the privacy policy and list the host under `privacy.allowed_hosts` in config/validate.yaml once it is accounted for (Art. 6 DSGVO) privacy-third-party
|
|
2488
|
+
:33 warning `<script data-consent="analytics" src="https://stats.example.org/counter.js">` is marked `data-consent` but runs as JavaScript — the browser runs it before the visitor agrees; set `type="text/plain"`, rename `src` to `data-src`, as in the markup of @nera-static/plugin-consent (§ 25 TDDDG) privacy-consent-leak
|
|
2489
|
+
|
|
2490
|
+
0 error(s), 2 warning(s)
|
|
2491
|
+
```
|
|
2492
|
+
|
|
2493
|
+
Both are warnings, so the build still succeeds. To fail it, promote the rule
|
|
2494
|
+
in `config/validate.yaml`:
|
|
2495
|
+
|
|
2496
|
+
```yaml:config/validate.yaml
|
|
2497
|
+
rules:
|
|
2498
|
+
privacy-consent-leak: error
|
|
2499
|
+
```
|
|
2500
|
+
|
|
2501
|
+
`privacy-consent-leak: off` switches it off. The check sees only the built
|
|
2502
|
+
HTML: it cannot tell whether your privacy policy names a service, or whether a
|
|
2503
|
+
service needs consent in the first place.
|
|
2504
|
+
|
|
2505
|
+
## Defaults, not legal advice
|
|
2506
|
+
|
|
2507
|
+
The plugin's texts and behaviour are **defaults, not legal advice**, and
|
|
2508
|
+
nothing here makes a site compliant with any law. What the plugin does is
|
|
2509
|
+
technical, and it holds whatever the config says:
|
|
2510
|
+
|
|
2511
|
+
1. The banner and dialog name each configured service, its provider and
|
|
2512
|
+
purpose, so the consent can be informed and specific (Art. 4 Nr. 11,
|
|
2513
|
+
Art. 7 DSGVO).
|
|
2514
|
+
2. "Reject all" is on the first layer, as visible and as easy to use as
|
|
2515
|
+
"Accept all".
|
|
2516
|
+
3. Nothing is pre-selected; "necessary" is implicit and cannot be configured.
|
|
2517
|
+
4. Nothing gated runs or loads before consent (§ 25 (1) TDDDG).
|
|
2518
|
+
5. Consent can be withdrawn at any time through the settings link, without a
|
|
2519
|
+
rebuild.
|
|
2520
|
+
6. A `revision` bump asks every visitor again.
|
|
2521
|
+
7. Storing the visitor's choice (in `localStorage`, under `nera-consent`) is
|
|
2522
|
+
strictly necessary and needs no consent (§ 25 (2) Nr. 2 TDDDG).
|
|
2523
|
+
|
|
2524
|
+
Whether your site needs consent, which services you list and what your banner
|
|
2525
|
+
and privacy policy say are your decisions. Check them yourself, or with
|
|
2526
|
+
someone qualified to advise you. The plugin's
|
|
2527
|
+
[README](https://github.com/seebaermichi/nera-plugin-consent#readme) and
|
|
2528
|
+
[npm page](https://www.npmjs.com/package/@nera-static/plugin-consent) have the
|
|
2529
|
+
full config reference, the markup contract and the known limitations.
|
|
2530
|
+
|
|
2531
|
+
## Next
|
|
2532
|
+
|
|
2533
|
+
[How this website is built](https://nera.js.org/tutorials/how-this-site-is-built.html) shows the
|
|
2534
|
+
plugins of this site working together. nera.js.org itself loads nothing from
|
|
2535
|
+
another host, so it shows no banner.
|
|
2536
|
+
|
|
2537
|
+
# Build a one-page site
|
|
2538
|
+
|
|
2539
|
+
Source: https://nera.js.org/tutorials/one-page-site.html
|
|
2540
|
+
|
|
2541
|
+
A freelancer or a small business often needs one page, not a site: a hero, the
|
|
2542
|
+
services, a few words about who you are, and a way to get in touch, all on one
|
|
2543
|
+
scrolling page. In this tutorial you build that page with each section in its
|
|
2544
|
+
own Markdown file. `@nera-static/plugin-one-page` merges the sections into the
|
|
2545
|
+
home page, `@nera-static/plugin-page-navigation` adds the in-page links,
|
|
2546
|
+
`@nera-static/plugin-contact-form` adds a contact form without a backend, and
|
|
2547
|
+
`@nera-static/plugin-social-media-links` puts your profiles in the footer.
|
|
2548
|
+
|
|
2549
|
+
Want a finished business site to edit instead? The business starter sets one up
|
|
2550
|
+
with a theme, sample pages for services, about, opening hours and contact, a
|
|
2551
|
+
contact form and social links:
|
|
2552
|
+
|
|
2553
|
+
```bash
|
|
2554
|
+
npx @nera-static/nera new my-site --starter business
|
|
2555
|
+
```
|
|
2556
|
+
|
|
2557
|
+
Its files won't match the steps below: the starter builds a site of several
|
|
2558
|
+
pages, while this tutorial builds a single page by hand, to show how the pieces
|
|
2559
|
+
fit together.
|
|
2560
|
+
|
|
2561
|
+
## 1. Scaffold and install
|
|
2562
|
+
|
|
2563
|
+
```bash
|
|
2564
|
+
npx @nera-static/nera new my-site
|
|
2565
|
+
cd my-site
|
|
2566
|
+
npm install @nera-static/plugin-one-page @nera-static/plugin-page-navigation \
|
|
2567
|
+
@nera-static/plugin-contact-form @nera-static/plugin-social-media-links
|
|
2568
|
+
```
|
|
2569
|
+
|
|
2570
|
+
Nera finds all four plugins on its own. Three of them ship templates. Publish
|
|
2571
|
+
them into your views folder, where they are yours to edit:
|
|
2572
|
+
|
|
2573
|
+
```bash
|
|
2574
|
+
npx nera-page-navigation
|
|
2575
|
+
npx nera-contact-form
|
|
2576
|
+
npx nera-social-media-links
|
|
2577
|
+
```
|
|
2578
|
+
|
|
2579
|
+
On a `nera new` site they land in `theme/views/vendor/plugin-<name>/`, and the
|
|
2580
|
+
contact form's client script in `theme/assets/js/contact-form.js`.
|
|
2581
|
+
`plugin-one-page` ships no template and needs no config file.
|
|
2582
|
+
|
|
2583
|
+
## 2. The target page
|
|
2584
|
+
|
|
2585
|
+
The page the sections are merged into is an ordinary page. Here it is the home
|
|
2586
|
+
page, and its own content is the hero:
|
|
2587
|
+
|
|
2588
|
+
```markdown:pages/index.md
|
|
2589
|
+
---
|
|
2590
|
+
layout: pages/one-page.pug
|
|
2591
|
+
title: Studio Lena
|
|
2592
|
+
description: Web design for small businesses in Berlin
|
|
2593
|
+
---
|
|
2594
|
+
# Websites for small businesses
|
|
2595
|
+
|
|
2596
|
+
I design and build fast, simple websites for shops, studios and practices.
|
|
2597
|
+
```
|
|
2598
|
+
|
|
2599
|
+
Give it a template of its own. It grows in the next steps; for now it renders
|
|
2600
|
+
the content:
|
|
2601
|
+
|
|
2602
|
+
```pug:theme/views/pages/one-page.pug
|
|
2603
|
+
extends ../layouts/layout
|
|
2604
|
+
|
|
2605
|
+
block content
|
|
2606
|
+
main#main
|
|
2607
|
+
!= content
|
|
2608
|
+
```
|
|
2609
|
+
|
|
2610
|
+
## 3. One file per section
|
|
2611
|
+
|
|
2612
|
+
Each section is a Markdown file that names its target page in
|
|
2613
|
+
**`add_to_page`** and its position in **`add_to_page_order`**. Keep them
|
|
2614
|
+
together in `pages/sections/`:
|
|
2615
|
+
|
|
2616
|
+
```markdown:pages/sections/services.md
|
|
2617
|
+
---
|
|
2618
|
+
title: Services
|
|
2619
|
+
add_to_page: /index.html
|
|
2620
|
+
add_to_page_order: 1
|
|
2621
|
+
anchor_id: services
|
|
2622
|
+
content_wrapper_attributes:
|
|
2623
|
+
class: section section--services
|
|
2624
|
+
---
|
|
2625
|
+
## Services
|
|
2626
|
+
|
|
2627
|
+
- **New websites**: from the first sketch to the live site.
|
|
2628
|
+
- **Redesigns**: a fresh look for the site you already have.
|
|
2629
|
+
- **Care plans**: updates and small changes every month.
|
|
2630
|
+
```
|
|
2631
|
+
|
|
2632
|
+
```markdown:pages/sections/about.md
|
|
2633
|
+
---
|
|
2634
|
+
title: About
|
|
2635
|
+
add_to_page: /index.html
|
|
2636
|
+
add_to_page_order: 2
|
|
2637
|
+
anchor_id: about
|
|
2638
|
+
content_wrapper_attributes:
|
|
2639
|
+
class: section section--about
|
|
2640
|
+
---
|
|
2641
|
+
## About
|
|
2642
|
+
|
|
2643
|
+
I'm Lena, a web designer in Berlin. I have built sites for small businesses
|
|
2644
|
+
since 2015.
|
|
2645
|
+
```
|
|
2646
|
+
|
|
2647
|
+
```markdown:pages/sections/contact.md
|
|
2648
|
+
---
|
|
2649
|
+
title: Contact
|
|
2650
|
+
add_to_page: /index.html
|
|
2651
|
+
add_to_page_order: 3
|
|
2652
|
+
anchor_id: contact
|
|
2653
|
+
content_wrapper_attributes:
|
|
2654
|
+
class: section section--contact
|
|
2655
|
+
---
|
|
2656
|
+
## Contact
|
|
2657
|
+
|
|
2658
|
+
Tell me about your project. The form opens your own email program with the
|
|
2659
|
+
message ready to send.
|
|
2660
|
+
```
|
|
2661
|
+
|
|
2662
|
+
Run `npx nera build`. Until step 7 it also warns that `plugin-contact-form` has
|
|
2663
|
+
no `recipient` configured; the form simply does not render yet.
|
|
2664
|
+
`public/index.html` now holds the hero followed by the three sections, in their
|
|
2665
|
+
order (shortened):
|
|
2666
|
+
|
|
2667
|
+
```html
|
|
2668
|
+
<main id="main">
|
|
2669
|
+
<h1>Websites for small businesses</h1>
|
|
2670
|
+
<p>I design and build fast, simple websites for shops, studios and practices.</p>
|
|
2671
|
+
|
|
2672
|
+
|
|
2673
|
+
<section class="section section--services">
|
|
2674
|
+
<a id="services"></a>
|
|
2675
|
+
<h2>Services</h2>
|
|
2676
|
+
<ul>
|
|
2677
|
+
<li><strong>New websites</strong>: from the first sketch to the live site.</li>
|
|
2678
|
+
…
|
|
2679
|
+
</ul>
|
|
2680
|
+
|
|
2681
|
+
</section>
|
|
2682
|
+
|
|
2683
|
+
<section class="section section--about">
|
|
2684
|
+
<a id="about"></a>
|
|
2685
|
+
<h2>About</h2>
|
|
2686
|
+
…
|
|
2687
|
+
</section>
|
|
2688
|
+
|
|
2689
|
+
<section class="section section--contact">
|
|
2690
|
+
<a id="contact"></a>
|
|
2691
|
+
<h2>Contact</h2>
|
|
2692
|
+
…
|
|
2693
|
+
</section>
|
|
2694
|
+
</main>
|
|
2695
|
+
```
|
|
2696
|
+
|
|
2697
|
+
The sections are always **appended after the target page's own content**.
|
|
2698
|
+
Each one is wrapped in a `<section>`; `content_wrapper_tag` sets another
|
|
2699
|
+
element, and `content_wrapper_tag: ''` drops the wrapper. The wrapper
|
|
2700
|
+
attributes are a plain mapping or a list of `{ attribute, value }` entries, and
|
|
2701
|
+
their values are HTML-escaped. Quote a value that contains `: `:
|
|
2702
|
+
|
|
2703
|
+
```yaml
|
|
2704
|
+
content_wrapper_attributes:
|
|
2705
|
+
style: 'background-color: #f5f5f5;'
|
|
2706
|
+
```
|
|
2707
|
+
|
|
2708
|
+
Unquoted, the frontmatter does not parse: the build logs
|
|
2709
|
+
`❌ Failed to process page …: Nested mappings are not allowed in compact
|
|
2710
|
+
mappings …`, drops the page and still exits 0. `nera validate` reports it as a
|
|
2711
|
+
`yaml-parse` error.
|
|
2712
|
+
|
|
2713
|
+
### `add_to_page` must match exactly
|
|
2714
|
+
|
|
2715
|
+
`add_to_page` is compared literally with the target page's `href`, which always
|
|
2716
|
+
starts with `/` and ends in `.html`: `pages/index.md` is `/index.html`,
|
|
2717
|
+
`pages/de/index.md` is `/de/index.html`. With `add_to_page: index.html` nothing
|
|
2718
|
+
is merged, and the build says so:
|
|
2719
|
+
|
|
2720
|
+
```text
|
|
2721
|
+
⚠️ one-page: no page has href "index.html" — 1 section(s) targeting it were not merged. `add_to_page` must match a page's href exactly, e.g. "/index.html" for pages/index.md
|
|
2722
|
+
```
|
|
2723
|
+
|
|
2724
|
+
## 4. Anchors
|
|
2725
|
+
|
|
2726
|
+
Each section gets an empty `<a id="…">` in front of its content, so
|
|
2727
|
+
`/index.html#services` jumps to it. **`anchor_id`** sets the id. Without it,
|
|
2728
|
+
the plugin derives one from the section's first **`<h1>`**, slugified:
|
|
2729
|
+
lowercase, accents removed, everything else turned into `-`. This section has
|
|
2730
|
+
no `anchor_id`:
|
|
2731
|
+
|
|
2732
|
+
```markdown:pages/sections/team.md
|
|
2733
|
+
---
|
|
2734
|
+
title: Team
|
|
2735
|
+
add_to_page: /index.html
|
|
2736
|
+
add_to_page_order: 4
|
|
2737
|
+
---
|
|
2738
|
+
# Über uns
|
|
2739
|
+
|
|
2740
|
+
Zwei Leute, ein Studio.
|
|
2741
|
+
```
|
|
2742
|
+
|
|
2743
|
+
It is merged as:
|
|
2744
|
+
|
|
2745
|
+
```html
|
|
2746
|
+
<section>
|
|
2747
|
+
<a id="uber-uns"></a>
|
|
2748
|
+
<h1>Über uns</h1>
|
|
2749
|
+
<p>Zwei Leute, ein Studio.</p>
|
|
2750
|
+
|
|
2751
|
+
</section>
|
|
2752
|
+
```
|
|
2753
|
+
|
|
2754
|
+
Lower headings are ignored, so a section with only `##` headings gets no anchor
|
|
2755
|
+
unless you set `anchor_id`. And an `<h1>` per section is not what you want on
|
|
2756
|
+
a one-page site: the home page already has its `<h1>`, and with `team.md` in
|
|
2757
|
+
place `nera build --check` warns `` page has more than one `<h1>` ``
|
|
2758
|
+
(`a11y-h1`). So give the sections `##` headings and an explicit `anchor_id`, as
|
|
2759
|
+
in step 3, and delete `team.md` again. Explicit ids also stay the same when you
|
|
2760
|
+
rename a heading or translate the page (see step 10).
|
|
2761
|
+
|
|
2762
|
+
## 5. Sections without a page of their own
|
|
2763
|
+
|
|
2764
|
+
A section is still a page of its own. Nera writes a page only if it has a
|
|
2765
|
+
`layout`, and the sections above have none, so they exist only inside
|
|
2766
|
+
`/index.html`. Add `layout: pages/default.pug` to `about.md` and the build also
|
|
2767
|
+
writes `/sections/about.html`, while the section still appears on the home page.
|
|
2768
|
+
Leave `layout` out unless you want that second URL.
|
|
2769
|
+
|
|
2770
|
+
`nera validate` does not know that the missing layout is on purpose:
|
|
2771
|
+
|
|
2772
|
+
```text
|
|
2773
|
+
pages/sections/about.md
|
|
2774
|
+
:1 warning page has no `layout` — the build skips it silently; add `layout: pages/default.pug` to its frontmatter (a template in theme/views), or, if it has none on purpose (a fragment or draft), add `ignore: { layout-missing: [pages/sections/about.md] }` to config/validate.yaml layout-missing
|
|
2775
|
+
…
|
|
2776
|
+
0 error(s), 3 warning(s)
|
|
2777
|
+
```
|
|
2778
|
+
|
|
2779
|
+
Because all sections live in one folder, one entry silences them all:
|
|
2780
|
+
|
|
2781
|
+
```yaml:config/validate.yaml
|
|
2782
|
+
ignore:
|
|
2783
|
+
layout-missing:
|
|
2784
|
+
- pages/sections
|
|
2785
|
+
```
|
|
2786
|
+
|
|
2787
|
+
A folder covers everything below it. `nera validate` now prints
|
|
2788
|
+
`✓ No problems found.`
|
|
2789
|
+
|
|
2790
|
+
## 6. In-page navigation
|
|
2791
|
+
|
|
2792
|
+
`plugin-page-navigation` builds a navigation of **sibling pages** in the same
|
|
2793
|
+
folder, and skips pages at the site root, so on its own it gives `index.md`
|
|
2794
|
+
nothing. Its other mode fits: a **`page_navigation`** list in the page's
|
|
2795
|
+
frontmatter, whose entries go to the template exactly as written. Point them
|
|
2796
|
+
at the anchors:
|
|
2797
|
+
|
|
2798
|
+
```markdown:pages/index.md
|
|
2799
|
+
---
|
|
2800
|
+
layout: pages/one-page.pug
|
|
2801
|
+
title: Studio Lena
|
|
2802
|
+
description: Web design for small businesses in Berlin
|
|
2803
|
+
page_navigation:
|
|
2804
|
+
- href: '#services'
|
|
2805
|
+
name: Services
|
|
2806
|
+
- href: '#about'
|
|
2807
|
+
name: About
|
|
2808
|
+
- href: '#contact'
|
|
2809
|
+
name: Contact
|
|
2810
|
+
---
|
|
2811
|
+
# Websites for small businesses
|
|
2812
|
+
|
|
2813
|
+
I design and build fast, simple websites for shops, studios and practices.
|
|
2814
|
+
```
|
|
2815
|
+
|
|
2816
|
+
Quote the `href`s: in YAML an unquoted `#` after a space starts a comment.
|
|
2817
|
+
Include the published template above the content:
|
|
2818
|
+
|
|
2819
|
+
```pug:theme/views/pages/one-page.pug
|
|
2820
|
+
extends ../layouts/layout
|
|
2821
|
+
|
|
2822
|
+
block content
|
|
2823
|
+
main#main
|
|
2824
|
+
include /vendor/plugin-page-navigation/page-navigation
|
|
2825
|
+
!= content
|
|
2826
|
+
```
|
|
2827
|
+
|
|
2828
|
+
The `<nav>` is named by the translation key `Page navigation`, so it stays
|
|
2829
|
+
distinct from a main menu for screen readers. Give it a label in your
|
|
2830
|
+
language in `config/app.yaml`:
|
|
2831
|
+
|
|
2832
|
+
```yaml:config/app.yaml
|
|
2833
|
+
translations:
|
|
2834
|
+
en:
|
|
2835
|
+
Page navigation: On this page
|
|
2836
|
+
```
|
|
2837
|
+
|
|
2838
|
+
The built page starts with:
|
|
2839
|
+
|
|
2840
|
+
```html
|
|
2841
|
+
<nav class="page-nav" aria-label="On this page"><a class="page-nav__link" href="#services">Services</a><a class="page-nav__link" href="#about">About</a><a class="page-nav__link" href="#contact">Contact</a></nav>
|
|
2842
|
+
```
|
|
2843
|
+
|
|
2844
|
+
You could write these three links into the template by hand just as well. The
|
|
2845
|
+
plugin earns its place once the links differ per page or per language: they
|
|
2846
|
+
live in each page's frontmatter, next to the content they point to.
|
|
2847
|
+
|
|
2848
|
+
## 7. The contact form
|
|
2849
|
+
|
|
2850
|
+
`plugin-contact-form` renders a form from `config/contact-form.yaml`. On submit
|
|
2851
|
+
a small script in the browser builds a `mailto:` link from the fields and opens
|
|
2852
|
+
the visitor's own email program with subject and message filled in. There is no
|
|
2853
|
+
backend: your site stores and sends nothing, and the message leaves only through
|
|
2854
|
+
the visitor's email. (Handling the form on a server is not covered here.)
|
|
2855
|
+
|
|
2856
|
+
```yaml:config/contact-form.yaml
|
|
2857
|
+
recipient: hello@example.com
|
|
2858
|
+
subject: contact_subject
|
|
2859
|
+
submit_label: contact_submit
|
|
2860
|
+
error_required: contact_required
|
|
2861
|
+
error_email: contact_email_invalid
|
|
2862
|
+
|
|
2863
|
+
fields:
|
|
2864
|
+
- { name: name, label: contact_name, type: text, required: true }
|
|
2865
|
+
- { name: email, label: contact_email, type: email, required: true }
|
|
2866
|
+
- name: topic
|
|
2867
|
+
label: contact_topic
|
|
2868
|
+
type: select
|
|
2869
|
+
required: true
|
|
2870
|
+
options:
|
|
2871
|
+
- { value: new-site, label: contact_topic_new }
|
|
2872
|
+
- { value: redesign, label: contact_topic_redesign }
|
|
2873
|
+
- { value: care, label: contact_topic_care }
|
|
2874
|
+
- { name: message, label: contact_message, type: textarea, required: true }
|
|
2875
|
+
```
|
|
2876
|
+
|
|
2877
|
+
Every user-facing value here is a **translation key**, resolved for each
|
|
2878
|
+
page's language from `translations:` in `config/app.yaml`. A key without a
|
|
2879
|
+
translation renders as written, so a site in one language could write the text
|
|
2880
|
+
directly; keys pay off in step 10. `name` and the option `value`s are data and
|
|
2881
|
+
are never translated. Add the English texts:
|
|
2882
|
+
|
|
2883
|
+
```yaml:config/app.yaml
|
|
2884
|
+
translations:
|
|
2885
|
+
en:
|
|
2886
|
+
Page navigation: On this page
|
|
2887
|
+
contact_subject: Enquiry from the website
|
|
2888
|
+
contact_submit: Open in my email program
|
|
2889
|
+
contact_required: Please fill in all required fields.
|
|
2890
|
+
contact_email_invalid: Please enter a valid email address.
|
|
2891
|
+
contact_name: Your name
|
|
2892
|
+
contact_email: Your email
|
|
2893
|
+
contact_topic: What can I help with?
|
|
2894
|
+
contact_topic_new: A new website
|
|
2895
|
+
contact_topic_redesign: A redesign
|
|
2896
|
+
contact_topic_care: A care plan
|
|
2897
|
+
contact_message: Your message
|
|
2898
|
+
```
|
|
2899
|
+
|
|
2900
|
+
Keep the keys `nera new` put under `en:` (`app_description`, `skip_to_content`
|
|
2901
|
+
and the others) next to these.
|
|
2902
|
+
|
|
2903
|
+
The form is Pug, so it goes in the template, not in a Markdown section. The
|
|
2904
|
+
contact section has the highest `add_to_page_order`, so the form placed after
|
|
2905
|
+
the content follows its text directly:
|
|
2906
|
+
|
|
2907
|
+
```pug:theme/views/pages/one-page.pug
|
|
2908
|
+
extends ../layouts/layout
|
|
2909
|
+
|
|
2910
|
+
block content
|
|
2911
|
+
main#main
|
|
2912
|
+
include /vendor/plugin-page-navigation/page-navigation
|
|
2913
|
+
!= content
|
|
2914
|
+
include /vendor/plugin-contact-form/contact-form
|
|
2915
|
+
```
|
|
2916
|
+
|
|
2917
|
+
The built form (shortened):
|
|
2918
|
+
|
|
2919
|
+
```html
|
|
2920
|
+
<form class="contact-form" novalidate="novalidate" data-contact-form="data-contact-form">
|
|
2921
|
+
<script type="application/json" data-contact-config="data-contact-config">
|
|
2922
|
+
{
|
|
2923
|
+
"subject": "Enquiry from the website",
|
|
2924
|
+
…
|
|
2925
|
+
}
|
|
2926
|
+
</script><span class="contact-form__recipient" hidden="hidden" data-contact-recipient="hello@example.com"></span>
|
|
2927
|
+
<div class="contact-form__field contact-form__field--text"><label class="contact-form__label" for="contact-name">Your name</label><input class="contact-form__input" type="text" id="contact-name" name="name" data-contact-field="data-contact-field" data-contact-label="Your name" required="required" /></div>
|
|
2928
|
+
…
|
|
2929
|
+
<div class="contact-form__decoy" aria-hidden="true" style="position:absolute;left:-9999px;top:auto;width:1px;height:1px;overflow:hidden"><label for="contact-website">website</label><input type="text" id="contact-website" name="website" tabindex="-1" autocomplete="off" /></div>
|
|
2930
|
+
<div class="contact-form__status" role="alert" aria-live="polite" data-contact-status="data-contact-status"></div><button class="contact-form__submit" type="submit">Open in my email program</button>
|
|
2931
|
+
</form>
|
|
2932
|
+
<script src="/js/contact-form.js"></script>
|
|
2933
|
+
```
|
|
2934
|
+
|
|
2935
|
+
Submitted with every field filled in, the form opened this link:
|
|
2936
|
+
|
|
2937
|
+
```text
|
|
2938
|
+
mailto:hello@example.com?subject=Enquiry%20from%20the%20website&body=Your%20name%3A%20Jane%20Doe%0D%0AYour%20email%3A%20jane%40example.org%0D%0AWhat%20can%20I%20help%20with%3F%3A%20redesign%0D%0AYour%20message%3A%20Hello%20Lena
|
|
2939
|
+
```
|
|
2940
|
+
|
|
2941
|
+
Submitted empty, it opened nothing and showed `Please fill in all required
|
|
2942
|
+
fields.` in the status line. Three details are worth knowing:
|
|
2943
|
+
|
|
2944
|
+
- **The recipient is obfuscated, not hidden.** It never appears as readable
|
|
2945
|
+
text, but it is in the page:
|
|
2946
|
+
|
|
2947
|
+
| `obfuscation` | What lands in the HTML | Strength |
|
|
2948
|
+
| --- | --- | --- |
|
|
2949
|
+
| `entities` (default) | each character as an HTML entity, as above | deters naïve scrapers; a determined one can still decode it |
|
|
2950
|
+
| `jsassembly` | only an array of character codes, rebuilt in JavaScript on submit | stronger, still not a guarantee |
|
|
2951
|
+
|
|
2952
|
+
Use an address you are willing to publish.
|
|
2953
|
+
- **A honeypot is built in.** The hidden `website` field is a decoy for bots; a
|
|
2954
|
+
submission that fills it is dropped silently. Never give a real field the
|
|
2955
|
+
honeypot's name. If you want a real "website" field, rename the decoy with
|
|
2956
|
+
`honeypot:` in the config.
|
|
2957
|
+
- **The plugin ships no CSS** apart from the inline rule that hides the decoy.
|
|
2958
|
+
Style the BEM classes `.contact-form`, `.contact-form__field`,
|
|
2959
|
+
`.contact-form__input` and the others from your own stylesheet.
|
|
2960
|
+
|
|
2961
|
+
## 8. Social links in the footer
|
|
2962
|
+
|
|
2963
|
+
`plugin-social-media-links` reads a list of links from
|
|
2964
|
+
`config/social-media-links.yaml`:
|
|
2965
|
+
|
|
2966
|
+
```yaml:config/social-media-links.yaml
|
|
2967
|
+
aria_label: Social media
|
|
2968
|
+
open_in_new_tab: false
|
|
2969
|
+
|
|
2970
|
+
social_media_links:
|
|
2971
|
+
- name: GitHub
|
|
2972
|
+
href: https://github.com/yourname
|
|
2973
|
+
icon: '<svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M12 .297c-6.63 0-12 5.373-12 12 …"/></svg>'
|
|
2974
|
+
icon_raw: true
|
|
2975
|
+
- name: LinkedIn
|
|
2976
|
+
href: https://www.linkedin.com/in/yourname
|
|
2977
|
+
```
|
|
2978
|
+
|
|
2979
|
+
The `d` attribute is shortened here; paste the full path of the icon you use.
|
|
2980
|
+
Simple Icons (simpleicons.org) has brand logos as SVG. `icon` is escaped unless
|
|
2981
|
+
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 plugin's
|
|
2983
|
+
sample config uses Font Awesome `<i>` tags instead, which need the Font Awesome
|
|
2984
|
+
CSS. Loading it from a CDN sends every visitor's IP address to a third party,
|
|
2985
|
+
and `nera build --check` then warns `privacy-third-party`. Inline SVG or plain
|
|
2986
|
+
text needs no request at all.
|
|
2987
|
+
|
|
2988
|
+
`open_in_new_tab: false` lets the visitor decide where a link opens; without
|
|
2989
|
+
it, every link gets `target="_blank"`. `rel="noopener noreferrer"` is set
|
|
2990
|
+
either way.
|
|
2991
|
+
|
|
2992
|
+
Include the published template in the footer of the base layout that
|
|
2993
|
+
`nera new` created. Remove its first line, the `//- nera:scaffold-default`
|
|
2994
|
+
marker, now that the file is your own:
|
|
2995
|
+
|
|
2996
|
+
```pug:theme/views/layouts/layout.pug
|
|
2997
|
+
<!DOCTYPE html>
|
|
2998
|
+
html(lang=app.lang)
|
|
2999
|
+
head
|
|
3000
|
+
meta(charset="UTF-8")
|
|
3001
|
+
meta(name="viewport", content="width=device-width, initial-scale=1.0")
|
|
3002
|
+
title #{ meta.title } | #{ app.name }
|
|
3003
|
+
meta(name="description", content=`${ meta.description || t('app_description') }`)
|
|
3004
|
+
meta(name="keywords", content=`${ meta.keywords || t('app_keywords') }`)
|
|
3005
|
+
meta(name="generator" content="nera")
|
|
3006
|
+
meta(name="robots" content=`${ meta.robots || app.robots }`)
|
|
3007
|
+
style.
|
|
3008
|
+
.skip-link { position: absolute; left: -9999px; }
|
|
3009
|
+
.skip-link:focus { position: static; }
|
|
3010
|
+
|
|
3011
|
+
body
|
|
3012
|
+
a.skip-link(href="#main") #{ t('skip_to_content') }
|
|
3013
|
+
block content
|
|
3014
|
+
footer
|
|
3015
|
+
include /vendor/plugin-social-media-links/social-media-links
|
|
3016
|
+
a(href="/imprint.html") #{ t('imprint') }
|
|
3017
|
+
= ' · '
|
|
3018
|
+
a(href="/privacy.html") #{ t('privacy') }
|
|
3019
|
+
```
|
|
3020
|
+
|
|
3021
|
+
The footer now starts with (SVG path shortened):
|
|
3022
|
+
|
|
3023
|
+
```html
|
|
3024
|
+
<footer>
|
|
3025
|
+
<nav class="social-media-links" aria-label="Social media">
|
|
3026
|
+
<ul class="social-media-links__list">
|
|
3027
|
+
<li class="social-media-links__item"><a class="social-media-links__link" href="https://github.com/yourname" title="GitHub" rel="noopener noreferrer"><span class="social-media-links__icon"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M12 .297c-6.63 0-12 5.373-12 12 …"/></svg></span><span class="social-media-links__label">GitHub</span></a></li>
|
|
3028
|
+
<li class="social-media-links__item"><a class="social-media-links__link" href="https://www.linkedin.com/in/yourname" title="LinkedIn" rel="noopener noreferrer"><span class="social-media-links__icon"></span><span class="social-media-links__label">LinkedIn</span></a></li>
|
|
3029
|
+
</ul>
|
|
3030
|
+
</nav><a href="/imprint.html">Imprint</a> · <a href="/privacy.html">Privacy</a>
|
|
3031
|
+
</footer>
|
|
3032
|
+
```
|
|
3033
|
+
|
|
3034
|
+
## 9. Scrolling under a sticky navigation
|
|
3035
|
+
|
|
3036
|
+
A little CSS makes the page feel like one: the navigation stays at the top, the
|
|
3037
|
+
links scroll smoothly, and a section does not end up hidden under the
|
|
3038
|
+
navigation. Create `theme/assets/css/site.css`:
|
|
3039
|
+
|
|
3040
|
+
```css:theme/assets/css/site.css
|
|
3041
|
+
html {
|
|
3042
|
+
scroll-behavior: smooth;
|
|
3043
|
+
}
|
|
3044
|
+
|
|
3045
|
+
@media (prefers-reduced-motion: reduce) {
|
|
3046
|
+
html {
|
|
3047
|
+
scroll-behavior: auto;
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
|
|
3051
|
+
.page-nav {
|
|
3052
|
+
position: sticky;
|
|
3053
|
+
top: 0;
|
|
3054
|
+
display: flex;
|
|
3055
|
+
gap: 1rem;
|
|
3056
|
+
padding: 1rem 0;
|
|
3057
|
+
background: #fff;
|
|
3058
|
+
}
|
|
3059
|
+
|
|
3060
|
+
.section > a[id] {
|
|
3061
|
+
scroll-margin-top: 4rem;
|
|
3062
|
+
}
|
|
3063
|
+
```
|
|
3064
|
+
|
|
3065
|
+
The scroll target is the anchor, not the `<section>`, so `scroll-margin-top`
|
|
3066
|
+
goes on `a[id]`. Load the file in the layout's `head`, after the `meta` lines:
|
|
3067
|
+
|
|
3068
|
+
```pug
|
|
3069
|
+
link(rel="stylesheet", href="/css/site.css")
|
|
3070
|
+
```
|
|
3071
|
+
|
|
3072
|
+
Files in `theme/assets/` are served from the site root, so the file is
|
|
3073
|
+
`/css/site.css`. In a headless browser, on a page long enough to scroll that
|
|
3074
|
+
far, a click on each navigation link put its heading 64 px (4rem) from the top,
|
|
3075
|
+
just below the 50 px high sticky navigation.
|
|
3076
|
+
|
|
3077
|
+
## 10. A second language
|
|
3078
|
+
|
|
3079
|
+
A German copy of the page is a second target with its own sections. Set
|
|
3080
|
+
`lang: de` on each file and target `/de/index.html`:
|
|
3081
|
+
|
|
3082
|
+
```markdown:pages/de/index.md
|
|
3083
|
+
---
|
|
3084
|
+
layout: pages/one-page.pug
|
|
3085
|
+
lang: de
|
|
3086
|
+
title: Studio Lena
|
|
3087
|
+
description: Webdesign für kleine Unternehmen in Berlin
|
|
3088
|
+
page_navigation:
|
|
3089
|
+
- href: '#services'
|
|
3090
|
+
name: Leistungen
|
|
3091
|
+
- href: '#about'
|
|
3092
|
+
name: Über mich
|
|
3093
|
+
- href: '#contact'
|
|
3094
|
+
name: Kontakt
|
|
3095
|
+
---
|
|
3096
|
+
# Websites für kleine Unternehmen
|
|
3097
|
+
|
|
3098
|
+
Ich gestalte und baue schnelle, einfache Websites für Läden, Studios und Praxen.
|
|
3099
|
+
```
|
|
3100
|
+
|
|
3101
|
+
```markdown:pages/de/sections/services.md
|
|
3102
|
+
---
|
|
3103
|
+
lang: de
|
|
3104
|
+
title: Leistungen
|
|
3105
|
+
add_to_page: /de/index.html
|
|
3106
|
+
add_to_page_order: 1
|
|
3107
|
+
anchor_id: services
|
|
3108
|
+
content_wrapper_attributes:
|
|
3109
|
+
class: section section--services
|
|
3110
|
+
---
|
|
3111
|
+
## Leistungen
|
|
3112
|
+
|
|
3113
|
+
- **Neue Websites**: von der ersten Skizze bis zur fertigen Seite.
|
|
3114
|
+
- **Redesigns**: ein frischer Auftritt für die Website, die Sie schon haben.
|
|
3115
|
+
- **Pflege**: Updates und kleine Änderungen jeden Monat.
|
|
3116
|
+
```
|
|
3117
|
+
|
|
3118
|
+
`about.md` and `contact.md` in `pages/de/sections/` follow the same pattern
|
|
3119
|
+
with `anchor_id: about` and `anchor_id: contact`. The anchors stay the same in
|
|
3120
|
+
both languages, so the CSS works for both and a link to `#contact` works on
|
|
3121
|
+
either page.
|
|
3122
|
+
|
|
3123
|
+
Extend the `ignore` entry to every language folder; `*` stands for one folder
|
|
3124
|
+
name:
|
|
3125
|
+
|
|
3126
|
+
```yaml:config/validate.yaml
|
|
3127
|
+
ignore:
|
|
3128
|
+
layout-missing:
|
|
3129
|
+
- pages/sections
|
|
3130
|
+
- pages/*/sections
|
|
3131
|
+
```
|
|
3132
|
+
|
|
3133
|
+
Translate the keys from steps 6 and 7 under `de:` in `config/app.yaml`:
|
|
3134
|
+
|
|
3135
|
+
```yaml:config/app.yaml
|
|
3136
|
+
de:
|
|
3137
|
+
app_description: Eine statische Website, gebaut mit Nera
|
|
3138
|
+
app_keywords: nera, static site generator
|
|
3139
|
+
skip_to_content: Zum Inhalt springen
|
|
3140
|
+
imprint: Impressum
|
|
3141
|
+
privacy: Datenschutz
|
|
3142
|
+
Page navigation: Auf dieser Seite
|
|
3143
|
+
contact_subject: Anfrage über die Website
|
|
3144
|
+
contact_submit: In meinem E-Mail-Programm öffnen
|
|
3145
|
+
contact_required: Bitte füllen Sie alle Pflichtfelder aus.
|
|
3146
|
+
contact_email_invalid: Bitte geben Sie eine gültige E-Mail-Adresse ein.
|
|
3147
|
+
contact_name: Ihr Name
|
|
3148
|
+
contact_email: Ihre E-Mail-Adresse
|
|
3149
|
+
contact_topic: Wobei kann ich helfen?
|
|
3150
|
+
contact_topic_new: Eine neue Website
|
|
3151
|
+
contact_topic_redesign: Ein Redesign
|
|
3152
|
+
contact_topic_care: Ein Pflegepaket
|
|
3153
|
+
contact_message: Ihre Nachricht
|
|
3154
|
+
```
|
|
3155
|
+
|
|
3156
|
+
The scaffolded layout sets `html(lang=app.lang)`, which is `en` on every page.
|
|
3157
|
+
Use the page's language instead:
|
|
3158
|
+
|
|
3159
|
+
```pug
|
|
3160
|
+
html(lang=meta.lang || app.lang)
|
|
3161
|
+
```
|
|
3162
|
+
|
|
3163
|
+
`/de/index.html` then has `<html lang="de">`, the German navigation and the
|
|
3164
|
+
German form, with the same field names:
|
|
3165
|
+
|
|
3166
|
+
```html
|
|
3167
|
+
<nav class="page-nav" aria-label="Auf dieser Seite"><a class="page-nav__link" href="#services">Leistungen</a><a class="page-nav__link" href="#about">Über mich</a><a class="page-nav__link" href="#contact">Kontakt</a></nav>
|
|
3168
|
+
…
|
|
3169
|
+
<div class="contact-form__field contact-form__field--text"><label class="contact-form__label" for="contact-name">Ihr Name</label><input class="contact-form__input" type="text" id="contact-name" name="name" data-contact-field="data-contact-field" data-contact-label="Ihr Name" required="required" /></div>
|
|
3170
|
+
```
|
|
3171
|
+
|
|
3172
|
+
The social links' `aria_label` is not passed through `t()` by the shipped
|
|
3173
|
+
template. To translate it, change the `nav` line in your published
|
|
3174
|
+
`theme/views/vendor/plugin-social-media-links/social-media-links.pug`:
|
|
3175
|
+
|
|
3176
|
+
```pug
|
|
3177
|
+
nav.social-media-links(aria-label=t(app.socialMediaLinksLabel))
|
|
3178
|
+
```
|
|
3179
|
+
|
|
3180
|
+
and add `Social media: Soziale Medien` under `de:`. With all of this in place,
|
|
3181
|
+
`nera validate` and `nera build --check` both print `✓ No problems found.`
|
|
3182
|
+
|
|
3183
|
+
## One page or stacks?
|
|
3184
|
+
|
|
3185
|
+
[plugin-stacks](https://nera.js.org/tutorials/reusable-content-blocks.html) also turns Markdown
|
|
3186
|
+
files into pieces of other pages, but the other way round. A stack is a block
|
|
3187
|
+
that a **view** places, anywhere and as often as you like, through
|
|
3188
|
+
`app.stacks`; it marks itself with `type: stack` and needs no `validate.yaml`
|
|
3189
|
+
entry. A one-page section names **its target page** in `add_to_page`, and the
|
|
3190
|
+
plugin appends it to that page's content, in order, with an anchor and a
|
|
3191
|
+
wrapper, without touching a template. Use one-page when a page is a sequence
|
|
3192
|
+
of sections. Use stacks when the same block belongs in several places or in a
|
|
3193
|
+
particular spot of a layout.
|
|
3194
|
+
|
|
3195
|
+
## Next
|
|
3196
|
+
|
|
3197
|
+
- [Build a navigation with active states](https://nera.js.org/tutorials/custom-navigation.html)
|
|
3198
|
+
adds a main menu, once the one page grows into a few.
|
|
3199
|
+
- [How this website is built](https://nera.js.org/tutorials/how-this-site-is-built.html) shows a
|
|
3200
|
+
complete Nera site with its plugins working together.
|
|
3201
|
+
|
|
3202
|
+
# How this website is built
|
|
3203
|
+
|
|
3204
|
+
Source: https://nera.js.org/tutorials/how-this-site-is-built.html
|
|
3205
|
+
|
|
3206
|
+
This whole site is built with Nera. Nothing here is special-cased — it's the same
|
|
3207
|
+
generator and the same public plugins you'd install. Here's the full recipe.
|
|
3208
|
+
|
|
3209
|
+
## Scaffolded like any site
|
|
3210
|
+
|
|
3211
|
+
It started with the nera CLI, which scaffolds a site whose one Nera dependency is
|
|
3212
|
+
`@nera-static/nera` (it brings the `@nera-static/core` engine):
|
|
3213
|
+
|
|
3214
|
+
```bash
|
|
3215
|
+
npx @nera-static/nera new nera-website
|
|
3216
|
+
```
|
|
3217
|
+
|
|
3218
|
+
## Thirteen plugins, each doing one thing
|
|
3219
|
+
|
|
3220
|
+
| Plugin | Job | Config |
|
|
3221
|
+
| --- | --- | --- |
|
|
3222
|
+
| `plugin-navigation` | Header + footer menus with active states | `config/navigation.yaml` |
|
|
3223
|
+
| `plugin-tags` | Tutorial tags + per-language `/tutorials/tags/*` pages | `config/tags.yaml` |
|
|
3224
|
+
| `plugin-search` | Per-language client-side search index + box | `config/search.yaml` |
|
|
3225
|
+
| `plugin-page-pagination` | Prev/next in docs and tutorials | `config/page-pagination.yaml` |
|
|
3226
|
+
| `plugin-canonical-links` | Canonical `<link>` tags for SEO | `config/canonical-links.yaml` |
|
|
3227
|
+
| `plugin-link-attributes` | External links open in a new tab | `config/link-attributes.yaml` |
|
|
3228
|
+
| `plugin-code-blocks` | Build-time syntax highlighting with a copy button | `config/code-blocks.yaml` |
|
|
3229
|
+
| `plugin-stacks` | The homepage feature grid, one Markdown file per feature in `pages/stacks/home-features/` (see [Reusable content blocks](https://nera.js.org/tutorials/reusable-content-blocks.html)) | — |
|
|
3230
|
+
| `tutorials-list` (local) | Builds `app.tutorials` for the index | — |
|
|
3231
|
+
| `llms-txt` (local) | `llms.txt`, `llms-full.txt` and a `.md` per page for AI assistants | `config/llms-txt.yaml` |
|
|
3232
|
+
| `skill-zip` (local) | [The Nera skill](https://nera.js.org/docs/using-ai.html) as a zip for claude.ai and Claude Desktop | — |
|
|
3233
|
+
| `heading-ids` (local) | An `id` on every h2–h4, so sections can be linked | — |
|
|
3234
|
+
| `table-scroll` (local) | Wraps every Markdown table in a `.table-scroll` box, so wide tables scroll on phones | — |
|
|
3235
|
+
|
|
3236
|
+
The five local plugins — `tutorials-list`, `llms-txt`, `skill-zip`,
|
|
3237
|
+
`heading-ids` and `table-scroll` — live in `plugins/`, set with `folders.plugins` in `config/app.yaml`. `llms-txt` and
|
|
3238
|
+
`skill-zip` write files rather than data, and hand them to the build through the
|
|
3239
|
+
`getAssets` hook (see [Write your own local plugin](https://nera.js.org/tutorials/write-a-local-plugin.html)).
|
|
3240
|
+
`skill-zip` reads the skill from the installed `@nera-static/nera`, so the
|
|
3241
|
+
download always matches the CLI the site builds with. Most of the others have
|
|
3242
|
+
their own tutorial in this section, if you want the details.
|
|
3243
|
+
|
|
3244
|
+
## Order matters — canonical links and search run last
|
|
3245
|
+
|
|
3246
|
+
Search builds its index from the final state of every page, so it has to run after
|
|
3247
|
+
everything else. Canonical links have to come after `plugin-tags` too, or the tag
|
|
3248
|
+
pages it generates get no canonical link — and alphabetically, `canonical-links`
|
|
3249
|
+
would run before `tags`. `config/plugin-order.yaml` says so:
|
|
3250
|
+
|
|
3251
|
+
```yaml
|
|
3252
|
+
plugin-order:
|
|
3253
|
+
- end:
|
|
3254
|
+
- plugin-canonical-links
|
|
3255
|
+
- plugin-search
|
|
3256
|
+
```
|
|
3257
|
+
|
|
3258
|
+
Everything else runs alphabetically in between. This is the one place plugin
|
|
3259
|
+
ordering is load-bearing on this site.
|
|
3260
|
+
|
|
3261
|
+
## Templates we own
|
|
3262
|
+
|
|
3263
|
+
Plugins that ship views were published into `theme/views/vendor/` with commands like
|
|
3264
|
+
`npx nera-navigation`. Those copies are ours to edit and style — nothing important
|
|
3265
|
+
is hidden inside `node_modules`.
|
|
3266
|
+
|
|
3267
|
+
## Content is just Markdown
|
|
3268
|
+
|
|
3269
|
+
Every page you're reading is a Markdown file under `pages/` with a `layout` in its
|
|
3270
|
+
frontmatter. The docs are `pages/docs/*.md`; this tutorial is
|
|
3271
|
+
`pages/tutorials/how-this-site-is-built.md`. Folders become URLs; no routing config
|
|
3272
|
+
exists.
|
|
3273
|
+
|
|
3274
|
+
## Build
|
|
3275
|
+
|
|
3276
|
+
```bash
|
|
3277
|
+
npm run build # pages/ -> public/
|
|
3278
|
+
```
|
|
3279
|
+
|
|
3280
|
+
## Checks and deploy
|
|
3281
|
+
|
|
3282
|
+
Every push to `main` and every pull request against it runs
|
|
3283
|
+
[`.github/workflows/test.yml`](https://github.com/seebaermichi/nera-website/blob/main/.github/workflows/test.yml) on Node 22 and 24 — the same commands you can run
|
|
3284
|
+
locally:
|
|
3285
|
+
|
|
3286
|
+
```bash
|
|
3287
|
+
npm ci
|
|
3288
|
+
npm run lint # eslint
|
|
3289
|
+
npm test # node --test on the tests beside the local plugins
|
|
3290
|
+
npm run validate # nera validate: layouts, includes, frontmatter
|
|
3291
|
+
npm run build -- --check # nera build --check
|
|
3292
|
+
```
|
|
3293
|
+
|
|
3294
|
+
`--check` looks at the built `public/` for accessibility, privacy and
|
|
3295
|
+
legal-notice problems and reports what it finds. Findings are warnings, so they
|
|
3296
|
+
fail the run only for a rule that `config/validate.yaml` promotes to an error.
|
|
3297
|
+
|
|
3298
|
+
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`, and `public/` is published to GitHub Pages — the site you are
|
|
3300
|
+
reading at nera.js.org.
|
|
3301
|
+
|
|
3302
|
+
That's the entire stack: Markdown in, static HTML out, plugins for the rest. If
|
|
3303
|
+
you've read the other tutorials in this section, you've now seen every piece of it
|
|
3304
|
+
in isolation — this is just all of them together.
|