This PR contains the work done to address small fixes. To provide further details: * HTML template * Removed the duplicate charset <meta> tag from the Page protocol's head property. * Router * Enabled auto-generated HEAD endpoints so every GET route gets a HEAD sibling. Uptime monitors and crawlers probing with HEAD now receive the page's status and headers instead of a 404. * Docker * Pinned the asset optimizer versionsvia build args so minified output is reproducible for a given Dockerfile commit. * Narrowed the build context copied into the release stage, only package manifests and Swift sources are copied. Static assets come from the separate assets stage after the binary is built. * svgo now minifies all SVGs recursively rather than just icon.svg, and the staging step creates Resources/Static explicitly instead of conditionally moving the unminified sources. * Added curl to the runtime image (needed for the container healthcheck) and .claude to .dockerignore. * Docker-compose * Added a `healthcheck` to the website service hitting GET /health (liveness only), so Compose reports process health without coupling container health to database reachability. Reviewed-on: rock-n-code/loud-amsterdam#23 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
110 lines
3.1 KiB
Swift
110 lines
3.1 KiB
Swift
import Elementary
|
|
import Foundation
|
|
import Localization
|
|
|
|
/// A page of the website: an HTML document with the shared scaffolding assembled around the page's content.
|
|
///
|
|
/// A conforming page supplies its locale, its localized title, the stylesheets and scripts it needs, and its content; the protocol assembles the rest of the
|
|
/// document around them: the metadata, stylesheet, icon, and manifest links in the head, the content followed by the script tags in the body, and the
|
|
/// document language derived from the locale.
|
|
protocol Page: HTMLDocument, Sendable {
|
|
|
|
// MARK: Associated types
|
|
|
|
/// The type of the page's markup.
|
|
associatedtype Content: HTML
|
|
|
|
// MARK: Properties
|
|
|
|
/// The page's markup, rendered before the ``scripts``.
|
|
@HTMLBuilder
|
|
var content: Content { get }
|
|
|
|
/// The locale the page content is localized to.
|
|
var locale: Locale { get }
|
|
|
|
/// The scripts loaded at the end of the document body, in order.
|
|
var scripts: [StaticFile] { get }
|
|
|
|
/// The stylesheets linked in the document head, in order.
|
|
var stylesheets: [StaticFile] { get }
|
|
|
|
}
|
|
|
|
// MARK: - Implementations
|
|
|
|
extension Page {
|
|
|
|
// MARK: Computed
|
|
|
|
/// The page ``content`` followed by its ``scripts``.
|
|
@HTMLBuilder
|
|
var body: some HTML {
|
|
content
|
|
for file in scripts {
|
|
script(.src(file.urlPath(for: .js))) {}
|
|
}
|
|
}
|
|
|
|
/// The metadata, ``stylesheets``, icon, and manifest links placed in the document head.
|
|
///
|
|
/// The charset declaration is omitted: Elementary's `HTMLDocument` scaffolding already
|
|
/// emits `<meta charset="UTF-8">` before this markup, and HTML5 allows only one.
|
|
@HTMLBuilder
|
|
var head: some HTML {
|
|
meta(
|
|
.name(.viewport),
|
|
.content("width=device-width, initial-scale=1")
|
|
)
|
|
for file in stylesheets {
|
|
link(
|
|
.rel(.stylesheet),
|
|
.href(file.urlPath(for: .css))
|
|
)
|
|
}
|
|
link(
|
|
.rel(.icon),
|
|
.href(StaticFile.favicon.urlPath(for: .ico)),
|
|
.custom(
|
|
name: "sizes",
|
|
value: "any"
|
|
)
|
|
)
|
|
link(
|
|
.rel(.icon),
|
|
.href(StaticFile.icon.urlPath(for: .svg)),
|
|
.custom(
|
|
name: "type",
|
|
value: "image/svg+xml"
|
|
)
|
|
)
|
|
link(
|
|
.rel("apple-touch-icon"),
|
|
.href(StaticFile.appleTouchIcon.urlPath(for: .png))
|
|
)
|
|
link(
|
|
.rel("manifest"),
|
|
.href(StaticFile.site.urlPath(for: .webmanifest))
|
|
)
|
|
meta(
|
|
.name("theme-color"),
|
|
.content("#fafafa")
|
|
)
|
|
meta(
|
|
.name("theme-color"),
|
|
.content("#0c0710"),
|
|
.custom(
|
|
name: "media",
|
|
value: "(prefers-color-scheme: dark)"
|
|
)
|
|
)
|
|
}
|
|
|
|
/// 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
|
|
}
|
|
|
|
}
|