Added a configurable site origin to the ConfigReader+Properties extension in the Website library target.
This commit is contained in:
@@ -60,18 +60,14 @@ public struct Analytics: Sendable {
|
||||
|
||||
// MARK: Computed
|
||||
|
||||
/// The tracker script's attributes: the website id and reporting domains, then each enabled behavior flag; disabled flags are omitted.
|
||||
/// The tracker script's attributes: the website id, the reporting domains when set, then each enabled behavior flag; disabled flags are omitted.
|
||||
public var attributes: [Attribute] {
|
||||
var attributes: [Attribute] = [
|
||||
.init("data-website-id", value: websiteID),
|
||||
.init("data-domains", value: domains)
|
||||
.init("data-website-id", value: websiteID)
|
||||
]
|
||||
|
||||
if !domains.isEmpty {
|
||||
attributes.append((
|
||||
name: "data-domains",
|
||||
value: domains
|
||||
))
|
||||
attributes.append(.init("data-domains", value: domains))
|
||||
}
|
||||
|
||||
if excludeHash {
|
||||
|
||||
@@ -240,6 +240,17 @@ package extension ConfigReader {
|
||||
)
|
||||
}
|
||||
|
||||
/// The public origin the site is served at (scheme and host, no trailing slash), read from the `site.origin` key.
|
||||
///
|
||||
/// The redirects and any absolute links derive from it, so a staging deployment can point it at itself — or leave it unset — without the
|
||||
/// production origin leaking into its markup.
|
||||
var siteOrigin: String {
|
||||
string(
|
||||
forKey: .Site.origin,
|
||||
default: .Site.origin
|
||||
)
|
||||
}
|
||||
|
||||
/// The directory the static files are served from, read from the `path.staticFiles` key.
|
||||
var staticFilesPath: String {
|
||||
string(
|
||||
|
||||
@@ -98,4 +98,9 @@ extension ConfigKey {
|
||||
/// The configuration key for the `Strict-Transport-Security` header value (omitted when unset).
|
||||
public static let strictTransportSecurity: ConfigKey = "security.strictTransportSecurity"
|
||||
}
|
||||
/// A namespace for the site configuration keys.
|
||||
public enum Site {
|
||||
/// The configuration key for the public origin the site is served at (scheme and host, no trailing slash).
|
||||
public static let origin: ConfigKey = "site.origin"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,4 +50,12 @@ extension String {
|
||||
/// The website server's name.
|
||||
public static let name = "SiteWebsite"
|
||||
}
|
||||
/// A namespace for the site string constants.
|
||||
public enum Site {
|
||||
/// The default public origin the site is served at (scheme and host, no trailing slash): empty, which leaves the HTTPS redirect off.
|
||||
///
|
||||
/// A deployment that trusts the forwarded-protocol header without also setting `site.origin` would otherwise redirect at a host the
|
||||
/// template guessed for it, and a `301` is cached for a long time.
|
||||
public static let origin = ""
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user