@jsnchn/buntastic 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/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
- Content inside `[head]` blocks is automatically placed in the parent's `<head>` section. Child layout head content is appended to parent head content.
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
- Content inside `[head]` blocks is automatically placed in the parent's `<head>` section. Child layout head content is appended to parent head content.
208
+ Head content from child layouts is appended to parent head content.
212
209
 
213
210
  ## Collections
214
211
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsnchn/buntastic",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "A simple static site generator built with Bun",
5
5
  "type": "module",
6
6
  "bin": {
package/src/index.ts CHANGED
@@ -113,46 +113,23 @@ async function resolveLayout(frontmatter: Frontmatter): Promise<{ template: stri
113
113
  childHead = headMatch[1].trim();
114
114
  }
115
115
 
116
- const bodyMatch = childContent.match(/\[content\]([\s\S]*?)\[\/content\]/);
117
- if (bodyMatch) {
118
- childBody = bodyMatch[1];
119
- } else {
120
- childBody = childContent;
121
- }
116
+ childBody = childContent;
122
117
 
123
118
  const parentResult = await resolveLayout({ extends: parentLayout[1] } as Frontmatter);
124
119
 
125
120
  let contentReplaced = parentResult.template;
126
121
 
127
- if (bodyMatch) {
128
- contentReplaced = contentReplaced.replace(
129
- /\[content\]([\s\S]*?)\[\/content\]/g,
130
- childBody
131
- );
132
- } else {
133
- contentReplaced = contentReplaced.replace(
134
- /\{\{\s*content\s*\|\s*safe\s*\}\}/g,
135
- childBody
136
- );
137
- }
122
+ contentReplaced = contentReplaced.replace(
123
+ /\{\{\s*content\s*\|\s*safe\s*\}\}/g,
124
+ childBody
125
+ );
138
126
 
139
127
  const mergedHead = parentResult.head + (childHead ? "\n" + childHead : "");
140
128
 
141
- if (headMatch) {
142
- contentReplaced = contentReplaced.replace(
143
- /\[head\]([\s\S]*?)\[\/head\]/g,
144
- mergedHead
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
- }
129
+ contentReplaced = contentReplaced.replace(
130
+ /<\/head>/i,
131
+ `\n${mergedHead}\n</head>`
132
+ );
156
133
 
157
134
  return { template: contentReplaced, head: mergedHead };
158
135
  }
@@ -160,8 +137,7 @@ async function resolveLayout(frontmatter: Frontmatter): Promise<{ template: stri
160
137
 
161
138
  let ownHead = "";
162
139
  if (extendsMatch) {
163
- const bodyMatch = extendsMatch[2];
164
- const headMatch = bodyMatch.match(/\[head\]([\s\S]*?)\[\/head\]/);
140
+ const headMatch = extendsMatch[2].match(/\[head\]([\s\S]*?)\[\/head\]/);
165
141
  ownHead = headMatch ? headMatch[1].trim() : "";
166
142
  }
167
143
 
@@ -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
- [content]
22
- [/content]
19
+ {{ content | safe }}
23
20
  </main>
24
21
  <footer>
25
22
  <p>Built with BunPress</p>
@@ -1,9 +1,7 @@
1
1
  ---
2
2
  extends: base.html
3
3
  ---
4
- [content]
5
4
  <article class="page">
6
5
  <h1>{{ title }}</h1>
7
6
  {{ content | safe }}
8
7
  </article>
9
- [/content]
@@ -4,7 +4,6 @@ extends: base.html
4
4
  [head]
5
5
  <link rel="stylesheet" href="/post.css">
6
6
  [/head]
7
- [content]
8
7
  <article class="post">
9
8
  <header>
10
9
  <h1>{{ title }}</h1>
@@ -14,4 +13,3 @@ extends: base.html
14
13
  {{ content | safe }}
15
14
  </div>
16
15
  </article>
17
- [/content]