diff --git a/@kindspells/astro-shield/src/netlify.mts b/@kindspells/astro-shield/src/netlify.mts index 74c3a26..abc1de1 100644 --- a/@kindspells/astro-shield/src/netlify.mts +++ b/@kindspells/astro-shield/src/netlify.mts @@ -459,5 +459,13 @@ export const patchNetlifyHeadersConfig = async ( const mergedConfig = mergeNetlifyHeadersConfig(baseConfig, patchConfig) + if (securityHeadersOptions.removeHtmlExtension) { + for (const entry of mergedConfig.entries) { + if (typeof entry === 'object' && 'path' in entry) { + entry.path = entry.path.replace(/\.html$/, '') + } + } + } + await writeFile(configPath, serializeNetlifyHeadersConfig(mergedConfig)) } diff --git a/@kindspells/astro-shield/src/types.mts b/@kindspells/astro-shield/src/types.mts index 093c070..6ddae06 100644 --- a/@kindspells/astro-shield/src/types.mts +++ b/@kindspells/astro-shield/src/types.mts @@ -129,6 +129,13 @@ export type SecurityHeadersOptions = { * Defaults to `undefined`. */ contentSecurityPolicy?: CSPOptions | undefined + + /** + * - If set, it will remove the `.html` extension from the URLs. + * + * Defaults to `false`. + */ + removeHtmlExtension?: boolean } export type ShieldOptions = { diff --git a/@kindspells/astro-shield/src/vercel.mts b/@kindspells/astro-shield/src/vercel.mts index ec7561a..6c647d9 100644 --- a/@kindspells/astro-shield/src/vercel.mts +++ b/@kindspells/astro-shield/src/vercel.mts @@ -159,5 +159,12 @@ export const patchVercelHeadersConfig = async ( const mergedConfig = mergeVercelConfig(baseConfig, patchConfig) + if (securityHeadersOptions.removeHtmlExtension) { + for (const route of mergedConfig.routes ?? []) { + if (route.src.endsWith('.html')) + route.src = route.src.slice(0, -5) + } + } + await writeFile(configPath, serializeVercelConfig(mergedConfig)) } diff --git a/docs/src/content/docs/reference/configuration.mdx b/docs/src/content/docs/reference/configuration.mdx index a784be4..9fadd2d 100644 --- a/docs/src/content/docs/reference/configuration.mdx +++ b/docs/src/content/docs/reference/configuration.mdx @@ -199,3 +199,9 @@ Type: `object | undefined`, defaults to `undefined`. Possible values are: - `'netlify'`: Generate the security headers for static content on Netlify. + +#### `securityHeaders.removeHtmlExtension` + +If set, it will remove the `.html` extension from the URLs. + +Type: `boolean`, defaults to `false`. diff --git a/docs/src/content/docs/ru/reference/configuration.mdx b/docs/src/content/docs/ru/reference/configuration.mdx index bffdf82..e62fb58 100644 --- a/docs/src/content/docs/ru/reference/configuration.mdx +++ b/docs/src/content/docs/ru/reference/configuration.mdx @@ -103,7 +103,7 @@ Content-Security-Policy (CSP) для динамического контента ### `sri.hashesModule` -Указывает путь к автоматически сгенерированному модулю, который содержит и +Указывает путь к автоматически сгенерированному модулю, который содержит и кспортирует хеши SRI, вычисленные Astro-Shield для нашего контента. Мы можем импортировать этот модуль в наш собственный код, если нам нужно @@ -201,3 +201,10 @@ Content-Security-Policy (CSP) для статического и/или дина Возможные значения: - `'netlify'`: генерировать заголовки безопасности для статического контента на Netlify. + +#### `securityHeaders.removeHtmlExtension` + +Если установлено, то Astro-Shield будет удалять расширение `.html` из +URL-адресов. + +Тип: `boolean`, defaults to `false`.