Files
ccn/Services/Website/Sources/Library/Internal/Pages/ErrorPage.swift
T
javier daf275b121 Improved the static assets definitions in the Website service (#18)
This PR contains the work done to overhaul the static asset definitions for the Website service.

To provide further details about the work:

* Website library
  * Overhauled the `StateFile` enumeration to reduce the number of cases to one case per logical file name, each exposing a `fileExtensions` list.
  * Wired everything into the pages with a consistent ordering convention: stylesheets load shared-first so the page sheet wins the CSS cascade; scripts load page-first with shared.js last. The error page also gained the shared stylesheet and its scripts; the index page gained its page CSS/JS and the new touch icon link.
  * Used the `StaticFile` enumeration as a single source of truth for every _href_/_src_ in the `IndexPage` and the `ErrorPage` pages, eliminating hardcoded asset paths.

* Website service
  * Added new assets to the Resources folder:
    * `apple-touch-icon.png`
    * `css/index.css`
    * `js/index.js`
    * `js/error.js`
    * `sitemap.xml`
  * Renamed existing assets within the Resources folder:
    * `css/style.css` → `css/shared.css`
    * `js/app.js` → `js/shared.js`
  * Fixed the working-directory location for the scheme in the Xcode project.

Reviewed-on: rock-n-code/loud-amsterdam#18
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
2026-07-19 02:08:59 +00:00

70 lines
1.9 KiB
Swift

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")
)
link(
.rel(.stylesheet),
.href(StaticFile.shared.urlPath(for: .css))
)
link(
.rel(.stylesheet),
.href(StaticFile.error.urlPath(for: .css))
)
}
/// 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)
}
}