Public/Utilities.ps1
function Use-PodeWebTemplates { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [string] $Title, [Parameter()] [string] $Logo, [Parameter()] [string] $FavIcon, [Parameter()] [string] $Stylesheet, [Parameter()] [ValidateSet('Light', 'Dark', 'Terminal')] [string] $Theme = 'Light' ) $mod = (Get-Module -Name Pode -ErrorAction Ignore) if (($null -eq $mod) -or ($mod.Version.Major -lt 2)) { throw "The Pode module is not loaded. You need at least Pode 2.0 to use the Pode.Web module." } if ([string]::IsNullOrWhiteSpace($FavIcon)) { $FavIcon = '/pode.web/images/favicon.ico' } Set-PodeWebState -Name 'title' -Value $Title Set-PodeWebState -Name 'logo' -Value $Logo Set-PodeWebState -Name 'favicon' -Value $FavIcon Set-PodeWebState -Name 'stylesheet' -Value $Stylesheet Set-PodeWebState -Name 'theme' -Value $Theme.ToLowerInvariant() Set-PodeWebState -Name 'pages' -Value @() $defaultBSColour = 'primary' if ($Theme -ieq 'terminal') { $defaultBSColour = 'success' } Set-PodeWebState -Name 'default-bs-colour' -Value $defaultBSColour $templatePath = Get-PodeWebTemplatePath Add-PodeStaticRoute -Path '/pode.web' -Source (Join-Path $templatePath 'Public') Add-PodeViewFolder -Name 'pode.web.views' -Source (Join-Path $templatePath 'Views') Add-PodeRoute -Method Get -Path '/' -ScriptBlock { $pages = @(Get-PodeWebState -Name 'pages') if (($null -ne $pages) -and ($pages.Length -gt 0)) { Move-PodeResponseUrl -Url "/pages/$($pages[0].Name)" return } Write-PodeWebViewResponse -Path 'index' -Data @{ Page = @{ Name = 'Home' } } } } |