Files
ccn/Services/Website/Sources/Library/Internal/Pages/ErrorPage.swift
T

70 lines
1.9 KiB
Swift
Raw Normal View History

import Elementary
import Foundation
import Localization
/// The HTML page rendered for a not-found response, with its text localized to a given locale.
struct ErrorPage: HTMLDocument, Sendable {
// 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)
}
// MARK: Document
/// The page's content: a localized heading and explanatory message, followed by the error and shared scripts.
var body: some HTML {
h1 {
localize("error.heading", locale: locale)
}
p {
localize("error.message", locale: locale)
}
script(.src(StaticFile.error.urlPath(for: .js))) {}
script(.src(StaticFile.shared.urlPath(for: .js))) {}
}
/// The metadata and stylesheet links placed in the document head.
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(StaticFile.shared.urlPath(for: .css))
)
link(
.rel(.stylesheet),
.href(StaticFile.error.urlPath(for: .css))
2026-06-28 14:18:04 +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
}
/// The localized document title.
var title: String {
localize("error.title", locale: locale)
}
}