2026-06-28 05:07:19 +00:00
|
|
|
import Elementary
|
2026-06-29 23:08:36 +00:00
|
|
|
import Foundation
|
|
|
|
|
import Localization
|
2026-06-28 05:07:19 +00:00
|
|
|
|
2026-06-29 23:08:36 +00:00
|
|
|
/// The HTML page rendered for a not-found response, with its text localized to a given locale.
|
2026-06-28 05:07:19 +00:00
|
|
|
struct ErrorPage: HTMLDocument, Sendable {
|
|
|
|
|
|
2026-06-29 23:08:36 +00:00
|
|
|
// MARK: Properties
|
|
|
|
|
|
|
|
|
|
/// The locale the page content is localized to.
|
|
|
|
|
private let locale: Locale
|
|
|
|
|
|
|
|
|
|
/// Resolves the page's text from the bundled String Catalog for the page's ``locale``.
|
|
|
|
|
private let localize: Localize
|
|
|
|
|
|
|
|
|
|
// MARK: Initializers
|
|
|
|
|
|
|
|
|
|
/// Creates a not-found page localized to the given locale.
|
|
|
|
|
/// - Parameter locale: the locale the page content is localized to.
|
|
|
|
|
init(
|
|
|
|
|
locale: Locale
|
|
|
|
|
) {
|
|
|
|
|
self.locale = locale
|
|
|
|
|
self.localize = .init(bundle: .module)
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-28 05:07:19 +00:00
|
|
|
// MARK: Document
|
|
|
|
|
|
2026-06-29 23:08:36 +00:00
|
|
|
/// The page's content: a localized heading and explanatory message.
|
2026-06-28 05:07:19 +00:00
|
|
|
var body: some HTML {
|
2026-06-29 23:08:36 +00:00
|
|
|
h1 {
|
|
|
|
|
localize("error.heading", locale: locale)
|
|
|
|
|
}
|
|
|
|
|
p {
|
|
|
|
|
localize("error.message", locale: locale)
|
|
|
|
|
}
|
2026-06-28 05:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
2026-06-28 14:18:04 +00:00
|
|
|
/// The metadata and stylesheet link placed in the document head.
|
2026-06-28 05:07:19 +00:00
|
|
|
var head: some HTML {
|
|
|
|
|
meta(.charset(.utf8))
|
|
|
|
|
meta(
|
|
|
|
|
.name(.viewport),
|
|
|
|
|
.content("width=device-width, initial-scale=1")
|
|
|
|
|
)
|
2026-06-28 14:18:04 +00:00
|
|
|
link(
|
|
|
|
|
.rel(.stylesheet),
|
|
|
|
|
.href("/css/error.css")
|
|
|
|
|
)
|
2026-06-28 05:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
2026-06-29 23:08:36 +00:00
|
|
|
/// The document language, derived from the page's locale and falling back to the default language.
|
|
|
|
|
var lang: String {
|
|
|
|
|
locale.language.languageCode?.identifier
|
|
|
|
|
?? LanguageList(bundle: .module).default
|
|
|
|
|
}
|
2026-06-28 05:07:19 +00:00
|
|
|
|
2026-06-29 23:08:36 +00:00
|
|
|
/// The localized document title.
|
|
|
|
|
var title: String {
|
|
|
|
|
localize("error.title", locale: locale)
|
|
|
|
|
}
|
2026-06-28 05:07:19 +00:00
|
|
|
|
|
|
|
|
}
|