feat: support kebab-case filenames for islands (#404)
This commit is contained in:
+13
-1
@@ -196,7 +196,7 @@ export class ServerContext {
|
||||
}
|
||||
const path = url.substring(baseUrl.length).substring("islands".length);
|
||||
const baseRoute = path.substring(1, path.length - extname(path).length);
|
||||
const name = baseRoute.replace("/", "");
|
||||
const name = sanitizeIslandName(baseRoute);
|
||||
const id = name.toLowerCase();
|
||||
if (typeof module.default !== "function") {
|
||||
throw new TypeError(
|
||||
@@ -676,6 +676,18 @@ function sanitizePathToRegex(path: string): string {
|
||||
.replaceAll("\:", "\\:");
|
||||
}
|
||||
|
||||
function toPascalCase(text: string): string {
|
||||
return text.replace(
|
||||
/(^\w|-\w)/g,
|
||||
(substring) => substring.replace(/-/, "").toUpperCase(),
|
||||
);
|
||||
}
|
||||
|
||||
function sanitizeIslandName(name: string): string {
|
||||
const fileName = name.replace("/", "");
|
||||
return toPascalCase(fileName);
|
||||
}
|
||||
|
||||
function serializeCSPDirectives(csp: ContentSecurityPolicyDirectives): string {
|
||||
return Object.entries(csp)
|
||||
.filter(([_key, value]) => value !== undefined)
|
||||
|
||||
Reference in New Issue
Block a user