@vojtaholik/static-kit-core 2.1.3 → 2.1.5
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 +19 -0
- package/src/vlna.ts +9 -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) {
|
package/src/vlna.ts
CHANGED
|
@@ -49,6 +49,10 @@ export function preventWidow(text: string): string {
|
|
|
49
49
|
return text.replace(/\s(\S{1,15})\s*$/, "\u00A0$1");
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/** Block-level closing tags — widow prevention only applies before these */
|
|
53
|
+
const BLOCK_CLOSE_RE =
|
|
54
|
+
/^<\/(p|div|li|h[1-6]|td|th|blockquote|figcaption|section|article|dd|dt|summary|caption)\b/i;
|
|
55
|
+
|
|
52
56
|
/** Tags whose text content should NOT be transformed */
|
|
53
57
|
const SKIP_TAGS = new Set([
|
|
54
58
|
"script",
|
|
@@ -112,7 +116,11 @@ export function vlnaHtml(html: string): string {
|
|
|
112
116
|
if (inSkipTag) {
|
|
113
117
|
result += text;
|
|
114
118
|
} else {
|
|
115
|
-
|
|
119
|
+
const transformed = vlna(text);
|
|
120
|
+
// Only prevent widows before a closing block tag or end of string
|
|
121
|
+
const rest = html.slice(textEnd);
|
|
122
|
+
const atBlockEnd = nextTag === -1 || BLOCK_CLOSE_RE.test(rest);
|
|
123
|
+
result += atBlockEnd ? preventWidow(transformed) : transformed;
|
|
116
124
|
}
|
|
117
125
|
|
|
118
126
|
i = textEnd;
|