@nera-static/plugin-utils 1.6.1 → 1.8.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/CHANGELOG.md +303 -0
- package/LICENSE +1 -1
- package/README.md +538 -8
- package/index.js +20 -31
- package/package.json +22 -6
- package/src/config.js +160 -0
- package/src/dates.js +155 -0
- package/src/frontmatter.js +50 -0
- package/src/glob.js +79 -0
- package/src/guard.js +105 -0
- package/src/html.js +76 -0
- package/src/lang.js +103 -0
- package/src/log.js +29 -0
- package/src/packages.js +143 -0
- package/src/pages.js +34 -0
- package/src/sort.js +38 -0
- package/src/urls.js +243 -0
- package/src/values.js +44 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.8.0] - 2026-11-27
|
|
9
|
+
|
|
10
|
+
The second half of the helpers Nera plugins, core and the tools copy from
|
|
11
|
+
each other: languages, dates, URLs and `base_path`, escaping, frontmatter,
|
|
12
|
+
glob matching, package names and page selection. Each subpath is written
|
|
13
|
+
once from the best sibling variant and documented in the README under
|
|
14
|
+
"Shared helpers". Nothing in `.` or in the 1.7.0 subpaths changed, and no
|
|
15
|
+
runtime dependency was added (still `js-yaml` only).
|
|
16
|
+
|
|
17
|
+
If you replace a local copy with one of these, check the shapes below: several
|
|
18
|
+
differ from what some siblings return today.
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
- **`@nera-static/plugin-utils/html`**: `escapeHtml` (`& < > " '`, `'` as
|
|
23
|
+
`'`), `escapeXml` (`'` as `'`, and the characters XML 1.0 forbids
|
|
24
|
+
even escaped are dropped) and `escapeRegExp`. Every escaper takes any
|
|
25
|
+
value: `null` and `undefined` give `''`, so `escapeHtml(null)` is `''`, not
|
|
26
|
+
`'null'`
|
|
27
|
+
- **`@nera-static/plugin-utils/lang`**: `siteLang(app, fallback = 'en')`,
|
|
28
|
+
`pageLang(meta, app, fallback = 'en')`, `siteLanguages(app)`,
|
|
29
|
+
`isLanguageMap(value, languages)` and `localize(value, lang, { fallbacks,
|
|
30
|
+
any })`. Languages are trimmed and a blank one counts as absent, so
|
|
31
|
+
`lang: 'de '` is `de`. `localize` returns `null` (not `undefined`) when no
|
|
32
|
+
entry fits
|
|
33
|
+
- **`@nera-static/plugin-utils/dates`**: `toDate(value)`, `formatW3C(value)`,
|
|
34
|
+
`pageDate(meta, 'published' | 'updated', { warn })`, `byDate(get, {
|
|
35
|
+
descending })` and the frozen key lists `PUBLISHED_KEYS` (`date`,
|
|
36
|
+
`datePublished`, `published`) and `UPDATED_KEYS` (`updated`, `updatedAt`,
|
|
37
|
+
`lastmod`, `dateModified`). **`createdAt` is never read**: core fills it
|
|
38
|
+
from the file's birth time, which CI stamps alike for every file. A time
|
|
39
|
+
without an offset is read as UTC, an impossible day such as `2026-02-30` is
|
|
40
|
+
no date, and only `Z` and `±hh:mm` offsets are accepted (`+0200` is not).
|
|
41
|
+
`pageDate` takes the first valid key and warns once per invalid value;
|
|
42
|
+
`byDate` puts items without a date last in both directions
|
|
43
|
+
- **`@nera-static/plugin-utils/sort`**: `byString` and `byHref`, comparing
|
|
44
|
+
code units instead of `localeCompare`, so the order is the same on every
|
|
45
|
+
machine
|
|
46
|
+
- **`@nera-static/plugin-utils/urls`**: `resolveOrigin({ cwd, app })`
|
|
47
|
+
(`app.origin`, else canonical-links' `app_origin`, trimmed),
|
|
48
|
+
`encodePath`, `joinUrl` and `siteUrl` (percent-encoded, so a canonical
|
|
49
|
+
link and a sitemap URL of a page are the same string),
|
|
50
|
+
`normalizeBasePath`, `withBasePath` and `stripBasePath` (core's exact
|
|
51
|
+
`base_path` rules), `hasScheme`, `isInside(root, target, { self })` (a
|
|
52
|
+
child folder named `..foo` is inside), and `srcsetUrls`/`mapSrcset`. The
|
|
53
|
+
`srcset` helpers follow the HTML candidate rule, where a URL ends at
|
|
54
|
+
whitespace: `/a.jpg?w=1,2` and data URIs stay whole, unlike splitting on
|
|
55
|
+
commas
|
|
56
|
+
- **`@nera-static/plugin-utils/frontmatter`**: `FRONTMATTER_OPTIONS`, core's
|
|
57
|
+
frozen `yaml` options (`timestamp`, `<<` merge, last duplicate key wins),
|
|
58
|
+
and `splitFrontmatter(raw)` → `{ yamlText, body }` by core's fence rule
|
|
59
|
+
(`----` and `--- ` are no fences, an unclosed block is YAML to the end).
|
|
60
|
+
It returns `null` when the file has no frontmatter
|
|
61
|
+
- **`@nera-static/plugin-utils/glob`**: `matchesPattern` and `matchesAny`
|
|
62
|
+
(the `*` glob of the sitemap and feed `exclude` lists), and, mirroring
|
|
63
|
+
core's `.neraignore` handling, `IGNORE_FILE`, `readIgnoreList(cwd)` and
|
|
64
|
+
`isIgnoredAsset(list, file, root)` (`true` means skipped)
|
|
65
|
+
- **`@nera-static/plugin-utils/packages`** gains the package-name rules:
|
|
66
|
+
`isPluginPackage(name)` (core's plugin discovery), `pluginShortName(name)`,
|
|
67
|
+
`pluginPackage(spec)`, which returns `{ name, pkg }` and throws a
|
|
68
|
+
`TypeError` for an invalid spec, and `themePackage(spec)` (core's rule,
|
|
69
|
+
`null` for a local or blank spec)
|
|
70
|
+
- **`@nera-static/plugin-utils/pages`**: `isRenderedPage(meta)` (non-blank
|
|
71
|
+
`layout` and `href`) and `isNoindex(meta, app)` (`noindex` in the page's
|
|
72
|
+
`robots`, else the site's)
|
|
73
|
+
|
|
74
|
+
## [1.7.0] - 2026-11-27
|
|
75
|
+
|
|
76
|
+
The helpers that Nera plugins, core and the tools copy from each other now
|
|
77
|
+
live here, one subpath export per family. Nothing in `.` changed, and no
|
|
78
|
+
dependency was added (still `js-yaml` only). Each subpath is documented in
|
|
79
|
+
the README under "Shared helpers".
|
|
80
|
+
|
|
81
|
+
### Added
|
|
82
|
+
|
|
83
|
+
- **`@nera-static/plugin-utils/values`**: `isPlainObject(value)` (prototype
|
|
84
|
+
`Object.prototype` or `null`; arrays, `Date`, `Map` and class instances
|
|
85
|
+
are not plain), `isText(value)` (a string with a non-whitespace
|
|
86
|
+
character) and `textOr(value, fallback)` (the trimmed string, else
|
|
87
|
+
`fallback`)
|
|
88
|
+
- **`@nera-static/plugin-utils/log`**: `createLogger(name, { sink })` with
|
|
89
|
+
`warn`, `info` and the page-scoped `page(page, what, todo)`, printing
|
|
90
|
+
`⚠️ <name>: …` (`ℹ️ ` for `info`)
|
|
91
|
+
- **`@nera-static/plugin-utils/config`**: `getConfig` (the same function as
|
|
92
|
+
in `.`), `loadPluginConfig(name, { cwd, app })`, which honours
|
|
93
|
+
`app.folders.config`, and `createConfigReader({ file, defaults, readers,
|
|
94
|
+
warn })` with the fleet's one message set and a date-aware `show()`.
|
|
95
|
+
Unknown keys are found with `Object.hasOwn`, so a YAML key
|
|
96
|
+
`constructor:` or `toString:` now warns as unknown instead of slipping
|
|
97
|
+
into the config, as it did in every plugin's own reader
|
|
98
|
+
- **`@nera-static/plugin-utils/packages`**: `requireFromSite(cwd)`, a
|
|
99
|
+
`require` that resolves from the site root, and
|
|
100
|
+
`ownVersion(import.meta.url)`, the calling package's version
|
|
101
|
+
- **`@nera-static/plugin-utils/guard`**: `assertCoreVersion({ plugin, need,
|
|
102
|
+
why, cwd, from, version, hint })`, `coreVersion({ cwd, from })`,
|
|
103
|
+
`satisfiesFloor(version, floor)` (a prerelease sorts below its release)
|
|
104
|
+
and `GET_ASSETS_CORE` (`'4.13.0'`), the core version guard five plugins
|
|
105
|
+
carried as identical copies. The optional `hint` is appended after the
|
|
106
|
+
update advice, for a plugin-specific way out such as code-blocks'
|
|
107
|
+
"Or set `assets: false` in config/code-blocks.yaml."
|
|
108
|
+
- **`CHANGELOG.md` is part of the published package**
|
|
109
|
+
|
|
110
|
+
### Changed
|
|
111
|
+
|
|
112
|
+
- **every built-in module is imported with the `node:` prefix**, enforced by
|
|
113
|
+
a lint rule; the README examples follow it
|
|
114
|
+
|
|
115
|
+
### Fixed
|
|
116
|
+
|
|
117
|
+
- **`resolveViewsDir` and `resolveAssetsDir` (and so `publishTemplates`,
|
|
118
|
+
`publishAllTemplates` and `publishAsset`) now follow core's `themeOnly`
|
|
119
|
+
rule.** On a site whose `config/app.yaml` sets `theme:` and which has
|
|
120
|
+
neither a `theme/` nor a root `views/` folder, they resolved to the
|
|
121
|
+
deprecated root `views/` / `assets/`; core uses `theme/views` /
|
|
122
|
+
`theme/assets` there. `npm run publish-template` therefore wrote
|
|
123
|
+
`views/vendor/…`, and the new root `views/` switched the build into the
|
|
124
|
+
deprecated layout. Both now return the `theme/` folder, as core does
|
|
125
|
+
- **an explicit blank `folders.views: ''` or `folders.assets: ''` in
|
|
126
|
+
`config/app.yaml` is kept, as core keeps it**: it is the site root. The
|
|
127
|
+
helpers ignored a blank value and fell back to `theme/<key>` or the root
|
|
128
|
+
`<key>/`, so `publishTemplates` wrote where the build does not look
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
## [1.6.1] - 2026-10-08
|
|
132
|
+
|
|
133
|
+
Documentation only — no code changed.
|
|
134
|
+
|
|
135
|
+
### Fixed
|
|
136
|
+
|
|
137
|
+
- **`README.md` Compatibility still listed `js-yaml ^4.1.0`** as the runtime
|
|
138
|
+
dependency; 1.6.0 moved to `js-yaml ^5.2.2`.
|
|
139
|
+
- **The `bin/publish-template.js` example put a comment above the
|
|
140
|
+
`#!/usr/bin/env node` line.** A hashbang is only valid as the very first
|
|
141
|
+
line, so a script copied verbatim failed with a `SyntaxError`.
|
|
142
|
+
- **"Themed site" is now defined where the publish destination is
|
|
143
|
+
described** — a site with a local `theme/` folder, which is what
|
|
144
|
+
`nera new` scaffolds — so plugin authors know which destination their
|
|
145
|
+
users get
|
|
146
|
+
|
|
147
|
+
## [1.6.0] - 2026-07-27
|
|
148
|
+
|
|
149
|
+
### Changed
|
|
150
|
+
|
|
151
|
+
- **js-yaml 4 → 5.** `getConfig` returns the same shapes it always did for
|
|
152
|
+
every construct a Nera config uses — verified by parsing all 96 YAML files
|
|
153
|
+
across the ecosystem under both versions and diffing the results. One
|
|
154
|
+
difference is worth knowing about: a bare date scalar (`published:
|
|
155
|
+
2026-07-27`) now parses as the string `'2026-07-27'` rather than a `Date`.
|
|
156
|
+
No packaged plugin config declares a date field, so this only affects you
|
|
157
|
+
if you put one in your own `config/<plugin>.yaml` and relied on getting a
|
|
158
|
+
`Date` back
|
|
159
|
+
|
|
160
|
+
### Fixed
|
|
161
|
+
|
|
162
|
+
- **a config file containing only comments no longer throws.** js-yaml 5
|
|
163
|
+
rejects a document with no content, where 4 returned `undefined`. Plugins
|
|
164
|
+
ship their config with every key commented out — that is how the defaults
|
|
165
|
+
are documented — so upgrading would have crashed the build of any site
|
|
166
|
+
that copied one of those files verbatim. Such a file is now treated as an
|
|
167
|
+
absent config and yields `{}`, as before. The same applies to an empty or
|
|
168
|
+
whitespace-only file. Genuinely malformed YAML still throws
|
|
169
|
+
|
|
170
|
+
## [1.5.0] - 2026-07-24
|
|
171
|
+
|
|
172
|
+
### Added
|
|
173
|
+
|
|
174
|
+
- **`resolveViewsDir(cwd?)`** and **`resolveAssetsDir(cwd?)`** — return the
|
|
175
|
+
project's presentation directories the same way the generator does
|
|
176
|
+
(`core.js`): an explicit `folders.<key>` in `config/app.yaml` wins;
|
|
177
|
+
otherwise `theme/views` / `theme/assets` when a local `theme/` folder
|
|
178
|
+
exists; otherwise the deprecated root `views/` / `assets/`
|
|
179
|
+
|
|
180
|
+
- **`publishAsset({ sourceFile, targetPath, force?, expectedPackageName? })`**
|
|
181
|
+
— publishes a single support file (e.g. a plugin's client script) into the
|
|
182
|
+
resolved assets folder, theme-aware, with the same skip-if-exists rule as
|
|
183
|
+
`publishTemplates`. Plugins that ship a runtime asset alongside their
|
|
184
|
+
templates (`plugin-search`, `plugin-contact-form`) should copy it through
|
|
185
|
+
here instead of a hand-rolled root `assets/` copy
|
|
186
|
+
|
|
187
|
+
### Changed
|
|
188
|
+
|
|
189
|
+
- **`publishTemplates` / `publishAllTemplates` now publish theme-aware.** The
|
|
190
|
+
destination is `resolveViewsDir()/vendor/<plugin>` rather than a hardcoded
|
|
191
|
+
root `views/vendor/<plugin>`. On a themed site (a local `theme/` folder, so
|
|
192
|
+
the build renders from `theme/views`) templates now land in
|
|
193
|
+
`theme/views/vendor/…`, where the generator's layered resolver actually
|
|
194
|
+
looks — publishing to root `views/vendor/` left the includes silently
|
|
195
|
+
resolving to nothing. Sites with no `theme/` folder are unchanged, so this
|
|
196
|
+
is additive rather than breaking
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
## [1.4.0] - 2026-07-22
|
|
200
|
+
|
|
201
|
+
### Added
|
|
202
|
+
|
|
203
|
+
- **`slugify(text)`** — turns a user-authored string into a URL-safe slug,
|
|
204
|
+
for anything that becomes a path segment, an HTML `id`, or a URL fragment.
|
|
205
|
+
`ß` → `ss`, NFKD with combining marks dropped, lowercase, runs of
|
|
206
|
+
non-alphanumerics collapsed to a single `-`, leading and trailing hyphens
|
|
207
|
+
trimmed. Idempotent; returns `''` when nothing usable remains
|
|
208
|
+
|
|
209
|
+
It lives here because two plugins had already written it independently and
|
|
210
|
+
only one got it right. The naive rule, `[^\w]+` → `-`, is ASCII-only:
|
|
211
|
+
`Über uns` becomes `-ber-uns` and `Straße` becomes `stra-e`. A leading
|
|
212
|
+
hyphen is legal in an HTML `id` but is **not a valid CSS identifier**, so
|
|
213
|
+
`#-ber-uns` matches nothing in a stylesheet and `querySelector` throws on
|
|
214
|
+
it. That shipped in `plugin-one-page` until its v3.0.0
|
|
215
|
+
|
|
216
|
+
Purely additive — no existing export changed. `plugin-tags`' `slugifyTag`
|
|
217
|
+
and `plugin-one-page`'s internal helper both delegate here as of
|
|
218
|
+
`plugin-tags` 3.2.1 and `plugin-one-page` 3.0.1, and both keep producing
|
|
219
|
+
byte-identical output; their test suites are reproduced here to prove it
|
|
220
|
+
|
|
221
|
+
## [1.3.1] - 2026-07-21
|
|
222
|
+
|
|
223
|
+
### Fixed
|
|
224
|
+
|
|
225
|
+
- corrected the "Example Plugin Structure" snippet in the README, which
|
|
226
|
+
taught the plugin contract wrongly in three ways: it used the signature
|
|
227
|
+
`getAppData(app)` instead of `getAppData(data)`, returned a bare object
|
|
228
|
+
instead of spreading `...data.app` (which silently discards every other
|
|
229
|
+
plugin's `app` data sitewide), and resolved config against `__dirname`,
|
|
230
|
+
which is undefined in ESM and points at the package rather than the
|
|
231
|
+
user's site
|
|
232
|
+
- documented that `getConfig` returns `{}` for a missing or empty file and
|
|
233
|
+
never throws, so plugins must supply a JS fallback for every key
|
|
234
|
+
- corrected `validateNeraProject`'s description: a `package.json` is
|
|
235
|
+
required unconditionally; the shape check is an alternative to the *name*
|
|
236
|
+
check, not to having a `package.json`
|
|
237
|
+
- documented that `publishAllTemplates` returns `true` when `sourceDir`
|
|
238
|
+
contains no `.pug` files, so a misconfigured publish script exits `0`
|
|
239
|
+
having copied nothing
|
|
240
|
+
|
|
241
|
+
### Added
|
|
242
|
+
|
|
243
|
+
- `## 🧩 Compatibility`, `## 🧪 Development` and `## 🤝 Contributing`
|
|
244
|
+
sections; the Node requirement was previously stated nowhere
|
|
245
|
+
|
|
246
|
+
### Changed
|
|
247
|
+
|
|
248
|
+
- License heading uses the fleet-standard `## 📦 License`
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
## [1.3.0] - 2026-07-21
|
|
252
|
+
|
|
253
|
+
### Changed
|
|
254
|
+
|
|
255
|
+
- raised minimum Node from 18 to 20; Node 18 reached end-of-life on
|
|
256
|
+
2025-04-30 and the dev toolchain requires Node 20+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
## [1.2.0] - 2026-07-19
|
|
260
|
+
|
|
261
|
+
### Fixed
|
|
262
|
+
|
|
263
|
+
- `publishAllTemplates` now publishes templates in subdirectories.
|
|
264
|
+
Plugins whose views use `partials/` or `helper/` previously shipped
|
|
265
|
+
top-level templates that could not compile
|
|
266
|
+
- `publishTemplates` no longer reports success when a source template
|
|
267
|
+
is missing. Sources are now all verified before anything is copied,
|
|
268
|
+
so a failure cannot leave a partially published destination
|
|
269
|
+
|
|
270
|
+
### Added
|
|
271
|
+
|
|
272
|
+
- `force` option on `publishTemplates` and `publishAllTemplates` to
|
|
273
|
+
re-publish over an existing `views/vendor/<plugin>/` directory. The
|
|
274
|
+
default remains skip-if-exists, so local edits are never discarded
|
|
275
|
+
unless explicitly requested
|
|
276
|
+
- `validateNeraProject` now also accepts any directory containing both
|
|
277
|
+
`config/app.yaml` and `pages/`, so projects not named `nera*` work.
|
|
278
|
+
The existing package-name check is retained as an alternative
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
## [1.1.0] - 2025-07-19
|
|
282
|
+
|
|
283
|
+
### Added
|
|
284
|
+
|
|
285
|
+
- `publishAllTemplates` for publishing every `.pug` file in a plugin's
|
|
286
|
+
views directory without listing them individually
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
## [1.0.5] - 2025-07-14
|
|
290
|
+
|
|
291
|
+
## [1.0.4] - 2025-07-13
|
|
292
|
+
|
|
293
|
+
## [1.0.3] - 2025-07-11
|
|
294
|
+
|
|
295
|
+
## [1.0.2] - 2025-07-11
|
|
296
|
+
|
|
297
|
+
## [1.0.1] - 2025-07-11
|
|
298
|
+
|
|
299
|
+
## [1.0.0] - 2025-07-11
|
|
300
|
+
|
|
301
|
+
Releases up to and including 1.0.5 pre-date this changelog. Dates are
|
|
302
|
+
taken from the npm registry; per-release contents were not recorded at
|
|
303
|
+
the time and have not been reconstructed here.
|
package/LICENSE
CHANGED