mikser-io 11.9.0 → 11.10.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.
@@ -1065,6 +1065,7 @@ distinction is the whole of [Faults](#faults) above.
1065
1065
  | Code | Severity | Means |
1066
1066
  | --- | --- | --- |
1067
1067
  | `source-content-not-text` | warn | A `sources()` collection with `content: true` loaded a file whose bytes are not text. They are decoded as UTF-8 and stored mangled, and every consumer inherits that. Set `content: false` to catalogue the files by path instead — `entity.uri` still points at them. Once per collection. |
1068
+ | `front-matter-unreadable` | warn | A file's front-matter block is present but not valid YAML. Its attributes are not available and the text is left as written. Previously this threw and ended the whole run with a parser stack that never named the file. |
1068
1069
  | `observer-bad-uri` | warn | An observer's `uri` is not an absolute URL, so no webhook can be routed to it. |
1069
1070
  | `untracked-file-read` | warn | A template read a file outside every folder mikser takes entities from, so it has no entity and changing it invalidates nothing. |
1070
1071
  | `progress` | info | A long phase reporting where it has got to. See [Progress](#progress). |
package/index.js CHANGED
@@ -57,7 +57,7 @@ export { commands } from './src/plugins/commands.js'
57
57
  export { data } from './src/plugins/data.js'
58
58
  export { documents } from './src/plugins/documents.js'
59
59
  export { files } from './src/plugins/files.js'
60
- export { frontMatter } from './src/plugins/front-matter.js'
60
+ export { frontMatter, readFrontMatter } from './src/plugins/front-matter.js'
61
61
  export { json } from './src/plugins/json.js'
62
62
  // layouts moved to sibling: import from 'mikser-io-layouts'
63
63
  export { mapper } from './src/plugins/mapper.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mikser-io",
3
- "version": "11.9.0",
3
+ "version": "11.10.0",
4
4
  "files": [
5
5
  "app.js",
6
6
  "index.js",
@@ -1,5 +1,28 @@
1
1
  import fm from 'front-matter'
2
2
 
3
+ // Read front matter out of a string.
4
+ //
5
+ // Exported because more than one place needs the answer and a second
6
+ // implementation would drift from this one. mikser-io-layouts calls it when
7
+ // it has to fall back to a layout as SYNCED — the file before this plugin has
8
+ // lifted its attributes out — and handing that raw text to a renderer is a
9
+ // bug with two faces: Handlebars emitted the YAML into the page, and LiquidJS
10
+ // refuses to parse it at all, failing at the front-matter line and taking the
11
+ // layout down with it.
12
+ //
13
+ // Returns { attributes, body }, or null when there is no front matter or it
14
+ // cannot be parsed. Never throws: a malformed block is the author's problem
15
+ // to see, not the build's to die on.
16
+ export function readFrontMatter(content) {
17
+ if (typeof content !== 'string' || !fm.test(content)) return null
18
+ try {
19
+ const info = fm(content)
20
+ return info?.attributes ? { attributes: info.attributes, body: info.body } : null
21
+ } catch (err) {
22
+ return { error: err.message }
23
+ }
24
+ }
25
+
3
26
  export function frontMatter(options = {}) {
4
27
  return ({
5
28
  onProcess,
@@ -10,14 +33,25 @@ export function frontMatter(options = {}) {
10
33
  onProcess(async () => {
11
34
  const logger = useLogger()
12
35
  for await (let { entity } of useJournal('Front matter', [OPERATION.CREATE, OPERATION.UPDATE])) {
13
- if (entity.content && fm.test(entity.content)) {
14
- const info = fm(entity.content)
15
- if (info.attributes) {
16
- entity.meta = Object.assign(entity.meta || {}, info.attributes)
17
- entity.content = info.body
18
- logger.trace('Front matter %s: %s', entity.collection, entity.id)
19
- }
36
+ const parsed = readFrontMatter(entity.content)
37
+ if (!parsed) continue
38
+ if (parsed.error) {
39
+ // Was an uncaught throw, which ended the RUN: js-yaml's
40
+ // exception went up through the journal loop and out of
41
+ // the process, printing a stack that named js-yaml and
42
+ // front-matter and not one word about which file. One
43
+ // mistyped line in one document stopped every other
44
+ // document from building, and left the author reading a
45
+ // parser's internals to find out where.
46
+ logger.warn(
47
+ { code: 'front-matter-unreadable', id: entity.id, collection: entity.collection },
48
+ 'Front matter in %s could not be parsed, so it is left as written and its attributes '
49
+ + 'are not available: %s', entity.id, parsed.error)
50
+ continue
20
51
  }
52
+ entity.meta = Object.assign(entity.meta || {}, parsed.attributes)
53
+ entity.content = parsed.body
54
+ logger.trace('Front matter %s: %s', entity.collection, entity.id)
21
55
  }
22
56
  })
23
57