@vojtaholik/static-kit-core 2.1.4 → 2.1.6
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/package.json +1 -1
- package/src/html-renderer.ts +31 -1
package/package.json
CHANGED
package/src/html-renderer.ts
CHANGED
|
@@ -86,6 +86,8 @@ export interface RenderPageOptions {
|
|
|
86
86
|
assetBase?: string;
|
|
87
87
|
/** Function to read template file content */
|
|
88
88
|
readFile?: (path: string) => Promise<string>;
|
|
89
|
+
/** Timestamp to append as ?v= to .css and .js references for cache-busting */
|
|
90
|
+
cacheBust?: number;
|
|
89
91
|
}
|
|
90
92
|
|
|
91
93
|
/**
|
|
@@ -127,6 +129,23 @@ export async function renderPage(
|
|
|
127
129
|
setAttr(node, "data-density", page.density);
|
|
128
130
|
}
|
|
129
131
|
|
|
132
|
+
// Cache-bust .css and .js references
|
|
133
|
+
if (options.cacheBust) {
|
|
134
|
+
if (node.nodeName === "link") {
|
|
135
|
+
const rel = getAttr(node, "rel");
|
|
136
|
+
const href = getAttr(node, "href");
|
|
137
|
+
if (rel === "stylesheet" && href && href.endsWith(".css")) {
|
|
138
|
+
setAttr(node, "href", `${href}?v=${options.cacheBust}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (node.nodeName === "script") {
|
|
142
|
+
const src = getAttr(node, "src");
|
|
143
|
+
if (src && src.endsWith(".js")) {
|
|
144
|
+
setAttr(node, "src", `${src}?v=${options.cacheBust}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
130
149
|
// Process regions - inject a marker that we'll replace after serialization
|
|
131
150
|
const regionName = getAttr(node, "data-region");
|
|
132
151
|
if (regionName) {
|
|
@@ -165,9 +184,11 @@ export async function renderPage(
|
|
|
165
184
|
// Czech typography: non-breaking spaces after single-char prepositions
|
|
166
185
|
html = vlnaHtml(html);
|
|
167
186
|
|
|
168
|
-
//
|
|
187
|
+
// Dev mode: inject overlay. Production: strip dev attributes.
|
|
169
188
|
if (options.isDev) {
|
|
170
189
|
html = injectDevOverlay(html);
|
|
190
|
+
} else {
|
|
191
|
+
html = stripDevAttributes(html);
|
|
171
192
|
}
|
|
172
193
|
|
|
173
194
|
return html;
|
|
@@ -270,6 +291,15 @@ function setAttr(node: Node, name: string, value: string): void {
|
|
|
270
291
|
}
|
|
271
292
|
}
|
|
272
293
|
|
|
294
|
+
/**
|
|
295
|
+
* Strip dev-only attributes (data-block-id, data-schema-address) from production HTML
|
|
296
|
+
*/
|
|
297
|
+
function stripDevAttributes(html: string): string {
|
|
298
|
+
return html
|
|
299
|
+
.replace(/\s+data-block-id="[^"]*"/g, "")
|
|
300
|
+
.replace(/\s+data-schema-address="[^"]*"/g, "");
|
|
301
|
+
}
|
|
302
|
+
|
|
273
303
|
/**
|
|
274
304
|
* Inject dev overlay script
|
|
275
305
|
*/
|