@nera-static/core 4.13.0 → 4.15.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/README.md CHANGED
@@ -51,7 +51,7 @@ Two things that are easy to miss:
51
51
 
52
52
  ## 📦 Public API
53
53
 
54
- The package is ESM (`"type": "module"`), requires **Node ≥ 20**, and exposes a barrel at the root plus per-module subpath exports.
54
+ The package is ESM (`"type": "module"`), requires **Node 20.19 or later** (Node 21 excluded), and exposes a barrel at the root plus per-module subpath exports.
55
55
 
56
56
  ```js
57
57
  import { run } from '@nera-static/core'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nera-static/core",
3
- "version": "4.13.0",
3
+ "version": "4.15.0",
4
4
  "description": "The Nera static site generator engine — the build pipeline and the layered theme/view resolver, importable by the Nera CLI, @nera-static/validate and tooling",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
@@ -50,7 +50,7 @@
50
50
  "author": "Michael Becker <micha.becker79@gmail.com> (https://github.com/seebaermichi)",
51
51
  "license": "MIT",
52
52
  "engines": {
53
- "node": ">=20.0.0"
53
+ "node": "^20.19.0 || >=22.0.0"
54
54
  },
55
55
  "repository": {
56
56
  "type": "git",
@@ -61,12 +61,9 @@
61
61
  },
62
62
  "homepage": "https://github.com/seebaermichi/nera#readme",
63
63
  "dependencies": {
64
- "cpy": "^13.2.2",
65
64
  "dotenv": "^18.0.4",
66
65
  "fs-readdir-recursive": "^1.1.0",
67
- "gray-matter": "^4.0.3",
68
66
  "markdown-it": "^15.0.0",
69
- "markdown-it-meta": "^0.0.1",
70
67
  "pretty": "^2.0.0",
71
68
  "pug": "^3.0.2",
72
69
  "rimraf": "^6.0.1",
package/src/core.js CHANGED
@@ -1,11 +1,52 @@
1
1
  import fs from 'fs'
2
2
  import path from 'path'
3
3
  import fsReaddirRecursive from 'fs-readdir-recursive'
4
- import meta from 'markdown-it-meta'
5
4
  import MarkdownIt from 'markdown-it'
6
5
  import yaml from 'yaml'
7
6
 
8
- const md = new MarkdownIt({ html: true }).use(meta)
7
+ // Frontmatter is parsed with `yaml` like every other YAML file Nera reads, set
8
+ // up to match what pages saw under markdown-it-meta/js-yaml 3: unquoted dates
9
+ // become Date objects, `<<` merge keys work, and a repeated key takes the last
10
+ // value. `nera validate` parses the same block, so a page it accepts parses
11
+ // here too.
12
+ const FRONTMATTER_OPTIONS = {
13
+ schema: 'core',
14
+ customTags: ['timestamp'],
15
+ merge: true,
16
+ uniqueKeys: false,
17
+ }
18
+
19
+ // Block rule for a `---` fenced YAML block on the page's first line, replacing
20
+ // markdown-it-meta. The result goes into the per-render `env`, not onto the
21
+ // shared `md` instance: markdown-it-meta's `md.meta` was never reset, so a page
22
+ // without frontmatter inherited the previous page's.
23
+ const frontmatterRule = (state, start, end) => {
24
+ if (start !== 0 || state.blkIndent !== 0 || state.tShift[start] < 0) {
25
+ return false
26
+ }
27
+ const lineAt = (line) =>
28
+ state.src.slice(state.bMarks[line], state.eMarks[line])
29
+ if (lineAt(start) !== '---') {
30
+ return false
31
+ }
32
+
33
+ const data = []
34
+ let line = start
35
+ while (line < end) {
36
+ line++
37
+ if (lineAt(line) === '---' || state.tShift[line] < 0) {
38
+ break
39
+ }
40
+ data.push(lineAt(line))
41
+ }
42
+
43
+ state.env.meta = yaml.parse(data.join('\n'), FRONTMATTER_OPTIONS) || {}
44
+ state.line = line + 1
45
+ return true
46
+ }
47
+
48
+ const md = new MarkdownIt({ html: true })
49
+ md.block.ruler.before('code', 'frontmatter', frontmatterRule, { alt: [] })
9
50
 
10
51
  // Normalise a site's `base_path` (config/app.yaml) into a URL prefix.
11
52
  // Absent/blank/`/` → '' so a root-served site is untouched and renders
@@ -152,7 +193,9 @@ export const getPagesData = (
152
193
 
153
194
  // Read and parse markdown
154
195
  const fileContent = fs.readFileSync(fullPath, 'utf-8')
155
- const content = md.render(fileContent)
196
+ const env = {}
197
+ const content = md.render(fileContent, env)
198
+ const pageMeta = env.meta || {}
156
199
 
157
200
  // Resolve the creation date. Prefer an author/platform-supplied
158
201
  // date from frontmatter — `createdAt`, else `date` — because the
@@ -163,7 +206,7 @@ export const getPagesData = (
163
206
  // frontmatter carries neither key do we fall back to `birthtime`,
164
207
  // which keeps a purely-local build byte-identical to before.
165
208
  // See nera-platform R1 (plans/01) and ROADMAP notes.
166
- let createdAt = md.meta.createdAt || md.meta.date
209
+ let createdAt = pageMeta.createdAt || pageMeta.date
167
210
  if (!createdAt) {
168
211
  try {
169
212
  createdAt = fs.statSync(fullPath).birthtime
@@ -196,7 +239,7 @@ export const getPagesData = (
196
239
  results.push({
197
240
  content,
198
241
  meta: {
199
- ...md.meta,
242
+ ...pageMeta,
200
243
  createdAt,
201
244
  href: wholeFilePathString,
202
245
  fullPath: wholeFilePathString,
package/src/render.js CHANGED
@@ -2,7 +2,6 @@ import fs from 'fs/promises'
2
2
  import fssync from 'fs'
3
3
  import path from 'path'
4
4
  import { createHash } from 'crypto'
5
- import cpy from 'cpy'
6
5
  import pug from 'pug'
7
6
  import pretty from 'pretty'
8
7
  import { rimraf } from 'rimraf'
@@ -335,6 +334,47 @@ export function ignoreFiles(ignoreList, filePath, sourceRoot) {
335
334
  )
336
335
  }
337
336
 
337
+ // OS and editor clutter that never belongs in public/, matched against a file's
338
+ // basename. The list cpy (via the `junk` package) skipped by default; kept so
339
+ // replacing cpy changes nothing a site ships.
340
+ const JUNK =
341
+ /^npm-debug\.log$|^\..*\.swp$|^\.DS_Store$|^\.AppleDouble$|^\.LSOverride$|^Icon\r$|^\._.*|^\.Spotlight-V100(?:$|\/)|\.Trashes|^__MACOSX$|~$|^Thumbs\.db$|^ehthumbs\.db$|^[Dd]esktop\.ini$|@eaDir$/
342
+
343
+ // Every file under `dir`, dotfiles included, junk excluded. Symlinks are
344
+ // followed like cpy's glob did (a linked directory is walked, a dangling link
345
+ // skipped); `seen` stops a link pointing back up the tree from looping.
346
+ const listFiles = async (dir, seen = new Set()) => {
347
+ const real = await fs.realpath(dir)
348
+ if (seen.has(real)) return []
349
+ seen.add(real)
350
+
351
+ const files = []
352
+ for (const entry of await fs.readdir(dir, { withFileTypes: true })) {
353
+ const full = path.join(dir, entry.name)
354
+ let stat = entry
355
+ if (entry.isSymbolicLink()) {
356
+ stat = await fs.stat(full).catch(() => null)
357
+ if (!stat) continue
358
+ }
359
+ if (stat.isDirectory()) {
360
+ files.push(...(await listFiles(full, seen)))
361
+ } else if (stat.isFile() && !JUNK.test(entry.name)) {
362
+ files.push(full)
363
+ }
364
+ }
365
+ return files
366
+ }
367
+
368
+ // Copy one file, creating its directory and keeping its mode and timestamps,
369
+ // as cpy's copy-file did.
370
+ const copyPreserving = async (from, to) => {
371
+ await fs.mkdir(path.dirname(to), { recursive: true })
372
+ await fs.copyFile(from, to)
373
+ const { atime, mtime, mode } = await fs.stat(from)
374
+ await fs.utimes(to, atime, mtime)
375
+ await fs.chmod(to, mode)
376
+ }
377
+
338
378
  // `ignoreBase` is the directory to read `.neraignore` from:
339
379
  // - omitted → the source's parent (back-compat with the pre-theme layout,
340
380
  // where `assets/` sat at the site root so its parent *was* the root)
@@ -349,13 +389,13 @@ export const copyFolder = async (sourceFolder, targetFolder, ignoreBase) => {
349
389
  const ignore = base === null ? [] : getIgnoredFiles(base)
350
390
 
351
391
  try {
352
- await cpy([`${sourceFolder}/**/*`], targetFolder, {
353
- parents: true,
354
- // Dotfiles (.htaccess, .well-known/) are site payload too;
355
- // anything unwanted is excluded via .neraignore.
356
- dot: true,
357
- filter: (file) => ignoreFiles(ignore, file.path, sourceFolder),
358
- })
392
+ for (const file of await listFiles(sourceFolder)) {
393
+ if (!ignoreFiles(ignore, file, sourceFolder)) continue
394
+ await copyPreserving(
395
+ file,
396
+ path.join(targetFolder, path.relative(sourceFolder, file))
397
+ )
398
+ }
359
399
  console.log(SUCCESS_COLOR, 'Assets copied')
360
400
  } catch (err) {
361
401
  console.error('Copy failed:', err)