@nera-static/mcp 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/icon.png +0 -0
- package/.claude-plugin/plugin.json +38 -0
- package/CHANGELOG.md +9 -0
- package/README.md +36 -7
- package/bin/nera-mcp.js +11 -1
- package/package.json +9 -2
- package/skills/nera/SKILL.md +135 -0
- package/skills/nera/recipes/blog.md +59 -0
- package/skills/nera/recipes/business-site.md +57 -0
- package/skills/nera/recipes/contact-form.md +63 -0
- package/skills/nera/recipes/custom-domain.md +49 -0
- package/skills/nera/recipes/images.md +45 -0
- package/skills/nera/recipes/multilingual.md +50 -0
- package/skills/nera/recipes/portfolio.md +51 -0
- package/skills/nera/recipes/search.md +52 -0
- package/src/runner.js +16 -14
- package/src/runtime.js +210 -0
|
Binary file
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nera",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Create, edit, build, validate, preview and publish websites made with Nera, a static site generator: the Nera skill plus the Nera MCP server, which works only inside the sites folder you pick on enable.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Michael Becker"
|
|
7
|
+
},
|
|
8
|
+
"homepage": "https://nera.js.org",
|
|
9
|
+
"repository": "https://github.com/seebaermichi/nera-mcp",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"icon": "./.claude-plugin/icon.png",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"nera",
|
|
14
|
+
"static-site-generator",
|
|
15
|
+
"mcp",
|
|
16
|
+
"markdown",
|
|
17
|
+
"pug"
|
|
18
|
+
],
|
|
19
|
+
"userConfig": {
|
|
20
|
+
"root": {
|
|
21
|
+
"type": "directory",
|
|
22
|
+
"title": "Sites folder",
|
|
23
|
+
"description": "The folder your Nera sites live in. Claude creates new sites in it and may read and change files only inside it.",
|
|
24
|
+
"required": true
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"mcpServers": {
|
|
28
|
+
"nera": {
|
|
29
|
+
"command": "npx",
|
|
30
|
+
"args": [
|
|
31
|
+
"-y",
|
|
32
|
+
"@nera-static/mcp@1.1.0",
|
|
33
|
+
"--root",
|
|
34
|
+
"${user_config.root}"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.1.0] - 2026-11-18
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- A Claude Desktop extension, `nera-mcp-<version>.mcpb`, attached to every GitHub Release: double-click to install, pick the sites folder in its settings. It runs on the Node that ships with Claude Desktop and brings npm itself, so no Node.js installation is needed. `npm run mcpb` builds it; its manifest is made from `package.json` and lists the tools and prompts the server registers.
|
|
13
|
+
- `NERA_MCP_RUNTIME=bundled` (set by the extension): every command the server starts finds `node`, `npm` and `npx` through a shim folder first on its PATH, even with no Node on the system PATH. Without the variable nothing changes.
|
|
14
|
+
- A Claude Code plugin with the Nera skill (copied from `@nera-static/nera`) and the server, and a marketplace in this repository: `claude plugin marketplace add seebaermichi/nera-mcp`, then `claude plugin install nera@nera`. It asks for the sites folder when it is enabled and starts the server at the plugin's own version.
|
|
15
|
+
- A 512×512 Nera icon (the favicon mark of nera.js.org) for the Desktop extension and the Claude Code plugin.
|
|
16
|
+
|
|
8
17
|
## [1.0.1] - 2026-11-18
|
|
9
18
|
|
|
10
19
|
### Added
|
package/README.md
CHANGED
|
@@ -15,14 +15,43 @@ The client starts this command itself; you only add it to the client's configura
|
|
|
15
15
|
|
|
16
16
|
## Requirements
|
|
17
17
|
|
|
18
|
-
- Node.js **22.12 or later** (`node --version`), with `npx
|
|
18
|
+
- Node.js **22.12 or later** (`node --version`), with `npx`. Not needed for the Claude Desktop extension, which brings its own.
|
|
19
19
|
- For `publish`: a GitHub account (and a Netlify account if you host there)
|
|
20
20
|
|
|
21
21
|
## Install
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
### Claude Desktop extension
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
The easiest way, and no Node.js needed: Claude Desktop runs the server on the Node it ships, and the extension brings npm along.
|
|
26
|
+
|
|
27
|
+
1. Download `nera-mcp-<version>.mcpb` from the [latest release](https://github.com/seebaermichi/nera-mcp/releases/latest).
|
|
28
|
+
2. Double-click it and choose **Install** in Claude Desktop.
|
|
29
|
+
3. Pick your **Sites folder** when Claude Desktop asks for it: the folder your sites live in.
|
|
30
|
+
|
|
31
|
+
The extension runs on macOS and Windows. To update, install the `.mcpb` of a newer release.
|
|
32
|
+
|
|
33
|
+
### Claude Code plugin
|
|
34
|
+
|
|
35
|
+
The plugin brings the server and the Nera skill, which teaches Claude how a Nera site is built, in one install:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
claude plugin marketplace add seebaermichi/nera-mcp
|
|
39
|
+
claude plugin install nera@nera
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
or, inside Claude Code 2.1.275 or later, in one step:
|
|
43
|
+
|
|
44
|
+
```text
|
|
45
|
+
/plugin install nera --marketplace seebaermichi/nera-mcp
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Claude Code asks for your **Sites folder** when the plugin is enabled. The plugin starts the server with `npx`, so it needs Node.js (see Requirements).
|
|
49
|
+
|
|
50
|
+
### Manual configuration
|
|
51
|
+
|
|
52
|
+
To add the server to a client yourself, replace `/Users/you/Sites` below with the folder your sites should live in. It must exist. Use an absolute path: clients do not expand `~` in their configuration files.
|
|
53
|
+
|
|
54
|
+
#### Claude Code
|
|
26
55
|
|
|
27
56
|
```bash
|
|
28
57
|
claude mcp add --transport stdio nera -- npx -y @nera-static/mcp --root /Users/you/Sites
|
|
@@ -30,9 +59,9 @@ claude mcp add --transport stdio nera -- npx -y @nera-static/mcp --root /Users/y
|
|
|
30
59
|
|
|
31
60
|
Add `--scope user` to have it in every project, or `--scope project` to share it through the project's `.mcp.json`.
|
|
32
61
|
|
|
33
|
-
|
|
62
|
+
#### Claude Desktop
|
|
34
63
|
|
|
35
|
-
Settings → Developer → **Edit Config** opens `claude_desktop_config.json` (macOS: `~/Library/Application Support/Claude/`, Windows: `%APPDATA%\Claude\`). Add the server and restart Claude Desktop:
|
|
64
|
+
Without the extension: Settings → Developer → **Edit Config** opens `claude_desktop_config.json` (macOS: `~/Library/Application Support/Claude/`, Windows: `%APPDATA%\Claude\`). Add the server and restart Claude Desktop:
|
|
36
65
|
|
|
37
66
|
```json
|
|
38
67
|
{
|
|
@@ -45,11 +74,11 @@ Settings → Developer → **Edit Config** opens `claude_desktop_config.json` (m
|
|
|
45
74
|
}
|
|
46
75
|
```
|
|
47
76
|
|
|
48
|
-
|
|
77
|
+
#### Cursor
|
|
49
78
|
|
|
50
79
|
Add the same `mcpServers` entry to `~/.cursor/mcp.json` (all projects) or `.cursor/mcp.json` (one project).
|
|
51
80
|
|
|
52
|
-
|
|
81
|
+
#### Codex
|
|
53
82
|
|
|
54
83
|
```bash
|
|
55
84
|
codex mcp add nera -- npx -y @nera-static/mcp --root /Users/you/Sites
|
package/bin/nera-mcp.js
CHANGED
|
@@ -64,13 +64,23 @@ if (!options.root) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
// the server and the Nera packages it loads come last: only the server needs them
|
|
67
|
-
const [{ StdioServerTransport }, { createServer }, { createProcesses }, { PathError }] = await Promise.all([
|
|
67
|
+
const [{ StdioServerTransport }, { createServer }, { createProcesses }, { PathError }, { setupRuntime }] = await Promise.all([
|
|
68
68
|
import('@modelcontextprotocol/sdk/server/stdio.js'),
|
|
69
69
|
import('../src/server.js'),
|
|
70
70
|
import('../src/processes.js'),
|
|
71
71
|
import('../src/paths.js'),
|
|
72
|
+
import('../src/runtime.js'),
|
|
72
73
|
])
|
|
73
74
|
|
|
75
|
+
// the Desktop extension sets NERA_MCP_RUNTIME=bundled: its Node has no npm and
|
|
76
|
+
// nothing on the PATH, so children get a shim folder for node, npm and npx;
|
|
77
|
+
// the folder goes when this process exits, however it exits
|
|
78
|
+
const runtime = setupRuntime()
|
|
79
|
+
if (runtime) {
|
|
80
|
+
process.on('exit', runtime.remove)
|
|
81
|
+
console.error(`nera-mcp: bundled runtime, node${runtime.npm ? ', npm and npx' : ' (no npm found)'} for children in ${runtime.dir}`)
|
|
82
|
+
}
|
|
83
|
+
|
|
74
84
|
const processes = createProcesses()
|
|
75
85
|
let server
|
|
76
86
|
try {
|
package/package.json
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nera-static/mcp",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A local MCP server for Nera: lets an AI assistant create, edit, build, validate, preview and publish Nera static sites under one folder",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
|
+
".claude-plugin/icon.png",
|
|
8
|
+
".claude-plugin/plugin.json",
|
|
7
9
|
"bin",
|
|
8
10
|
"docs",
|
|
11
|
+
"skills",
|
|
9
12
|
"src",
|
|
10
13
|
"CHANGELOG.md"
|
|
11
14
|
],
|
|
12
15
|
"scripts": {
|
|
13
16
|
"lint": "eslint .",
|
|
14
17
|
"test": "vitest",
|
|
15
|
-
"prepack": "node scripts/fetch-docs.js"
|
|
18
|
+
"prepack": "node scripts/fetch-docs.js && node scripts/sync-skill.js",
|
|
19
|
+
"mcpb": "node scripts/fetch-docs.js && node scripts/build-mcpb.js",
|
|
20
|
+
"skill": "node scripts/sync-skill.js",
|
|
21
|
+
"version": "node scripts/sync-version.js && git add .claude-plugin/plugin.json"
|
|
16
22
|
},
|
|
17
23
|
"keywords": [
|
|
18
24
|
"nera",
|
|
@@ -47,6 +53,7 @@
|
|
|
47
53
|
"zod": "^4.6.7"
|
|
48
54
|
},
|
|
49
55
|
"devDependencies": {
|
|
56
|
+
"@anthropic-ai/mcpb": "^2.1.2",
|
|
50
57
|
"eslint": "^10.15.0",
|
|
51
58
|
"vitest": "^5.1.1"
|
|
52
59
|
},
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: nera
|
|
3
|
+
description: Create, change, check and deploy websites built with Nera, the Markdown + Pug static site generator (npm package @nera-static/nera). Use when package.json lists @nera-static/nera, or when the user asks to build a website, page, blog, portfolio or business site with Nera, or to add a contact form, search, images, a second language or a custom domain to a Nera site. Holds the workflow, the checks to run after every change, and short recipes for common sites and features.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Nera
|
|
7
|
+
|
|
8
|
+
Nera turns Markdown pages and Pug templates into plain HTML. It is not
|
|
9
|
+
Eleventy, Hugo, Astro or Jekyll; do not apply their conventions.
|
|
10
|
+
|
|
11
|
+
## Read this first
|
|
12
|
+
|
|
13
|
+
- **In an existing site, read `AGENTS.md` at the site root before anything
|
|
14
|
+
else.** It holds the folder map, the commands and the traps (pages need
|
|
15
|
+
`layout`, URLs end in `.html`, `public/` is wiped on every build, plugin
|
|
16
|
+
templates are copied and included by hand). This skill does not repeat it.
|
|
17
|
+
- No site yet? Scaffold one (step 1 below), then read its `AGENTS.md`.
|
|
18
|
+
- The "Notes for this site" section at the end of `AGENTS.md` belongs to the
|
|
19
|
+
site owner: follow it, and add to it what the next agent should know.
|
|
20
|
+
|
|
21
|
+
## Workflow
|
|
22
|
+
|
|
23
|
+
1. **Scaffold.** `npx @nera-static/nera new my-site` creates a folder and
|
|
24
|
+
installs; `npx @nera-static/nera new .` fills the current, empty folder.
|
|
25
|
+
Start from an official starter when one fits, with `--starter <name>`:
|
|
26
|
+
- `blank`: a home page, imprint and privacy placeholders, one layout
|
|
27
|
+
- `blog`: sample posts, tags, archive, prev/next, feed, sitemap
|
|
28
|
+
- `business`: home, about, services, opening hours, contact form
|
|
29
|
+
- `portfolio`: project pages with image galleries, about, contact form
|
|
30
|
+
|
|
31
|
+
`--name "<site name>"` and `--lang <code>` set `name` and `lang` in
|
|
32
|
+
`config/app.yaml`. With `--yes`, or without a terminal, it never asks:
|
|
33
|
+
`npx @nera-static/nera new my-site --starter blog --name "My Blog" --lang en --yes`.
|
|
34
|
+
`--theme <name>` starts from a theme instead (not together with
|
|
35
|
+
`--starter`, which brings its own); `--no-install` skips `npm install`.
|
|
36
|
+
2. **Content.** One Markdown file per page in `pages/`, each with YAML
|
|
37
|
+
frontmatter that names its `layout`. Site name, language and texts for
|
|
38
|
+
templates go in `config/app.yaml`. Shared markup goes in `theme/views/`.
|
|
39
|
+
3. **Plugins.** Look for a plugin before writing a feature (see below).
|
|
40
|
+
Install it, configure it in `config/<name>.yaml`, copy its templates with
|
|
41
|
+
its own binary and include them in a layout.
|
|
42
|
+
4. **Validate.** `npx nera validate` and fix every error it reports. It
|
|
43
|
+
finds broken layouts and includes and pages the build would skip.
|
|
44
|
+
5. **Build and check.** `npx nera build --check` and fix what it reports
|
|
45
|
+
(accessibility, privacy and legal hints on the built site).
|
|
46
|
+
`npm run dev` previews on http://localhost:3000 with live reload; stop it
|
|
47
|
+
when you are done.
|
|
48
|
+
6. **Deploy.** `npm run build` writes the finished site into `public/`.
|
|
49
|
+
Upload the contents of `public/` to any static host. See
|
|
50
|
+
[custom-domain](recipes/custom-domain.md) for a domain of your own.
|
|
51
|
+
Or `npx nera publish --yes` puts it on GitHub Pages: it signs in to
|
|
52
|
+
GitHub (the site owner enters the code it prints), creates (or
|
|
53
|
+
reuses) the repository and the deploy workflow, sets `base_path` and
|
|
54
|
+
prints the live URL (`--json` for a JSON object).
|
|
55
|
+
`--domain <host>` sets a custom domain and checks its DNS.
|
|
56
|
+
`npx nera publish --yes --target netlify` deploys to Netlify instead:
|
|
57
|
+
GitHub Actions still builds the site, the site owner also authorizes
|
|
58
|
+
Nera CLI on Netlify through the link it prints, and the Netlify site
|
|
59
|
+
and its repository secrets are set up for you. Netlify's free plan
|
|
60
|
+
covers about 20 deploys a month (300 credits, 15 per deploy) and then
|
|
61
|
+
pauses the sites until the next month, so publish when a batch of
|
|
62
|
+
changes is ready; `nera publish` warns at 80 % of the budget. A later
|
|
63
|
+
run reuses the target kept in `config/publish.yaml`. Pick the target
|
|
64
|
+
with `--target`: GitHub's terms do not allow GitHub Pages as free
|
|
65
|
+
hosting for a business, so use `--target netlify` for a business site
|
|
66
|
+
(without `--target`, a person at a terminal is asked whether the site
|
|
67
|
+
is for a business). To move a published site, run
|
|
68
|
+
`npx nera publish --yes --target <other>`: it sets up the new host and
|
|
69
|
+
swaps the deploy job, leaves the site on the old host online and prints
|
|
70
|
+
how to remove it there (`movedFrom` in `--json`).
|
|
71
|
+
|
|
72
|
+
Repeat steps 2–5 for every change. For machine-readable results, add `--json`:
|
|
73
|
+
`npx nera validate --json`, `npx nera check --json`,
|
|
74
|
+
`npx nera build --check --json`.
|
|
75
|
+
|
|
76
|
+
Existing site on an older Nera? `npx nera update` updates the Nera packages
|
|
77
|
+
and refreshes `AGENTS.md` and this skill.
|
|
78
|
+
|
|
79
|
+
## Look for a plugin before writing a feature
|
|
80
|
+
|
|
81
|
+
Features come from npm packages named `@nera-static/plugin-<name>`. An
|
|
82
|
+
installed plugin loads on the next build, with nothing to register. Do not
|
|
83
|
+
hand-write navigation, a contact form, tags, search, pagination, image
|
|
84
|
+
handling, a sitemap, a feed or a consent banner: a plugin exists for each.
|
|
85
|
+
The catalog: https://github.com/seebaermichi/nera/blob/main/PLUGINS.md
|
|
86
|
+
|
|
87
|
+
The published plugins: canonical-links, code-blocks, consent, contact-form,
|
|
88
|
+
feed, images, link-attributes, navigation, one-page, page-navigation,
|
|
89
|
+
page-pagination, popular-content, search, simple-page-list, sitemap,
|
|
90
|
+
social-media-links, stacks, statistics, tags. Each plugin's README (on npm, or
|
|
91
|
+
`github.com/seebaermichi/nera-plugin-<name>`) lists its config keys and its
|
|
92
|
+
template binary. Read it before you configure the plugin.
|
|
93
|
+
|
|
94
|
+
A feature no plugin covers can be a local plugin in
|
|
95
|
+
`src/plugins/<name>/index.js`; see the tutorial
|
|
96
|
+
[Write a local plugin](https://nera.js.org/tutorials/write-a-local-plugin.md).
|
|
97
|
+
|
|
98
|
+
## Recipes
|
|
99
|
+
|
|
100
|
+
Short task guides. Each names the steps, the files it touches and the docs
|
|
101
|
+
page to open next.
|
|
102
|
+
|
|
103
|
+
- [Business site](recipes/business-site.md): home, about, services, contact,
|
|
104
|
+
imprint and privacy, with a menu
|
|
105
|
+
- [Blog](recipes/blog.md): posts, a post list, tags, pagination, sitemap
|
|
106
|
+
- [Portfolio](recipes/portfolio.md): project pages with responsive images
|
|
107
|
+
- [Contact form](recipes/contact-form.md): a `mailto:` form, no backend
|
|
108
|
+
- [Search](recipes/search.md): client-side search over the site
|
|
109
|
+
- [Images](recipes/images.md): responsive AVIF/WebP images
|
|
110
|
+
- [Multilingual site](recipes/multilingual.md): a second language
|
|
111
|
+
- [Custom domain](recipes/custom-domain.md): DNS, GitHub Pages
|
|
112
|
+
`--domain`, `base_path`
|
|
113
|
+
|
|
114
|
+
## Docs
|
|
115
|
+
|
|
116
|
+
The docs on https://nera.js.org are the truth; this skill only points to
|
|
117
|
+
them. For AI assistants, in English:
|
|
118
|
+
|
|
119
|
+
- Index: https://nera.js.org/llms.txt
|
|
120
|
+
- Everything in one file: https://nera.js.org/llms-full.txt
|
|
121
|
+
- Single pages as Markdown:
|
|
122
|
+
[getting started](https://nera.js.org/docs/getting-started.md),
|
|
123
|
+
[core concepts](https://nera.js.org/docs/core-concepts.md),
|
|
124
|
+
[writing content](https://nera.js.org/docs/writing-content.md),
|
|
125
|
+
[plugins](https://nera.js.org/docs/plugins.md),
|
|
126
|
+
[deployment](https://nera.js.org/docs/deployment.md),
|
|
127
|
+
[CLI](https://nera.js.org/docs/cli.md),
|
|
128
|
+
[using AI](https://nera.js.org/docs/using-ai.md)
|
|
129
|
+
- Tutorials: [build a blog](https://nera.js.org/tutorials/build-a-blog.md),
|
|
130
|
+
[custom navigation](https://nera.js.org/tutorials/custom-navigation.md),
|
|
131
|
+
[tag your content](https://nera.js.org/tutorials/tag-your-content.md),
|
|
132
|
+
[add search](https://nera.js.org/tutorials/add-search.md),
|
|
133
|
+
[prev/next pagination](https://nera.js.org/tutorials/prev-next-pagination.md),
|
|
134
|
+
[canonical links](https://nera.js.org/tutorials/canonical-links-seo.md),
|
|
135
|
+
[how nera.js.org is built](https://nera.js.org/tutorials/how-this-site-is-built.md)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Recipe: blog
|
|
2
|
+
|
|
3
|
+
Posts in a folder, a list of posts on the home page, tags, previous/next
|
|
4
|
+
links and a sitemap.
|
|
5
|
+
|
|
6
|
+
## Fast path
|
|
7
|
+
|
|
8
|
+
`npx @nera-static/nera new my-blog --starter blog` creates a blog on
|
|
9
|
+
`@nera-static/theme-blog`: sample posts, tags, an archive by year,
|
|
10
|
+
previous/next, an Atom feed, a sitemap and navigation. The theme's own
|
|
11
|
+
templates list the posts; it does not use simple-page-list. Read its
|
|
12
|
+
`AGENTS.md`, then replace the sample posts and the placeholder
|
|
13
|
+
`origin: https://example.com` in `config/app.yaml` with the live URL; step 9
|
|
14
|
+
below still applies. The steps below build the blog by hand instead, with
|
|
15
|
+
different files.
|
|
16
|
+
|
|
17
|
+
## Steps
|
|
18
|
+
|
|
19
|
+
1. Scaffold: `npx @nera-static/nera new my-blog`, then read its `AGENTS.md`.
|
|
20
|
+
2. One Markdown file per post in `pages/posts/`, e.g.
|
|
21
|
+
`pages/posts/first-post.md`, each with `layout`, `title`, `description`,
|
|
22
|
+
`date` (`2026-10-12`) and `tags` (`tags: travel, food` or a YAML list).
|
|
23
|
+
A post is served at `/posts/first-post.html`.
|
|
24
|
+
3. Post list: `npm install @nera-static/plugin-simple-page-list`, set
|
|
25
|
+
`page_path: /posts`, `sortBy: date` and `sortOrder: descending` in
|
|
26
|
+
`config/simple-page-list.yaml`, run
|
|
27
|
+
`npx nera-simple-page-list`, and include the list in the template of the
|
|
28
|
+
home page (data: `app.pageList`).
|
|
29
|
+
4. Tags: `npm install @nera-static/plugin-tags`. It builds a page per tag
|
|
30
|
+
at `/tags/<tag>.html`. Run `npx nera-tags` and include
|
|
31
|
+
`partials/tag-links` in the post template and `partials/tag-cloud` where
|
|
32
|
+
you want all tags.
|
|
33
|
+
5. Previous/next: `npm install @nera-static/plugin-page-pagination`, give
|
|
34
|
+
each post a `pagination_order` number, run `npx nera-page-pagination`
|
|
35
|
+
and include it in the post template. It links pages of the same folder.
|
|
36
|
+
6. A post template of its own: `theme/views/pages/post.pug`, extending
|
|
37
|
+
`../layouts/layout` like `pages/default.pug`, with exactly one `main`.
|
|
38
|
+
Posts then use `layout: pages/post.pug`.
|
|
39
|
+
7. Sitemap: `npm install @nera-static/plugin-sitemap` and set `origin` in
|
|
40
|
+
`config/app.yaml`. It also writes `robots.txt`.
|
|
41
|
+
8. Menu: `@nera-static/plugin-navigation`, as in
|
|
42
|
+
[business-site](business-site.md).
|
|
43
|
+
9. `npx nera validate`, then `npx nera build --check`; fix what they report.
|
|
44
|
+
|
|
45
|
+
Each plugin's README names its config keys and include paths; read it
|
|
46
|
+
before step 3, 4 or 5.
|
|
47
|
+
|
|
48
|
+
## Files touched
|
|
49
|
+
|
|
50
|
+
`pages/posts/*.md`, `pages/index.md`, `config/app.yaml`,
|
|
51
|
+
`config/simple-page-list.yaml`, `config/tags.yaml` (optional),
|
|
52
|
+
`theme/views/pages/post.pug`, `theme/views/vendor/plugin-*/`,
|
|
53
|
+
`package.json`.
|
|
54
|
+
|
|
55
|
+
## Read next
|
|
56
|
+
|
|
57
|
+
- https://nera.js.org/tutorials/build-a-blog.md
|
|
58
|
+
- https://nera.js.org/tutorials/tag-your-content.md
|
|
59
|
+
- https://nera.js.org/tutorials/prev-next-pagination.md
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Recipe: business site
|
|
2
|
+
|
|
3
|
+
A small business presence: home, about, services, opening hours, contact,
|
|
4
|
+
imprint and privacy, with a menu on every page.
|
|
5
|
+
|
|
6
|
+
## Fast path
|
|
7
|
+
|
|
8
|
+
`npx @nera-static/nera new my-business --starter business` creates all of
|
|
9
|
+
this on `@nera-static/theme-business`: the pages, navigation, a contact form,
|
|
10
|
+
responsive images, social links and a sitemap. Read its `AGENTS.md`, then
|
|
11
|
+
replace the sample texts; steps 2, 8 and 9 below still apply. The steps
|
|
12
|
+
below build the site by hand instead, with different files.
|
|
13
|
+
|
|
14
|
+
## Steps
|
|
15
|
+
|
|
16
|
+
1. Scaffold: `npx @nera-static/nera new my-business`, then read its
|
|
17
|
+
`AGENTS.md`.
|
|
18
|
+
2. Set the site in `config/app.yaml`: `name`, `lang`, and `origin` (the
|
|
19
|
+
live URL, e.g. `https://example.com`) once the domain is known.
|
|
20
|
+
3. Write one Markdown page per topic, each with `layout: pages/default.pug`,
|
|
21
|
+
a `title` and a `description`: `pages/index.md`, `pages/about.md`,
|
|
22
|
+
`pages/services.md`, `pages/opening-hours.md`, `pages/contact.md`.
|
|
23
|
+
Opening hours fit a Markdown table. A new site already has
|
|
24
|
+
`pages/imprint.md` and `pages/privacy.md` as placeholders, linked from
|
|
25
|
+
the layout's footer: replace their text, or write them if they are
|
|
26
|
+
missing.
|
|
27
|
+
4. Menu: `npm install @nera-static/plugin-navigation`, list the pages in
|
|
28
|
+
`config/navigation.yaml` (`href` ending in `.html`, `name`; groups such
|
|
29
|
+
as `main:` and `footer:`; a footer menu replaces the layout's own
|
|
30
|
+
imprint and privacy links, so keep only one of the two), run
|
|
31
|
+
`npx nera-navigation` and include a menu in
|
|
32
|
+
`theme/views/layouts/layout.pug` (see the plugin README for the mixins).
|
|
33
|
+
5. Contact form: follow [contact-form](contact-form.md).
|
|
34
|
+
6. Optional, for search engines: `@nera-static/plugin-sitemap` (needs
|
|
35
|
+
`origin`) and `@nera-static/plugin-canonical-links`. Social profiles:
|
|
36
|
+
`@nera-static/plugin-social-media-links`.
|
|
37
|
+
7. Styles: a CSS file in `theme/assets/css/`, linked from the layout's
|
|
38
|
+
`head` (`link(rel="stylesheet" href="/css/main.css")`).
|
|
39
|
+
8. `npx nera validate`, then `npx nera build --check`; fix what they report.
|
|
40
|
+
The legal hints from the check matter here: a business site usually
|
|
41
|
+
needs an imprint and a privacy page.
|
|
42
|
+
9. Deploy `public/` (see [custom-domain](custom-domain.md)).
|
|
43
|
+
|
|
44
|
+
Mark invented details (address, hours, prices, legal texts) as placeholders
|
|
45
|
+
for the owner to replace, and say that legal pages need checking.
|
|
46
|
+
|
|
47
|
+
## Files touched
|
|
48
|
+
|
|
49
|
+
`config/app.yaml`, `config/navigation.yaml`, `pages/*.md`,
|
|
50
|
+
`theme/views/layouts/layout.pug`, `theme/views/vendor/plugin-navigation/`,
|
|
51
|
+
`theme/assets/css/`, `package.json`.
|
|
52
|
+
|
|
53
|
+
## Read next
|
|
54
|
+
|
|
55
|
+
- https://nera.js.org/docs/writing-content.md
|
|
56
|
+
- https://nera.js.org/tutorials/custom-navigation.md
|
|
57
|
+
- https://nera.js.org/docs/deployment.md
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Recipe: contact form
|
|
2
|
+
|
|
3
|
+
A contact form with `@nera-static/plugin-contact-form`. It opens the
|
|
4
|
+
visitor's mail client (`mailto:`): no backend, no form service, no account.
|
|
5
|
+
Do not hand-write a `<form>` or post to a third-party service.
|
|
6
|
+
|
|
7
|
+
## Steps
|
|
8
|
+
|
|
9
|
+
1. `npm install @nera-static/plugin-contact-form`
|
|
10
|
+
2. Create `config/contact-form.yaml`. `recipient` and at least one field
|
|
11
|
+
are required; without them the form does not render and the build only
|
|
12
|
+
warns:
|
|
13
|
+
|
|
14
|
+
```yaml
|
|
15
|
+
recipient: hello@example.com
|
|
16
|
+
fields:
|
|
17
|
+
- name: name
|
|
18
|
+
label: Your name
|
|
19
|
+
type: text
|
|
20
|
+
required: true
|
|
21
|
+
- name: email
|
|
22
|
+
label: Your email
|
|
23
|
+
type: email
|
|
24
|
+
required: true
|
|
25
|
+
- name: message
|
|
26
|
+
label: Message
|
|
27
|
+
type: textarea
|
|
28
|
+
required: true
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Field types: `text`, `email`, `tel`, `textarea`, `select`, `checkbox`,
|
|
32
|
+
`radio`. The README lists the optional keys (subject, labels, honeypot,
|
|
33
|
+
`consent_text` with a link to the privacy page).
|
|
34
|
+
3. `npx nera-contact-form` copies the form to
|
|
35
|
+
`theme/views/vendor/plugin-contact-form/` and its script to
|
|
36
|
+
`theme/assets/js/contact-form.js`.
|
|
37
|
+
4. A page template for the contact page, `theme/views/pages/contact.pug`:
|
|
38
|
+
|
|
39
|
+
```pug
|
|
40
|
+
extends ../layouts/layout
|
|
41
|
+
|
|
42
|
+
block content
|
|
43
|
+
main
|
|
44
|
+
| !{ content }
|
|
45
|
+
include /vendor/plugin-contact-form/contact-form
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
5. `pages/contact.md` with `layout: pages/contact.pug`, a `title` and a
|
|
49
|
+
short text above the form.
|
|
50
|
+
6. `npx nera validate`, then `npx nera build --check`. Open
|
|
51
|
+
`/contact.html` with `npm run dev` and submit once: the mail client
|
|
52
|
+
should open with the message filled in.
|
|
53
|
+
|
|
54
|
+
## Files touched
|
|
55
|
+
|
|
56
|
+
`package.json`, `config/contact-form.yaml`, `pages/contact.md`,
|
|
57
|
+
`theme/views/pages/contact.pug`, `theme/views/vendor/plugin-contact-form/`,
|
|
58
|
+
`theme/assets/js/contact-form.js`.
|
|
59
|
+
|
|
60
|
+
## Read next
|
|
61
|
+
|
|
62
|
+
- Plugin README: https://github.com/seebaermichi/nera-plugin-contact-form
|
|
63
|
+
- https://nera.js.org/docs/plugins.md
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Recipe: custom domain
|
|
2
|
+
|
|
3
|
+
Serve the built site under a domain of your own. Nera builds static files;
|
|
4
|
+
the domain is set at the host and at the domain registrar.
|
|
5
|
+
|
|
6
|
+
## Steps
|
|
7
|
+
|
|
8
|
+
1. Build: `npm run build`. Deploy the contents of `public/` to the host
|
|
9
|
+
(GitHub Pages, Netlify, any static host). Set the host to build with
|
|
10
|
+
`npm run build` and publish `public/`, or upload `public/` yourself.
|
|
11
|
+
2. At the host, add the custom domain in its site settings.
|
|
12
|
+
3. At the registrar, set the DNS records the host names for that domain,
|
|
13
|
+
usually a `CNAME` record for `www` pointing at the host and `A`/`AAAA`
|
|
14
|
+
records (or `ALIAS`) for the bare domain. Copy them from the host's own
|
|
15
|
+
docs; they differ per host. DNS can take hours to spread.
|
|
16
|
+
4. **GitHub Pages through `nera publish`:** run
|
|
17
|
+
`npx nera publish --yes --domain www.example.com`. It sets the domain in
|
|
18
|
+
the Pages settings, removes `base_path`, checks the DNS on every publish
|
|
19
|
+
and prints the records to set when they are missing (`A`/`AAAA` for a
|
|
20
|
+
bare domain, a `CNAME` to `<user>.github.io` otherwise). Steps 2 and 5 are done for you; set
|
|
21
|
+
the records of step 3 yourself.
|
|
22
|
+
No `CNAME` file is needed: GitHub ignores it for a site an Actions
|
|
23
|
+
workflow deploys. Only a Pages site deployed from a branch uses one; put
|
|
24
|
+
it in `theme/assets/CNAME` (never in `public/`, which every build deletes).
|
|
25
|
+
**Netlify through `nera publish`:** run
|
|
26
|
+
`npx nera publish --yes --target netlify --domain www.example.com`. It sets
|
|
27
|
+
the domain on the Netlify site, checks the DNS on every publish and prints
|
|
28
|
+
the records to set when they are missing (`A 75.2.60.5` for a bare
|
|
29
|
+
domain, a `CNAME` to `<site>.netlify.app` otherwise). Netlify issues the
|
|
30
|
+
HTTPS certificate by itself once the records point to it, so steps 2, 5
|
|
31
|
+
and 7 are done for you; set the records of step 3 yourself.
|
|
32
|
+
5. **`base_path`:** leave it unset for a custom domain or any site served
|
|
33
|
+
from the root. Set `base_path: /<repo>` in `config/app.yaml` only for a
|
|
34
|
+
site served under a sub-path, such as a GitHub project page at
|
|
35
|
+
`https://<user>.github.io/<repo>/`; Nera then prefixes every root-absolute
|
|
36
|
+
link and asset URL. Remove it again when the custom domain takes over.
|
|
37
|
+
6. Set `origin: https://www.example.com` in `config/app.yaml`, so the
|
|
38
|
+
sitemap and canonical links use the real domain.
|
|
39
|
+
7. Turn on HTTPS at the host once the domain resolves.
|
|
40
|
+
8. `npx nera validate`, then `npx nera build --check`, then deploy again.
|
|
41
|
+
|
|
42
|
+
## Files touched
|
|
43
|
+
|
|
44
|
+
`config/app.yaml` (`origin`, `base_path`), DNS settings outside the site,
|
|
45
|
+
`theme/assets/CNAME` only for a Pages site deployed from a branch.
|
|
46
|
+
|
|
47
|
+
## Read next
|
|
48
|
+
|
|
49
|
+
- https://nera.js.org/docs/deployment.md
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Recipe: images
|
|
2
|
+
|
|
3
|
+
Responsive images with `@nera-static/plugin-images`: each picture becomes a
|
|
4
|
+
`<picture>` with AVIF and WebP in several widths, plus a fallback. Needs
|
|
5
|
+
`@nera-static/core` 4.13.0 or later (`npx nera update` brings it).
|
|
6
|
+
|
|
7
|
+
## Steps
|
|
8
|
+
|
|
9
|
+
1. `npm install @nera-static/plugin-images`
|
|
10
|
+
2. Put the originals in the assets folder, e.g. `theme/assets/images/`.
|
|
11
|
+
They are referenced without `theme/assets`: `/images/photo.jpg`.
|
|
12
|
+
3. In Markdown, write images as usual; the plugin rewrites them:
|
|
13
|
+
``. A title becomes a caption
|
|
14
|
+
(``), and query parameters crop or
|
|
15
|
+
size one image (`?w=800&ratio=16:9`, see the README).
|
|
16
|
+
4. In frontmatter, `image: /images/hero.jpg` gets precomputed variants for
|
|
17
|
+
templates. Run `npx nera-images` to copy the `picture` mixin to
|
|
18
|
+
`theme/views/vendor/plugin-images/`, then in a template:
|
|
19
|
+
|
|
20
|
+
```pug
|
|
21
|
+
include /vendor/plugin-images/picture
|
|
22
|
+
+picture(meta.images && meta.images.image, { alt: meta.image_alt })
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Images written directly in Pug (`img(src=…)`) are not processed.
|
|
26
|
+
5. Optional `config/images.yaml`: `formats`, `widths`, `sizes`, `quality`.
|
|
27
|
+
6. Variants are cached in `.nera-cache/images/`; the scaffold's
|
|
28
|
+
`.gitignore` already ignores `.nera-cache`.
|
|
29
|
+
7. Originals with location data? List their folder (e.g. `images`) in a
|
|
30
|
+
`.neraignore` file at the site root; its paths are relative to the
|
|
31
|
+
assets folder. Only the processed variants, without metadata, are then
|
|
32
|
+
published.
|
|
33
|
+
8. `npx nera validate`, then `npx nera build --check`; every image needs
|
|
34
|
+
alt text.
|
|
35
|
+
|
|
36
|
+
## Files touched
|
|
37
|
+
|
|
38
|
+
`package.json`, `theme/assets/images/`, `pages/*.md`,
|
|
39
|
+
`config/images.yaml` (optional), `theme/views/vendor/plugin-images/`,
|
|
40
|
+
`.neraignore` (optional).
|
|
41
|
+
|
|
42
|
+
## Read next
|
|
43
|
+
|
|
44
|
+
- Plugin README: https://github.com/seebaermichi/nera-plugin-images
|
|
45
|
+
- https://nera.js.org/docs/writing-content.md
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Recipe: multilingual site
|
|
2
|
+
|
|
3
|
+
A second language beside the first, e.g. English at `/` and German at
|
|
4
|
+
`/de/`.
|
|
5
|
+
|
|
6
|
+
## Steps
|
|
7
|
+
|
|
8
|
+
1. Keep the default language at the root of `pages/` and put each other
|
|
9
|
+
language in its own folder: `pages/de/index.md` becomes `/de/index.html`.
|
|
10
|
+
2. Give every page in another language `lang` in its frontmatter
|
|
11
|
+
(`lang: de`). Pages without it use `lang` from `config/app.yaml`.
|
|
12
|
+
3. Pair the versions of a page with the same `slug` in their frontmatter
|
|
13
|
+
(`slug: about` on `pages/about.md` and `pages/de/ueber-uns.md`).
|
|
14
|
+
4. Template texts: write `t('key')` in Pug and add the texts per language
|
|
15
|
+
under `translations:` in `config/app.yaml`:
|
|
16
|
+
|
|
17
|
+
```yaml
|
|
18
|
+
lang: en
|
|
19
|
+
translations:
|
|
20
|
+
en:
|
|
21
|
+
read_more: Read more
|
|
22
|
+
de:
|
|
23
|
+
read_more: Weiterlesen
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`t()` uses the page's `lang`, else the site's.
|
|
27
|
+
5. In `theme/views/layouts/layout.pug`, set the document language from the
|
|
28
|
+
page: `html(lang=meta.lang || app.lang)`.
|
|
29
|
+
6. Menus: one group per language in `config/navigation.yaml` (`main:` and
|
|
30
|
+
`main_de:`), each rendered with the menu mixin and the language root,
|
|
31
|
+
e.g. `+linkListNav(app.nav.main_de.elements, 'nav--main', '/de')`.
|
|
32
|
+
Add a link to the other language's version of the page.
|
|
33
|
+
7. Search engines: `@nera-static/plugin-canonical-links` with
|
|
34
|
+
`available_languages` in `config/canonical-links.yaml` adds `hreflang`
|
|
35
|
+
links; `@nera-static/plugin-sitemap` lists the pairs too. Both use
|
|
36
|
+
`lang` and `slug`.
|
|
37
|
+
8. Search and tags can keep one index or tag list per language
|
|
38
|
+
(`group_by_lang` in `config/search.yaml` or `config/tags.yaml`).
|
|
39
|
+
9. `npx nera validate`, then `npx nera build --check`.
|
|
40
|
+
|
|
41
|
+
## Files touched
|
|
42
|
+
|
|
43
|
+
`pages/<lang>/*.md`, `config/app.yaml`, `config/navigation.yaml`,
|
|
44
|
+
`config/canonical-links.yaml`, `theme/views/layouts/layout.pug`.
|
|
45
|
+
|
|
46
|
+
## Read next
|
|
47
|
+
|
|
48
|
+
- https://nera.js.org/docs/core-concepts.md
|
|
49
|
+
- https://nera.js.org/tutorials/canonical-links-seo.md
|
|
50
|
+
- https://nera.js.org/tutorials/custom-navigation.md
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Recipe: portfolio
|
|
2
|
+
|
|
3
|
+
A home page with a grid of projects, one page per project, large responsive
|
|
4
|
+
images.
|
|
5
|
+
|
|
6
|
+
## Fast path
|
|
7
|
+
|
|
8
|
+
`npx @nera-static/nera new my-portfolio --starter portfolio` creates a
|
|
9
|
+
portfolio on `@nera-static/theme-business`: project pages with image
|
|
10
|
+
galleries, about, a contact form, navigation, responsive images and a
|
|
11
|
+
sitemap. Read its `AGENTS.md`, then replace the sample projects and images
|
|
12
|
+
and the placeholder `origin: https://example.com` in `config/app.yaml`;
|
|
13
|
+
step 7 below still applies. The steps below build the portfolio by hand
|
|
14
|
+
instead, with different files.
|
|
15
|
+
|
|
16
|
+
## Steps
|
|
17
|
+
|
|
18
|
+
1. Scaffold: `npx @nera-static/nera new my-portfolio`, then read its
|
|
19
|
+
`AGENTS.md`.
|
|
20
|
+
2. Images: put originals in `theme/assets/images/` and set up
|
|
21
|
+
[images](images.md) first, so every photo is served as AVIF/WebP in
|
|
22
|
+
several widths.
|
|
23
|
+
3. One Markdown file per project in `pages/projects/`, each with `layout`,
|
|
24
|
+
`title`, `description`, `date` and `image: /images/<file>.jpg` (the cover
|
|
25
|
+
picture). Show more photos in the body with
|
|
26
|
+
``.
|
|
27
|
+
4. Project list: `npm install @nera-static/plugin-simple-page-list`, set
|
|
28
|
+
`page_path: /projects` in `config/simple-page-list.yaml`, run
|
|
29
|
+
`npx nera-simple-page-list`, and render `app.pageList` on the home page.
|
|
30
|
+
For a grid with cover images, loop over `app.pageList` in your own Pug
|
|
31
|
+
template instead of the published one.
|
|
32
|
+
5. A project template, `theme/views/pages/project.pug`, extending
|
|
33
|
+
`../layouts/layout`, that shows the cover with the images plugin's
|
|
34
|
+
`+picture` mixin and then `content`, with exactly one `main`.
|
|
35
|
+
6. Optional: `@nera-static/plugin-tags` to group projects by kind,
|
|
36
|
+
`@nera-static/plugin-page-pagination` for previous/next project,
|
|
37
|
+
`@nera-static/plugin-social-media-links`, `@nera-static/plugin-sitemap`.
|
|
38
|
+
7. `npx nera validate`, then `npx nera build --check`. The check reports
|
|
39
|
+
images without alt text; describe what each picture shows.
|
|
40
|
+
|
|
41
|
+
## Files touched
|
|
42
|
+
|
|
43
|
+
`theme/assets/images/`, `pages/projects/*.md`, `pages/index.md`,
|
|
44
|
+
`config/images.yaml` (optional), `config/simple-page-list.yaml`,
|
|
45
|
+
`theme/views/pages/project.pug`, `theme/views/vendor/plugin-*/`,
|
|
46
|
+
`package.json`.
|
|
47
|
+
|
|
48
|
+
## Read next
|
|
49
|
+
|
|
50
|
+
- https://nera.js.org/docs/writing-content.md
|
|
51
|
+
- https://nera.js.org/docs/plugins.md
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Recipe: search
|
|
2
|
+
|
|
3
|
+
Client-side search with `@nera-static/plugin-search`: the build writes a
|
|
4
|
+
JSON index, a small script searches it in the browser. No backend.
|
|
5
|
+
|
|
6
|
+
## Steps
|
|
7
|
+
|
|
8
|
+
1. `npm install @nera-static/plugin-search`. It works without config;
|
|
9
|
+
`config/search.yaml` can change the indexed `fields` or set
|
|
10
|
+
`group_by_lang: true` for one index per language.
|
|
11
|
+
2. `npx nera-search` copies the search template to
|
|
12
|
+
`theme/views/vendor/plugin-search/` and its script to
|
|
13
|
+
`theme/assets/js/search.js`.
|
|
14
|
+
3. A page template for the search page, `theme/views/pages/search.pug`:
|
|
15
|
+
|
|
16
|
+
```pug
|
|
17
|
+
extends ../layouts/layout
|
|
18
|
+
|
|
19
|
+
block content
|
|
20
|
+
main
|
|
21
|
+
| !{ content }
|
|
22
|
+
include /vendor/plugin-search/search.pug
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
4. `pages/search.md` with `layout: pages/search.pug`, a `title` and a
|
|
26
|
+
`# Search` heading, and `show_title: false` in `config/search.yaml`, so
|
|
27
|
+
that heading is the page's only `h1` (without the key the template adds
|
|
28
|
+
its own and `nera build --check` warns `a11y-h1`). Link the page from
|
|
29
|
+
the menu.
|
|
30
|
+
5. The template's input is already labelled (`aria-label`, default
|
|
31
|
+
"Search"). To translate the template, add `search_label`, `search_title`
|
|
32
|
+
and `search_placeholder` to the site's translations. A copy published
|
|
33
|
+
before plugin-search 2.3.0 lacks both: refresh it with
|
|
34
|
+
`npx nera-search --force` if it was never edited.
|
|
35
|
+
6. The index is written to `theme/assets/search-index.json` on every build
|
|
36
|
+
and served as `/search-index.json`. It is generated: add
|
|
37
|
+
`theme/assets/search-index*.json` to `.gitignore`.
|
|
38
|
+
7. Only pages with a `layout` are indexed. If other plugins add pages (tags),
|
|
39
|
+
run search last with `config/plugin-order.yaml` as the README shows.
|
|
40
|
+
8. `npx nera validate`, then `npx nera build --check`; try a query with
|
|
41
|
+
`npm run dev`.
|
|
42
|
+
|
|
43
|
+
## Files touched
|
|
44
|
+
|
|
45
|
+
`package.json`, `config/search.yaml` (optional), `pages/search.md`,
|
|
46
|
+
`theme/views/pages/search.pug`, `theme/views/vendor/plugin-search/`,
|
|
47
|
+
`theme/assets/js/search.js`, `.gitignore`.
|
|
48
|
+
|
|
49
|
+
## Read next
|
|
50
|
+
|
|
51
|
+
- https://nera.js.org/tutorials/add-search.md
|
|
52
|
+
- Plugin README: https://github.com/seebaermichi/nera-plugin-search
|
package/src/runner.js
CHANGED
|
@@ -2,6 +2,7 @@ import { spawn as nodeSpawn } from 'node:child_process'
|
|
|
2
2
|
import { existsSync } from 'node:fs'
|
|
3
3
|
import { createRequire } from 'node:module'
|
|
4
4
|
import path from 'node:path'
|
|
5
|
+
import { activeShim, npmScripts, ownNpm, withPathPrefix } from './runtime.js'
|
|
5
6
|
|
|
6
7
|
const require = createRequire(import.meta.url)
|
|
7
8
|
const NERA_BIN = path.join('node_modules', '@nera-static', 'nera', 'bin', 'nera.js')
|
|
@@ -27,22 +28,19 @@ export function neraBin(cwd) {
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
|
-
* How to start npm without a shell: its `npm-cli.js`
|
|
31
|
-
* (
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* How to start npm without a shell: its `npm-cli.js` from the server's own
|
|
32
|
+
* `node_modules/npm` (the Desktop extension bundles one) or next to the running
|
|
33
|
+
* Node (where every Node installer puts it), else the `npm` executable on the
|
|
34
|
+
* PATH. Running the script through `process.execPath` avoids `npm.cmd` on
|
|
35
|
+
* Windows, which Node refuses to spawn without a shell.
|
|
34
36
|
*
|
|
35
37
|
* @param {string} [execPath] the Node binary
|
|
38
|
+
* @param {string|null} [own] the server's own npm package folder
|
|
36
39
|
* @returns {{ file: string, prefix: string[] }}
|
|
37
40
|
*/
|
|
38
|
-
export function npmCommand(execPath = process.execPath) {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
path.join(bin, '..', 'lib', 'node_modules', 'npm', 'bin', 'npm-cli.js'),
|
|
42
|
-
path.join(bin, 'node_modules', 'npm', 'bin', 'npm-cli.js'),
|
|
43
|
-
]
|
|
44
|
-
const script = candidates.find((candidate) => existsSync(candidate))
|
|
45
|
-
return script ? { file: execPath, prefix: [script] } : { file: 'npm', prefix: [] }
|
|
41
|
+
export function npmCommand(execPath = process.execPath, own = ownNpm()) {
|
|
42
|
+
const scripts = npmScripts(execPath, own)
|
|
43
|
+
return scripts ? { file: execPath, prefix: [scripts.npmCli] } : { file: 'npm', prefix: [] }
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
/**
|
|
@@ -83,19 +81,23 @@ export function capped(text) {
|
|
|
83
81
|
* POSIX — its own process group, so `stopChild` reaches the processes it
|
|
84
82
|
* starts in turn (npm's scripts, Vite's workers). Windows has no process
|
|
85
83
|
* groups to signal; `stopChild` ends the tree with `taskkill /T` there.
|
|
84
|
+
* Under the bundled runtime the shim folder (`src/runtime.js`) comes first on
|
|
85
|
+
* the PATH, so the child and everything it starts find `node`, `npm` and `npx`.
|
|
86
86
|
*
|
|
87
87
|
* @param {string} cwd
|
|
88
88
|
* @param {Record<string, string>} [env] added to this process's environment
|
|
89
89
|
* @param {NodeJS.Platform} [platform] injected in tests
|
|
90
|
+
* @param {string|null} [shim] the shim folder; the active one by default
|
|
90
91
|
* @returns {import('node:child_process').SpawnOptions}
|
|
91
92
|
*/
|
|
92
|
-
export function spawnOptions(cwd, env = {}, platform = process.platform) {
|
|
93
|
+
export function spawnOptions(cwd, env = {}, platform = process.platform, shim = activeShim()) {
|
|
94
|
+
const merged = { ...process.env, NO_COLOR: '1', FORCE_COLOR: '0', ...env }
|
|
93
95
|
return {
|
|
94
96
|
cwd,
|
|
95
97
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
96
98
|
shell: false,
|
|
97
99
|
detached: platform !== 'win32',
|
|
98
|
-
env:
|
|
100
|
+
env: shim ? withPathPrefix(merged, shim, platform) : merged,
|
|
99
101
|
}
|
|
100
102
|
}
|
|
101
103
|
|
package/src/runtime.js
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// The bundled runtime of the Claude Desktop extension: Claude Desktop runs the
|
|
2
|
+
// server on the Node it ships, which comes without npm and puts nothing on the
|
|
3
|
+
// PATH. Every child (`nera new` → `npm install`, `nera dev` → Vite's
|
|
4
|
+
// `#!/usr/bin/env node` scripts, npm's lifecycle scripts) looks `node`, `npm`
|
|
5
|
+
// and `npx` up on the PATH, so under `NERA_MCP_RUNTIME=bundled` the bin writes
|
|
6
|
+
// a shim folder for the three and every child gets it first on its PATH.
|
|
7
|
+
import { existsSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
8
|
+
import { createRequire } from 'node:module'
|
|
9
|
+
import os from 'node:os'
|
|
10
|
+
import path from 'node:path'
|
|
11
|
+
|
|
12
|
+
const require = createRequire(import.meta.url)
|
|
13
|
+
|
|
14
|
+
/** The environment variable that switches the bundled runtime on. */
|
|
15
|
+
export const RUNTIME_ENV = 'NERA_MCP_RUNTIME'
|
|
16
|
+
/** Its one value that does; any other leaves children as they were. */
|
|
17
|
+
export const BUNDLED = 'bundled'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The `npm` package folder this server can load itself: the one the
|
|
21
|
+
* Desktop extension bundles in its `node_modules`, or null when there is none
|
|
22
|
+
* (an ordinary install from npm brings none). Only `node_modules` folders
|
|
23
|
+
* count, not Node's legacy global folders (`~/.node_modules`, `$PREFIX/lib/node`).
|
|
24
|
+
*
|
|
25
|
+
* @returns {string|null}
|
|
26
|
+
*/
|
|
27
|
+
export function ownNpm() {
|
|
28
|
+
const folders = (require.resolve.paths('npm') || []).filter((folder) => path.basename(folder) === 'node_modules')
|
|
29
|
+
const found = folders.find((folder) => existsSync(path.join(folder, 'npm', 'bin', 'npm-cli.js')))
|
|
30
|
+
return found ? path.join(found, 'npm') : null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Where npm's two entry scripts are: in the server's own `node_modules/npm`
|
|
35
|
+
* first (the bundled one), else next to the Node binary, where every Node
|
|
36
|
+
* installer puts npm (`lib/node_modules/npm` on POSIX, `node_modules/npm` on
|
|
37
|
+
* Windows). Null when neither has it.
|
|
38
|
+
*
|
|
39
|
+
* @param {string} [execPath] the Node binary
|
|
40
|
+
* @param {string|null} [own] the server's own npm package folder
|
|
41
|
+
* @returns {{ npmCli: string, npxCli: string }|null}
|
|
42
|
+
*/
|
|
43
|
+
export function npmScripts(execPath = process.execPath, own = ownNpm()) {
|
|
44
|
+
const bin = path.dirname(execPath)
|
|
45
|
+
const folders = [
|
|
46
|
+
own,
|
|
47
|
+
path.join(bin, '..', 'lib', 'node_modules', 'npm'),
|
|
48
|
+
path.join(bin, 'node_modules', 'npm'),
|
|
49
|
+
].filter(Boolean)
|
|
50
|
+
const folder = folders.find((candidate) => existsSync(path.join(candidate, 'bin', 'npm-cli.js')))
|
|
51
|
+
if (!folder) return null
|
|
52
|
+
return {
|
|
53
|
+
npmCli: path.join(folder, 'bin', 'npm-cli.js'),
|
|
54
|
+
npxCli: path.join(folder, 'bin', 'npx-cli.js'),
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Quotes a path for a POSIX `sh` script: in single quotes, where nothing is
|
|
60
|
+
* expanded, with each `'` closed, escaped and reopened.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} value
|
|
63
|
+
* @returns {string}
|
|
64
|
+
*/
|
|
65
|
+
function shQuote(value) {
|
|
66
|
+
return `'${value.replaceAll('\'', '\'\\\'\'')}'`
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Quotes a path for a Windows `.cmd` script: in double quotes (a Windows path
|
|
71
|
+
* cannot contain one), with `%` doubled so cmd does not expand it as a
|
|
72
|
+
* variable.
|
|
73
|
+
*
|
|
74
|
+
* @param {string} value
|
|
75
|
+
* @returns {string}
|
|
76
|
+
*/
|
|
77
|
+
function cmdQuote(value) {
|
|
78
|
+
return `"${value.replaceAll('%', '%%')}"`
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The shim scripts for a platform: file name → content. Each one runs its
|
|
83
|
+
* target with the Node binary and passes every argument on unchanged (`"$@"`
|
|
84
|
+
* in `sh`, `%*` in `cmd`). `npm` and `npx` are left out when no npm was found.
|
|
85
|
+
*
|
|
86
|
+
* @param {object} options
|
|
87
|
+
* @param {string} options.execPath the Node binary the children run on
|
|
88
|
+
* @param {{ npmCli: string, npxCli: string }|null} options.npm
|
|
89
|
+
* @param {NodeJS.Platform} options.platform
|
|
90
|
+
* @returns {Record<string, string>}
|
|
91
|
+
*/
|
|
92
|
+
export function shimScripts({ execPath, npm, platform }) {
|
|
93
|
+
const targets = { node: [execPath] }
|
|
94
|
+
if (npm) {
|
|
95
|
+
targets.npm = [execPath, npm.npmCli]
|
|
96
|
+
targets.npx = [execPath, npm.npxCli]
|
|
97
|
+
}
|
|
98
|
+
const scripts = {}
|
|
99
|
+
for (const [name, command] of Object.entries(targets)) {
|
|
100
|
+
if (platform === 'win32') {
|
|
101
|
+
scripts[`${name}.cmd`] = `@echo off\r\n${command.map(cmdQuote).join(' ')} %*\r\n`
|
|
102
|
+
} else {
|
|
103
|
+
scripts[name] = `#!/bin/sh\nexec ${command.map(shQuote).join(' ')} "$@"\n`
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return scripts
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Writes the shim folder: a fresh temp folder (never inside a site or the
|
|
111
|
+
* root) holding the scripts of `shimScripts`, executable on POSIX.
|
|
112
|
+
*
|
|
113
|
+
* @param {object} [options]
|
|
114
|
+
* @param {string} [options.execPath]
|
|
115
|
+
* @param {{ npmCli: string, npxCli: string }|null} [options.npm]
|
|
116
|
+
* @param {NodeJS.Platform} [options.platform]
|
|
117
|
+
* @param {string} [options.parent] the folder the shim folder is created in
|
|
118
|
+
* @returns {{ dir: string, npm: boolean, remove: () => void }} `remove` deletes the folder, and may be called more than once
|
|
119
|
+
*/
|
|
120
|
+
export function writeShim({
|
|
121
|
+
execPath = process.execPath,
|
|
122
|
+
npm = npmScripts(execPath),
|
|
123
|
+
platform = process.platform,
|
|
124
|
+
parent = os.tmpdir(),
|
|
125
|
+
} = {}) {
|
|
126
|
+
const dir = mkdtempSync(path.join(parent, 'nera-mcp-runtime-'))
|
|
127
|
+
for (const [name, content] of Object.entries(shimScripts({ execPath, npm, platform }))) {
|
|
128
|
+
writeFileSync(path.join(dir, name), content, { mode: 0o755 })
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
dir,
|
|
132
|
+
npm: Boolean(npm),
|
|
133
|
+
remove: () => rmSync(dir, { recursive: true, force: true }),
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The name of the PATH variable in `env`. On Windows the name is
|
|
139
|
+
* case-insensitive and is usually `Path`; an env object spread from
|
|
140
|
+
* `process.env` keeps that spelling, so it is looked up rather than assumed.
|
|
141
|
+
*
|
|
142
|
+
* @param {Record<string, string|undefined>} env
|
|
143
|
+
* @param {NodeJS.Platform} platform
|
|
144
|
+
* @returns {string}
|
|
145
|
+
*/
|
|
146
|
+
export function pathKey(env, platform = process.platform) {
|
|
147
|
+
if (platform !== 'win32') return 'PATH'
|
|
148
|
+
return Object.keys(env).find((key) => key.toUpperCase() === 'PATH') || 'Path'
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* A copy of `env` with `dir` first on its PATH. On Windows every spelling of
|
|
153
|
+
* the variable is folded into one, so the child does not get two that
|
|
154
|
+
* disagree.
|
|
155
|
+
*
|
|
156
|
+
* @param {Record<string, string|undefined>} env
|
|
157
|
+
* @param {string} dir
|
|
158
|
+
* @param {NodeJS.Platform} [platform]
|
|
159
|
+
* @returns {Record<string, string|undefined>}
|
|
160
|
+
*/
|
|
161
|
+
export function withPathPrefix(env, dir, platform = process.platform) {
|
|
162
|
+
const key = pathKey(env, platform)
|
|
163
|
+
const delimiter = platform === 'win32' ? ';' : ':'
|
|
164
|
+
const result = { ...env }
|
|
165
|
+
if (platform === 'win32') {
|
|
166
|
+
for (const name of Object.keys(result)) {
|
|
167
|
+
if (name.toUpperCase() === 'PATH') delete result[name]
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
result[key] = env[key] ? `${dir}${delimiter}${env[key]}` : dir
|
|
171
|
+
return result
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** @type {string|null} */
|
|
175
|
+
let activeDir = null
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Makes `dir` the shim folder every child is spawned with (`spawnOptions`);
|
|
179
|
+
* null switches that off again.
|
|
180
|
+
*
|
|
181
|
+
* @param {string|null} dir
|
|
182
|
+
*/
|
|
183
|
+
export function activateShim(dir) {
|
|
184
|
+
activeDir = dir
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* The shim folder in use, or null when children get the PATH unchanged.
|
|
189
|
+
*
|
|
190
|
+
* @returns {string|null}
|
|
191
|
+
*/
|
|
192
|
+
export function activeShim() {
|
|
193
|
+
return activeDir
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* What the bin calls at start: under `NERA_MCP_RUNTIME=bundled` it writes the
|
|
198
|
+
* shim folder and activates it; otherwise it does nothing.
|
|
199
|
+
*
|
|
200
|
+
* @param {object} [options]
|
|
201
|
+
* @param {Record<string, string|undefined>} [options.env]
|
|
202
|
+
* @param {Parameters<typeof writeShim>[0]} [options.shim] passed to `writeShim` (tests)
|
|
203
|
+
* @returns {ReturnType<typeof writeShim>|null} the shim, whose `remove` the bin calls on exit
|
|
204
|
+
*/
|
|
205
|
+
export function setupRuntime({ env = process.env, shim } = {}) {
|
|
206
|
+
if (env[RUNTIME_ENV] !== BUNDLED) return null
|
|
207
|
+
const written = writeShim(shim)
|
|
208
|
+
activateShim(written.dir)
|
|
209
|
+
return written
|
|
210
|
+
}
|