@matra/site-generation 0.2.1 → 0.4.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.ja.md CHANGED
@@ -87,14 +87,17 @@ console.log(`Generated ${outputs.length} files`)
87
87
 
88
88
  両APIはlayout、asset、base path、再利用可能なMatra部品に対応します。
89
89
  Matra部品は`fn Name(props, children) { ... }`で定義し、単一の文書nodeを返します。
90
- 子要素なしの呼び出しは`Name(props, [])`と書きます。第2引数の省略には、公開済みの
91
- Core `0.3.1`より新しいruntimeが必要です。
90
+ 子要素なしの呼び出しは`Name(props)`または`Name(props, [])`と書きます。
92
91
  設定schema、入力規則、部品の動作、出力保証の詳細は
93
92
  [サイト生成の契約](../../spec/site-generation.ja.md)を参照してください。
94
93
 
94
+ HTML出力では子要素の配列を再帰的に平坦化するため、条件分岐などが返す配列に`...`は不要です。
95
+ `if`の分岐は最後の式の値だけを返すため、複数の要素を出力するときは配列にまとめます。
96
+ 文書値の配列構造は保持されますが、従来JSONとして表示されていた子配列のHTML出力は変わります。
97
+
95
98
  ## Markdownとブログの出力
96
99
 
97
- 既定のMarkdown変換はそのままです。site-generation `0.2.x`で、サイトに`npm install @matra/markdown-unified@^0.1.0`し、
100
+ 既定のMarkdown変換はそのままです。site-generation `0.4.x`で、サイトに`npm install @matra/markdown-unified@^0.1.3`し、
98
101
  `markdown: "unified"`(ファイル設定では`site.markdown`)を指定すると、
99
102
  YAML frontmatter・GFM・数式(MathML)・見出しID・目次・抜粋を利用できます。
100
103
  目次は`page.data.toc`、抜粋は`page.data.excerpt`から参照できます。
package/README.md CHANGED
@@ -90,16 +90,19 @@ link validation, page data and content, routes, and output management are unaffe
90
90
 
91
91
  Both APIs support layouts, assets, a base path, and reusable Matra components.
92
92
  Matra components are defined as `fn Name(props, children) { ... }` and return
93
- one document node. Use `Name(props, [])` when there are no children; omitting the
94
- second argument requires a newer Core runtime than the published `0.3.1`. See the
93
+ one document node. Use `Name(props)` or `Name(props, [])` when there are no children. See the
95
94
  [site-generation contract](../../spec/site-generation.md)
96
95
  for the complete configuration schema, input rules, component behavior, and
97
96
  output guarantees.
98
97
 
98
+ HTML output recursively flattens child arrays, so arrays returned by conditional expressions do not need `...`.
99
+ An `if` branch returns only its last expression, so group multiple elements in an array.
100
+ The document value retains its array structure, but child arrays previously rendered as JSON produce different HTML.
101
+
99
102
  ## Markdown and blog outputs
100
103
 
101
104
  The default Markdown behavior is unchanged. For frontmatter, GFM, math, heading IDs, TOC and
102
- excerpts, use site-generation `0.2.x` and install the [optional unified preset](../markdown-unified/README.md) (`@matra/markdown-unified@^0.1.0`) in the site
105
+ excerpts, use site-generation `0.4.x` and install the [optional unified preset](../markdown-unified/README.md) (`@matra/markdown-unified@^0.1.3`) in the site
103
106
  and set `markdown: "unified"` (under `site` in file configuration).
104
107
  `generateSite({ markdown: async ({ body, document, metadata }) => ..., ... })` also accepts a
105
108
  custom hook returning a node sequence or `{ content: nodes, data: derivedFields }`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matra/site-generation",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "Declarative static site generation for Matra",
5
5
  "type": "module",
6
6
  "exports": {
@@ -10,8 +10,8 @@
10
10
  "src"
11
11
  ],
12
12
  "dependencies": {
13
- "@matra/core": "^0.3.1",
14
- "@matra/html": "^0.3.1",
13
+ "@matra/core": "^0.4.0",
14
+ "@matra/html": "^0.4.1",
15
15
  "js-yaml": "^5.2.2",
16
16
  "markdown-it": "^14.3.0"
17
17
  },
package/src/site.mjs CHANGED
@@ -195,7 +195,7 @@ function warnDiscardedNodes(entry) {
195
195
  for (const statement of branch.slice(0, -1)) {
196
196
  if (statement.kind === "expression" && statement.expression.kind === "node") {
197
197
  console.warn(
198
- `${entry.document}: if branch discards <${statement.expression.tag}>. Use ...if with an array to emit multiple nodes.`,
198
+ `${entry.document}: if branch discards <${statement.expression.tag}>. Return an array to emit multiple nodes.`,
199
199
  )
200
200
  }
201
201
  }
@@ -1014,13 +1014,12 @@ function resolveMarkdownLink(href, kind, document, settings, location) {
1014
1014
 
1015
1015
  function assertCompleteDocument(ast, source) {
1016
1016
  if (ast.tag !== "html") throw new TypeError(`${source}: generated page must have one html root`)
1017
- const heads = ast.children.filter(
1018
- child => child && typeof child === "object" && child.tag === "head",
1019
- )
1020
- const bodies = ast.children.filter(
1017
+ const children = ast.children.flat(Infinity)
1018
+ const heads = children.filter(child => child && typeof child === "object" && child.tag === "head")
1019
+ const bodies = children.filter(
1021
1020
  child => child && typeof child === "object" && child.tag === "body",
1022
1021
  )
1023
- if (heads.length !== 1 || bodies.length !== 1 || ast.children.length !== 2) {
1022
+ if (heads.length !== 1 || bodies.length !== 1 || children.length !== 2) {
1024
1023
  throw new TypeError(`${source}: generated html must contain exactly one head and one body`)
1025
1024
  }
1026
1025
  }