@vojtaholik/static-kit-core 2.1.7 → 2.1.9

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vojtaholik/static-kit-core",
3
- "version": "2.1.7",
3
+ "version": "2.1.9",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -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
@@ -18,6 +18,11 @@ export const configSchema = z.object({
18
18
  devPort: z.number().default(3000),
19
19
  /** HTML output format: "formatted" (pretty-printed) or "minified" */
20
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(/\/+$/, "")),
21
26
  });
22
27
 
23
28
  export type StaticKitConfig = z.infer<typeof configSchema>;
package/src/index.ts CHANGED
@@ -59,3 +59,6 @@ export { vlna, vlnaHtml, preventWidow } from "./vlna.ts";
59
59
 
60
60
  // Configuration
61
61
  export { configSchema, defineConfig, type StaticKitConfig } from "./config.ts";
62
+
63
+ // Base path rewriting
64
+ export { rewriteBasePath } from "./base-path.ts";