@matra/site-generation 0.2.0 → 0.3.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 +11 -1
- package/README.md +13 -2
- package/package.json +2 -2
- package/src/site.mjs +22 -13
package/README.ja.md
CHANGED
|
@@ -81,14 +81,24 @@ console.log(`Generated ${outputs.length} files`)
|
|
|
81
81
|
(`layout: false`で無効化可能)、diagnosticと相対link解決に使う論理文書pathを
|
|
82
82
|
指定します。`layouts`と`components`は名前から`{ source, document? }`へのmapです。
|
|
83
83
|
|
|
84
|
+
テンプレートとlayoutが`site.documents`を使わない場合、
|
|
85
|
+
`includeDocumentsInTemplates: false`を指定すると空配列を渡し、描画時の全文書一覧のコピーを避けます。
|
|
86
|
+
既定値は`true`です。Markdown変換、リンク検証、ページのdataとcontent、route、出力管理は変わりません。
|
|
87
|
+
|
|
84
88
|
両APIはlayout、asset、base path、再利用可能なMatra部品に対応します。
|
|
85
89
|
Matra部品は`fn Name(props, children) { ... }`で定義し、単一の文書nodeを返します。
|
|
90
|
+
子要素なしの呼び出しは`Name(props, [])`と書きます。第2引数の省略には、公開済みの
|
|
91
|
+
Core `0.3.1`より新しいruntimeが必要です。
|
|
86
92
|
設定schema、入力規則、部品の動作、出力保証の詳細は
|
|
87
93
|
[サイト生成の契約](../../spec/site-generation.ja.md)を参照してください。
|
|
88
94
|
|
|
95
|
+
HTML出力では子要素の配列を再帰的に平坦化するため、条件分岐などが返す配列に`...`は不要です。
|
|
96
|
+
`if`の分岐は最後の式の値だけを返すため、複数の要素を出力するときは配列にまとめます。
|
|
97
|
+
文書値の配列構造は保持されますが、従来JSONとして表示されていた子配列のHTML出力は変わります。
|
|
98
|
+
|
|
89
99
|
## Markdownとブログの出力
|
|
90
100
|
|
|
91
|
-
既定のMarkdown変換はそのままです。site-generation `0.
|
|
101
|
+
既定のMarkdown変換はそのままです。site-generation `0.3.x`で、サイトに`npm install @matra/markdown-unified@^0.1.2`し、
|
|
92
102
|
`markdown: "unified"`(ファイル設定では`site.markdown`)を指定すると、
|
|
93
103
|
YAML frontmatter・GFM・数式(MathML)・見出しID・目次・抜粋を利用できます。
|
|
94
104
|
目次は`page.data.toc`、抜粋は`page.data.excerpt`から参照できます。
|
package/README.md
CHANGED
|
@@ -83,16 +83,27 @@ data, select a layout (or disable it with `layout: false`), and set the
|
|
|
83
83
|
logical document path used for diagnostics and relative links. `layouts` and
|
|
84
84
|
`components` map names to `{ source, document? }` objects.
|
|
85
85
|
|
|
86
|
+
When templates and layouts do not use `site.documents`, set
|
|
87
|
+
`includeDocumentsInTemplates: false` to pass them an empty array and avoid copying
|
|
88
|
+
the full document list during rendering. The default is `true`. Markdown conversion,
|
|
89
|
+
link validation, page data and content, routes, and output management are unaffected.
|
|
90
|
+
|
|
86
91
|
Both APIs support layouts, assets, a base path, and reusable Matra components.
|
|
87
92
|
Matra components are defined as `fn Name(props, children) { ... }` and return
|
|
88
|
-
one document node.
|
|
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
|
|
95
|
+
[site-generation contract](../../spec/site-generation.md)
|
|
89
96
|
for the complete configuration schema, input rules, component behavior, and
|
|
90
97
|
output guarantees.
|
|
91
98
|
|
|
99
|
+
HTML output recursively flattens child arrays, so arrays returned by conditional expressions do not need `...`.
|
|
100
|
+
An `if` branch returns only its last expression, so group multiple elements in an array.
|
|
101
|
+
The document value retains its array structure, but child arrays previously rendered as JSON produce different HTML.
|
|
102
|
+
|
|
92
103
|
## Markdown and blog outputs
|
|
93
104
|
|
|
94
105
|
The default Markdown behavior is unchanged. For frontmatter, GFM, math, heading IDs, TOC and
|
|
95
|
-
excerpts, use site-generation `0.
|
|
106
|
+
excerpts, use site-generation `0.3.x` and install the [optional unified preset](../markdown-unified/README.md) (`@matra/markdown-unified@^0.1.2`) in the site
|
|
96
107
|
and set `markdown: "unified"` (under `site` in file configuration).
|
|
97
108
|
`generateSite({ markdown: async ({ body, document, metadata }) => ..., ... })` also accepts a
|
|
98
109
|
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.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Declarative static site generation for Matra",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@matra/core": "^0.3.1",
|
|
14
|
-
"@matra/html": "^0.
|
|
14
|
+
"@matra/html": "^0.4.0",
|
|
15
15
|
"js-yaml": "^5.2.2",
|
|
16
16
|
"markdown-it": "^14.3.0"
|
|
17
17
|
},
|
package/src/site.mjs
CHANGED
|
@@ -122,13 +122,15 @@ async function generateLoadedSite({
|
|
|
122
122
|
page.content = content
|
|
123
123
|
page.data = { ...data, ...page.data }
|
|
124
124
|
}
|
|
125
|
-
settings.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
125
|
+
if (settings.includeDocumentsInTemplates !== false) {
|
|
126
|
+
settings.documents.push({
|
|
127
|
+
id: document.id,
|
|
128
|
+
path: document.id,
|
|
129
|
+
route: page?.route ?? null,
|
|
130
|
+
metadata: { ...data, ...metadata },
|
|
131
|
+
content,
|
|
132
|
+
})
|
|
133
|
+
}
|
|
132
134
|
}
|
|
133
135
|
for (const template of [...layouts.values(), ...templates.values()]) {
|
|
134
136
|
template.bundle = await buildTemplate(template, root)
|
|
@@ -193,7 +195,7 @@ function warnDiscardedNodes(entry) {
|
|
|
193
195
|
for (const statement of branch.slice(0, -1)) {
|
|
194
196
|
if (statement.kind === "expression" && statement.expression.kind === "node") {
|
|
195
197
|
console.warn(
|
|
196
|
-
`${entry.document}: if branch discards <${statement.expression.tag}>.
|
|
198
|
+
`${entry.document}: if branch discards <${statement.expression.tag}>. Return an array to emit multiple nodes.`,
|
|
197
199
|
)
|
|
198
200
|
}
|
|
199
201
|
}
|
|
@@ -353,9 +355,16 @@ function normalizeDirectSite(input) {
|
|
|
353
355
|
"templates",
|
|
354
356
|
"components",
|
|
355
357
|
"documents",
|
|
358
|
+
"includeDocumentsInTemplates",
|
|
356
359
|
]),
|
|
357
360
|
"generateSite",
|
|
358
361
|
)
|
|
362
|
+
if (
|
|
363
|
+
Object.hasOwn(options, "includeDocumentsInTemplates") &&
|
|
364
|
+
typeof options.includeDocumentsInTemplates !== "boolean"
|
|
365
|
+
) {
|
|
366
|
+
throw new TypeError("includeDocumentsInTemplates must be a boolean")
|
|
367
|
+
}
|
|
359
368
|
if (options.root !== undefined && (typeof options.root !== "string" || !options.root)) {
|
|
360
369
|
throw new TypeError("root must be a non-empty path")
|
|
361
370
|
}
|
|
@@ -377,6 +386,7 @@ function normalizeDirectSite(input) {
|
|
|
377
386
|
.map(key => [key, options[key]]),
|
|
378
387
|
)
|
|
379
388
|
const settings = normalizeSettings({ version: 1, site: siteOptions }, root)
|
|
389
|
+
settings.includeDocumentsInTemplates = options.includeDocumentsInTemplates ?? true
|
|
380
390
|
if (transform) settings.markdown = transform
|
|
381
391
|
if (settings.outputDirectory === root) throw new Error("site.output must not be the project root")
|
|
382
392
|
const documentDirectories =
|
|
@@ -1004,13 +1014,12 @@ function resolveMarkdownLink(href, kind, document, settings, location) {
|
|
|
1004
1014
|
|
|
1005
1015
|
function assertCompleteDocument(ast, source) {
|
|
1006
1016
|
if (ast.tag !== "html") throw new TypeError(`${source}: generated page must have one html root`)
|
|
1007
|
-
const
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
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(
|
|
1011
1020
|
child => child && typeof child === "object" && child.tag === "body",
|
|
1012
1021
|
)
|
|
1013
|
-
if (heads.length !== 1 || bodies.length !== 1 ||
|
|
1022
|
+
if (heads.length !== 1 || bodies.length !== 1 || children.length !== 2) {
|
|
1014
1023
|
throw new TypeError(`${source}: generated html must contain exactly one head and one body`)
|
|
1015
1024
|
}
|
|
1016
1025
|
}
|