Shared HTML template for the Website service (#22)

This PR contains the work done to define a `Page` protocol that extracts the HTML scaffolding that `IndexPage` and `ErrorPage` pages duplicated, so every page of the website declares only what makes it unique — its content, title, and assets — while the document structure lives in one place. Also cleans up imports across the workspace.

Reviewed-on: rock-n-code/loud-amsterdam#22
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit is contained in:
2026-07-19 08:56:35 +00:00
committed by javier
parent 6bdc127057
commit d0058dc636
10 changed files with 139 additions and 95 deletions
@@ -3,12 +3,12 @@ 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 {
struct ErrorPage {
// MARK: Properties
/// The locale the page content is localized to.
private let locale: Locale
let locale: Locale
/// Resolves the page's text from the bundled String Catalog for the page's ``locale``.
private let localize: Localize
@@ -23,45 +23,31 @@ struct ErrorPage: HTMLDocument, Sendable {
self.locale = locale
self.localize = .init(bundle: .module)
}
}
// MARK: Document
// MARK: Page
/// The page's content: a localized heading and explanatory message, followed by the error and shared scripts.
var body: some HTML {
extension ErrorPage: Page {
// MARK: Properties
var content: 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))
)
var scripts: [StaticFile] {
[.error, .shared]
}
/// 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
var stylesheets: [StaticFile] {
[.shared, .error]
}
/// The localized document title.
var title: String {
localize("error.title", locale: locale)
}