@vojtaholik/static-kit-core 2.1.6 → 2.1.8
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/base-path.ts +16 -0
- package/src/config.ts +7 -0
- package/src/index.ts +3 -0
package/package.json
CHANGED
package/src/base-path.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rewrite internal links in HTML to include a base path prefix.
|
|
3
|
+
* Only matches href attributes with absolute paths (starting with /).
|
|
4
|
+
*/
|
|
5
|
+
export function rewriteBasePath(html: string, basePath: string): string {
|
|
6
|
+
if (!basePath) return html;
|
|
7
|
+
|
|
8
|
+
return html.replace(/href="(\/[^"]*)"/g, (match, path: string) => {
|
|
9
|
+
// Already prefixed
|
|
10
|
+
if (path.startsWith(`${basePath}/`) || path === basePath) {
|
|
11
|
+
return match;
|
|
12
|
+
}
|
|
13
|
+
const newPath = path === "/" ? `${basePath}/` : `${basePath}${path}`;
|
|
14
|
+
return `href="${newPath}"`;
|
|
15
|
+
});
|
|
16
|
+
}
|
package/src/config.ts
CHANGED
|
@@ -16,6 +16,13 @@ export const configSchema = z.object({
|
|
|
16
16
|
publicPath: z.string().default("/public"),
|
|
17
17
|
/** Dev server port */
|
|
18
18
|
devPort: z.number().default(3000),
|
|
19
|
+
/** HTML output format: "formatted" (pretty-printed) or "minified" */
|
|
20
|
+
htmlOutput: z.enum(["formatted", "minified"]).default("formatted"),
|
|
21
|
+
/** URL path prefix for production builds — all internal links get this prefix */
|
|
22
|
+
basePath: z
|
|
23
|
+
.string()
|
|
24
|
+
.default("")
|
|
25
|
+
.transform((v) => v.replace(/\/+$/, "")),
|
|
19
26
|
});
|
|
20
27
|
|
|
21
28
|
export type StaticKitConfig = z.infer<typeof configSchema>;
|
package/src/index.ts
CHANGED