Public/Set-GhostTag.ps1
|
function Set-GhostTag { <# .SYNOPSIS Updates a tag on the Ghost site. .DESCRIPTION Changes the properties that are passed and leaves every other property of the tag as it is. Pass an empty string to clear a text property. Changing the slug changes the address of the page of the tag; Ghost does not redirect the old address. The posts that have the tag keep it. Unlike a post, a tag is not protected against a change that somebody else made in the meantime: the update always applies. .EXAMPLE Set-GhostTag -Id '5ddc9063c35e7700383b27e0' -Description 'Announcements and updates.' Changes the description of the tag. .EXAMPLE Get-GhostTag -Slug 'news' | Set-GhostTag -Name 'Announcements' -Slug 'announcements' Renames the tag News and gives it a new address. .EXAMPLE Get-GhostTag -Filter 'visibility:public' | Set-GhostTag -AccentColor '#ff5500' Gives every public tag the same accent color. .EXAMPLE Set-GhostTag -Id '5ddc9063c35e7700383b27e0' -MetaDescription '' Clears the description for search engines. .LINK https://docs.ghost.org/admin-api .LINK https://docs.ghost.org/content-api/tags #> [CmdletBinding(SupportsShouldProcess)] [OutputType('Ghost.Tag')] param( # Id of the tag to update. [Parameter(Mandatory, Position = 0, ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [string] $Id, # Name of the tag. A name that starts with # makes it an internal tag. [ValidateNotNullOrEmpty()] [string] $Name, # Slug of the tag, the last part of its address. [ValidateNotNullOrEmpty()] [string] $Slug, # Description of the tag, 500 characters at most. [string] $Description, # Address of the feature image. [string] $FeatureImage, # Whether the tag is shown on the site. Ghost derives it from the name: internal for a name that starts # with #, public for any other. [ValidateSet('public', 'internal')] [string] $Visibility, # Accent color of the tag as a hexadecimal color, such as #ff5500. An empty string clears it. [ValidatePattern('^(#[0-9a-fA-F]{6})?$')] [string] $AccentColor, # Canonical address of the page of the tag, when the original lives somewhere else. [string] $CanonicalUrl, # Title for search engines. [string] $MetaTitle, # Description for search engines. [string] $MetaDescription, # Open Graph image, used when the page of the tag is shared. [string] $OgImage, # Open Graph title. [string] $OgTitle, # Open Graph description. [string] $OgDescription, # Image for the X (Twitter) card. [string] $TwitterImage, # Title for the X (Twitter) card. [string] $TwitterTitle, # Description for the X (Twitter) card. [string] $TwitterDescription, # Code injected in the head of the page of the tag. [string] $CodeInjectionHead, # Code injected before the end of the body of the page of the tag. [string] $CodeInjectionFoot ) begin { Test-GhostConnection $resources = Get-GhostAPIData -Endpoint $MyInvocation.MyCommand.Name } process { try { $uri = New-URIString -Endpoint $resources.URI -Parameters $PSBoundParameters $body = New-BodyString -BodyKeys $resources.Body -Parameters $PSBoundParameters -Wrapper $resources.Result if (-not $body) { throw 'Nothing to update: pass at least one property of the tag, such as -Name or -Description.' } if ($PSCmdlet.ShouldProcess($Id, $resources.Description)) { $result = Submit-Request -Uri $uri -Method $resources.Method -Body $body -Success $resources.Success $result = Test-ReturnFormat -Result $result -Location $resources.Result Set-ObjectTypeName -InputObject $result -TypeName $resources.TypeName } } catch { $PSCmdlet.ThrowTerminatingError($_) } } } |