@jsnchn/buntastic 0.2.0 → 0.3.1
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/AGENTS.md +2 -5
- package/README.md +2 -5
- package/package.json +1 -1
- package/src/index.ts +10 -33
- package/src/layouts/base.html +1 -4
- package/src/layouts/page.html +0 -2
- package/src/layouts/post.html +0 -2
package/AGENTS.md
CHANGED
|
@@ -64,7 +64,6 @@ draft: false # Set true to exclude from production build
|
|
|
64
64
|
| `{{ description }}` | Page description |
|
|
65
65
|
| `{{ url }}` | Current page URL |
|
|
66
66
|
| `{{ collection }}` | Array of posts in current folder (for index pages) |
|
|
67
|
-
| `{{ head \| safe }}` | Head content from child layouts (appended to parent) |
|
|
68
67
|
|
|
69
68
|
## Layout System
|
|
70
69
|
|
|
@@ -85,7 +84,7 @@ The `{{ content | safe }}` placeholder is where child content gets injected.
|
|
|
85
84
|
|
|
86
85
|
## Head Block
|
|
87
86
|
|
|
88
|
-
Layouts can inject content into the `<head>` section using `[head]...[/head]` blocks:
|
|
87
|
+
Layouts can inject content into the `<head>` section using `[head]...[/head]` blocks. Content inside these blocks is automatically merged and appended to the `<head>` element in the parent layout:
|
|
89
88
|
|
|
90
89
|
```html
|
|
91
90
|
<!-- layouts/post.html -->
|
|
@@ -95,15 +94,13 @@ extends: base.html
|
|
|
95
94
|
[head]
|
|
96
95
|
<link rel="stylesheet" href="/post.css">
|
|
97
96
|
[/head]
|
|
98
|
-
[content]
|
|
99
97
|
<article class="post">
|
|
100
98
|
<h1>{{ title }}</h1>
|
|
101
99
|
{{ content | safe }}
|
|
102
100
|
</article>
|
|
103
|
-
[/content]
|
|
104
101
|
```
|
|
105
102
|
|
|
106
|
-
|
|
103
|
+
Head content from child layouts is appended to parent head content.
|
|
107
104
|
|
|
108
105
|
## Development
|
|
109
106
|
|
package/README.md
CHANGED
|
@@ -169,7 +169,6 @@ extends: base.html
|
|
|
169
169
|
| `{{ description }}` | Meta description |
|
|
170
170
|
| `{{ url }}` | Current page URL |
|
|
171
171
|
| `{{ collection }}` | List of posts in current folder (for index pages) |
|
|
172
|
-
| `{{ head | safe }}` | Head content from child layouts (appended to parent) |
|
|
173
172
|
|
|
174
173
|
### Layout Inheritance
|
|
175
174
|
|
|
@@ -190,7 +189,7 @@ Use `extends:` to build on top of other layouts:
|
|
|
190
189
|
|
|
191
190
|
### Head Block
|
|
192
191
|
|
|
193
|
-
Layouts can inject content into the `<head>` section using `[head]...[/head]` blocks:
|
|
192
|
+
Layouts can inject content into the `<head>` section using `[head]...[/head]` blocks. Content inside these blocks is automatically merged and appended to the `<head>` element in the parent layout:
|
|
194
193
|
|
|
195
194
|
```html
|
|
196
195
|
<!-- layouts/post.html -->
|
|
@@ -200,15 +199,13 @@ extends: base.html
|
|
|
200
199
|
[head]
|
|
201
200
|
<link rel="stylesheet" href="/post.css">
|
|
202
201
|
[/head]
|
|
203
|
-
[content]
|
|
204
202
|
<article class="post">
|
|
205
203
|
<h1>{{ title }}</h1>
|
|
206
204
|
{{ content | safe }}
|
|
207
205
|
</article>
|
|
208
|
-
[/content]
|
|
209
206
|
```
|
|
210
207
|
|
|
211
|
-
|
|
208
|
+
Head content from child layouts is appended to parent head content.
|
|
212
209
|
|
|
213
210
|
## Collections
|
|
214
211
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -111,11 +111,7 @@ async function resolveLayout(frontmatter: Frontmatter): Promise<{ template: stri
|
|
|
111
111
|
const headMatch = childContent.match(/\[head\]([\s\S]*?)\[\/head\]/);
|
|
112
112
|
if (headMatch) {
|
|
113
113
|
childHead = headMatch[1].trim();
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const bodyMatch = childContent.match(/\[content\]([\s\S]*?)\[\/content\]/);
|
|
117
|
-
if (bodyMatch) {
|
|
118
|
-
childBody = bodyMatch[1];
|
|
114
|
+
childBody = childContent.replace(headMatch[0], '').trim();
|
|
119
115
|
} else {
|
|
120
116
|
childBody = childContent;
|
|
121
117
|
}
|
|
@@ -124,35 +120,17 @@ async function resolveLayout(frontmatter: Frontmatter): Promise<{ template: stri
|
|
|
124
120
|
|
|
125
121
|
let contentReplaced = parentResult.template;
|
|
126
122
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
);
|
|
132
|
-
} else {
|
|
133
|
-
contentReplaced = contentReplaced.replace(
|
|
134
|
-
/\{\{\s*content\s*\|\s*safe\s*\}\}/g,
|
|
135
|
-
childBody
|
|
136
|
-
);
|
|
137
|
-
}
|
|
123
|
+
contentReplaced = contentReplaced.replace(
|
|
124
|
+
/\{\{\s*content\s*\|\s*safe\s*\}\}/g,
|
|
125
|
+
childBody
|
|
126
|
+
);
|
|
138
127
|
|
|
139
128
|
const mergedHead = parentResult.head + (childHead ? "\n" + childHead : "");
|
|
140
129
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
);
|
|
146
|
-
} else {
|
|
147
|
-
contentReplaced = contentReplaced.replace(
|
|
148
|
-
/\[head\]([\s\S]*?)\[\/head\]/g,
|
|
149
|
-
mergedHead
|
|
150
|
-
);
|
|
151
|
-
contentReplaced = contentReplaced.replace(
|
|
152
|
-
/\{\{\s*head\s*\|\s*safe\s*\}\}/g,
|
|
153
|
-
mergedHead
|
|
154
|
-
);
|
|
155
|
-
}
|
|
130
|
+
contentReplaced = contentReplaced.replace(
|
|
131
|
+
/<\/head>/i,
|
|
132
|
+
`\n${mergedHead}\n</head>`
|
|
133
|
+
);
|
|
156
134
|
|
|
157
135
|
return { template: contentReplaced, head: mergedHead };
|
|
158
136
|
}
|
|
@@ -160,8 +138,7 @@ async function resolveLayout(frontmatter: Frontmatter): Promise<{ template: stri
|
|
|
160
138
|
|
|
161
139
|
let ownHead = "";
|
|
162
140
|
if (extendsMatch) {
|
|
163
|
-
const
|
|
164
|
-
const headMatch = bodyMatch.match(/\[head\]([\s\S]*?)\[\/head\]/);
|
|
141
|
+
const headMatch = extendsMatch[2].match(/\[head\]([\s\S]*?)\[\/head\]/);
|
|
165
142
|
ownHead = headMatch ? headMatch[1].trim() : "";
|
|
166
143
|
}
|
|
167
144
|
|
package/src/layouts/base.html
CHANGED
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
<title>{{ title }}</title>
|
|
7
7
|
<meta name="description" content="{{ description }}">
|
|
8
8
|
<link rel="stylesheet" href="/style.css">
|
|
9
|
-
[head]
|
|
10
|
-
[/head]
|
|
11
9
|
</head>
|
|
12
10
|
<body>
|
|
13
11
|
<header>
|
|
@@ -18,8 +16,7 @@
|
|
|
18
16
|
</nav>
|
|
19
17
|
</header>
|
|
20
18
|
<main>
|
|
21
|
-
|
|
22
|
-
[/content]
|
|
19
|
+
{{ content | safe }}
|
|
23
20
|
</main>
|
|
24
21
|
<footer>
|
|
25
22
|
<p>Built with BunPress</p>
|
package/src/layouts/page.html
CHANGED
package/src/layouts/post.html
CHANGED