2026-06-28 05:07:19 +00:00
|
|
|
import Elementary
|
2026-06-29 23:08:36 +00:00
|
|
|
import Foundation
|
|
|
|
|
import Localization
|
2026-06-28 05:07:19 +00:00
|
|
|
|
2026-06-29 23:08:36 +00:00
|
|
|
/// The website's landing page, with its text localized to a given locale.
|
2026-06-28 05:07:19 +00:00
|
|
|
struct IndexPage: HTMLDocument, Sendable {
|
|
|
|
|
|
2026-06-29 23:08:36 +00:00
|
|
|
// 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)
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-28 05:07:19 +00:00
|
|
|
// MARK: Document
|
|
|
|
|
|
2026-07-19 02:08:59 +00:00
|
|
|
/// The page's content: a localized greeting followed by the shared and index scripts.
|
2026-06-28 05:07:19 +00:00
|
|
|
var body: some HTML {
|
2026-06-29 23:08:36 +00:00
|
|
|
p {
|
|
|
|
|
localize("index.greeting", locale: locale)
|
|
|
|
|
}
|
2026-07-19 02:08:59 +00:00
|
|
|
script(.src(StaticFile.index.urlPath(for: .js))) {}
|
|
|
|
|
script(.src(StaticFile.shared.urlPath(for: .js))) {}
|
2026-06-28 05:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 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-07-19 02:08:59 +00:00
|
|
|
.href(StaticFile.shared.urlPath(for: .css))
|
|
|
|
|
)
|
|
|
|
|
link(
|
|
|
|
|
.rel(.stylesheet),
|
|
|
|
|
.href(StaticFile.index.urlPath(for: .css))
|
2026-06-28 05:07:19 +00:00
|
|
|
)
|
|
|
|
|
link(
|
|
|
|
|
.rel(.icon),
|
2026-07-19 02:08:59 +00:00
|
|
|
.href(StaticFile.favicon.urlPath(for: .ico)),
|
2026-06-28 05:07:19 +00:00
|
|
|
.custom(
|
|
|
|
|
name: "sizes",
|
|
|
|
|
value: "any"
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
link(
|
|
|
|
|
.rel(.icon),
|
2026-07-19 02:08:59 +00:00
|
|
|
.href(StaticFile.icon.urlPath(for: .svg)),
|
2026-06-28 05:07:19 +00:00
|
|
|
.custom(
|
|
|
|
|
name: "type",
|
|
|
|
|
value: "image/svg+xml"
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
link(
|
|
|
|
|
.rel("apple-touch-icon"),
|
2026-07-19 02:08:59 +00:00
|
|
|
.href(StaticFile.appleTouchIcon.urlPath(for: .png))
|
2026-06-28 05:07:19 +00:00
|
|
|
)
|
|
|
|
|
link(
|
|
|
|
|
.rel("manifest"),
|
2026-07-19 02:08:59 +00:00
|
|
|
.href(StaticFile.site.urlPath(for: .webmanifest))
|
2026-06-28 05:07:19 +00:00
|
|
|
)
|
2026-07-19 03:35:50 +00:00
|
|
|
meta(
|
|
|
|
|
.name("theme-color"),
|
|
|
|
|
.content("#0c0710"),
|
|
|
|
|
.custom(
|
|
|
|
|
name: "media",
|
|
|
|
|
value: "(prefers-color-scheme: dark)"
|
|
|
|
|
)
|
|
|
|
|
)
|
2026-06-28 05:07:19 +00:00
|
|
|
meta(
|
|
|
|
|
.name("theme-color"),
|
|
|
|
|
.content("#fafafa")
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-29 23:08:36 +00:00
|
|
|
/// The document language, derived from the page's locale and falling back to the default language.
|
2026-06-28 05:07:19 +00:00
|
|
|
var lang: String {
|
2026-06-29 23:08:36 +00:00
|
|
|
locale.language.languageCode?.identifier
|
|
|
|
|
?? LanguageList(bundle: .module).default
|
2026-06-28 05:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
2026-06-29 23:08:36 +00:00
|
|
|
/// The localized document title.
|
2026-06-28 14:18:04 +00:00
|
|
|
var title: String {
|
2026-06-29 23:08:36 +00:00
|
|
|
localize("index.title", locale: locale)
|
2026-06-28 14:18:04 +00:00
|
|
|
}
|
2026-06-28 05:07:19 +00:00
|
|
|
|
|
|
|
|
}
|