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

90 lines
2.2 KiB
Swift
Raw Normal View History

import Elementary
import Foundation
import Localization
/// The website's landing page, with its text localized to a given locale.
struct IndexPage: 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 landing 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 greeting followed by the app script.
var body: some HTML {
p {
localize("index.greeting", locale: locale)
}
2026-06-28 14:18:04 +00:00
script(.src("/js/app.js")) {}
}
/// The metadata, stylesheet, icon, and manifest 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),
2026-06-28 14:18:04 +00:00
.href("/css/style.css")
)
link(
.rel(.icon),
.href("/favicon.ico"),
.custom(
name: "sizes",
value: "any"
)
)
link(
.rel(.icon),
.href("/icon.svg"),
.custom(
name: "type",
value: "image/svg+xml"
)
)
link(
.rel("apple-touch-icon"),
2026-06-28 14:18:04 +00:00
.href("/icon.png")
)
link(
.rel("manifest"),
2026-06-28 14:18:04 +00:00
.href("/site.webmanifest")
)
meta(
.name("theme-color"),
.content("#fafafa")
)
}
/// 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.
2026-06-28 14:18:04 +00:00
var title: String {
localize("index.title", locale: locale)
2026-06-28 14:18:04 +00:00
}
}