Project updates from Template

This commit contains the latest updates from the generic Website template, which rework the compression and localization:

- Reworked the compression and localization in the Infrastructure package. (3c568e4)
- Adopted the reworked compression and localization in the Website service. (08cf3e3)

The template commit that only touched the root README (53676ed) was left out, as this project no longer carries that file.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
2026-09-20 12:45:58 +02:00
co-authored by Claude Fable 5.1
parent 65b62681eb
commit 916df7e2f0
24 changed files with 426 additions and 218 deletions
@@ -1,19 +1,23 @@
import Elementary
import Foundation
import Hummingbird
import Localization
/// Serves a custom error page for requests that match neither a route nor a static file.
///
/// Placed ahead of `FileMiddleware` in the middleware chain, it catches the `.notFound` error that bubbles up when no file exists for the requested
/// path and responds with the rendered error page and a `404 Not Found` status. The page is served in the language stored on the context by
/// ``LocalizationMiddleware``, falling back to the default language.
/// path and responds with the rendered error page and a `404 Not Found` status.
///
/// Its responses declare `Vary: Accept-Language`: where the page routes pin their language by URL, this is the one responder that negotiates.
/// An unrouted path names no edition, so no canonical URL contradicts the header.
public struct NotFoundMiddleware<Context: LocalizedRequestContext> {
/// It negotiates the language itself, on the way out, so the cost falls on the 404s rather than on every request through the chain where page
/// routes pin their language by URL, this is the one responder that has to ask. Its responses declare `Vary: Accept-Language` accordingly: an
/// unrouted path names no edition, so no canonical URL contradicts the header.
public struct NotFoundMiddleware<Context: RequestContext> {
// MARK: Properties
/// Negotiates the language a not-found response is served in.
private let negotiate: Negotiate
/// The error page, rendered once per supported language and reused for every not-found response.
private let responses: LocalizedHTMLCollectionResponse
@@ -27,6 +31,7 @@ public struct NotFoundMiddleware<Context: LocalizedRequestContext> {
bundle: Bundle,
document: (Locale) -> Document
) {
self.negotiate = .init(bundle: bundle)
self.responses = .init(
bundle: bundle,
status: .notFound,
@@ -69,7 +74,7 @@ extension NotFoundMiddleware: RouterMiddleware {
}
return responses.response(
for: context.language,
for: negotiate(for: request),
request: request
)
}