Public/Enable-GhostTheme.ps1
|
function Enable-GhostTheme { <# .SYNOPSIS Activates a theme on the Ghost site. .DESCRIPTION Makes a theme that is on the site the active one and returns it. The site shows the theme right away, and the theme that was active before stays on the site. To go back, activate that one again. The name is the name Ghost stored the theme under, which is the name of the zip file it was uploaded with. New-GhostTheme returns it, and New-GhostTheme -Activate uploads and activates in one go. Ghost does not let an integration list the themes of a site. Which theme is active is in the setting active_theme, which Ghost Admin shows under Settings > Design. .EXAMPLE Enable-GhostTheme -Name 'my-theme' Activates the theme my-theme. .EXAMPLE New-GhostTheme -Path ./dist/my-theme.zip | Enable-GhostTheme Uploads a theme and activates it. .EXAMPLE Enable-GhostTheme -Name 'source' Goes back to Source, the theme a new site starts with. .LINK https://docs.ghost.org/admin-api/themes/overview #> [CmdletBinding(SupportsShouldProcess)] [OutputType('Ghost.Theme')] param( # Name of the theme to activate. [Parameter(Mandatory, Position = 0, ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [string] $Name ) begin { Test-GhostConnection $resources = Get-GhostAPIData -Endpoint $MyInvocation.MyCommand.Name } process { try { $uri = New-URIString -Endpoint $resources.URI -Parameters $PSBoundParameters if ($PSCmdlet.ShouldProcess($Name, $resources.Description)) { $result = Submit-Request -Uri $uri -Method $resources.Method -Success $resources.Success $result = Test-ReturnFormat -Result $result -Location $resources.Result Set-ObjectTypeName -InputObject $result -TypeName $resources.TypeName } } catch { $PSCmdlet.ThrowTerminatingError($_) } } } |