2026-06-28 05:07:19 +00:00
|
|
|
import Elementary
|
2026-06-29 23:08:36 +00:00
|
|
|
import Foundation
|
2026-07-23 01:04:37 +00:00
|
|
|
import Infrastructure
|
2026-06-29 23:08:36 +00:00
|
|
|
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-08-01 23:06:22 +02:00
|
|
|
struct NotFoundPage {
|
2026-06-28 05:07:19 +00:00
|
|
|
|
2026-06-29 23:08:36 +00:00
|
|
|
// MARK: Properties
|
|
|
|
|
|
2026-07-23 01:04:37 +00:00
|
|
|
/// The version token appended to the page's asset URLs, or `nil` to leave them unversioned.
|
|
|
|
|
let assetVersion: String?
|
|
|
|
|
|
2026-06-29 23:08:36 +00:00
|
|
|
/// The locale the page content is localized to.
|
2026-07-19 08:56:35 +00:00
|
|
|
let locale: Locale
|
2026-06-29 23:08:36 +00:00
|
|
|
|
|
|
|
|
/// 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.
|
2026-07-23 01:04:37 +00:00
|
|
|
/// - Parameters:
|
|
|
|
|
/// - locale: the locale the page content is localized to.
|
|
|
|
|
/// - assetVersion: the version token appended to the page's asset URLs, or `nil` (the
|
|
|
|
|
/// default) to leave them unversioned.
|
2026-06-29 23:08:36 +00:00
|
|
|
init(
|
2026-07-23 01:04:37 +00:00
|
|
|
locale: Locale,
|
|
|
|
|
assetVersion: String? = nil
|
2026-06-29 23:08:36 +00:00
|
|
|
) {
|
2026-07-23 01:04:37 +00:00
|
|
|
self.assetVersion = assetVersion
|
2026-06-29 23:08:36 +00:00
|
|
|
self.locale = locale
|
|
|
|
|
self.localize = .init(bundle: .module)
|
|
|
|
|
}
|
2026-07-19 08:56:35 +00:00
|
|
|
}
|
2026-06-29 23:08:36 +00:00
|
|
|
|
2026-07-19 08:56:35 +00:00
|
|
|
// MARK: Page
|
2026-06-28 05:07:19 +00:00
|
|
|
|
2026-08-01 23:06:22 +02:00
|
|
|
extension NotFoundPage: Page {
|
2026-07-19 08:56:35 +00:00
|
|
|
|
|
|
|
|
// MARK: Properties
|
|
|
|
|
|
|
|
|
|
var content: some HTML {
|
2026-06-29 23:08:36 +00:00
|
|
|
h1 {
|
2026-08-01 23:06:22 +02:00
|
|
|
localize("notFound.heading", locale: locale)
|
2026-06-29 23:08:36 +00:00
|
|
|
}
|
|
|
|
|
p {
|
2026-08-01 23:06:22 +02:00
|
|
|
localize("notFound.message", locale: locale)
|
2026-06-29 23:08:36 +00:00
|
|
|
}
|
2026-06-28 05:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
2026-07-23 01:04:37 +00:00
|
|
|
var scripts: [any Asset] {
|
2026-08-01 23:06:22 +02:00
|
|
|
[StaticFile.notFound, StaticFile.shared]
|
2026-06-28 05:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
2026-07-23 01:04:37 +00:00
|
|
|
var stylesheets: [any Asset] {
|
2026-08-01 23:06:22 +02:00
|
|
|
[StaticFile.shared, StaticFile.notFound]
|
2026-06-29 23:08:36 +00:00
|
|
|
}
|
2026-06-28 05:07:19 +00:00
|
|
|
|
2026-06-29 23:08:36 +00:00
|
|
|
var title: String {
|
2026-08-01 23:06:22 +02:00
|
|
|
localize("notFound.title", locale: locale)
|
2026-06-29 23:08:36 +00:00
|
|
|
}
|
2026-06-28 05:07:19 +00:00
|
|
|
|
|
|
|
|
}
|