Public/Get-GhostPage.ps1
|
function Get-GhostPage { <# .SYNOPSIS Gets pages from the Ghost site. .DESCRIPTION Without parameters every page is returned, whatever its status. Ghost returns pages in pages; all pages are retrieved unless -Limit or -Page is used, in which case exactly that page is returned. Use -Id or -Slug to get a single page. The content of a page is returned in the lexical property. Use -Formats to get it as HTML or plain text. .EXAMPLE Get-GhostPage Returns every page of the site. .EXAMPLE Get-GhostPage -Filter 'status:draft' -Order 'updated_at desc' -Limit 5 Returns the five drafts that were changed most recently. .EXAMPLE Get-GhostPage -Slug 'welcome' -Formats html, plaintext Returns the page with the slug welcome, with its content as HTML and as plain text. .EXAMPLE Get-GhostPage -Fields id, title, status Returns only the id, the title and the status of every page, which is much faster on a large site. .LINK https://docs.ghost.org/admin-api/pages/overview #> [CmdletBinding(DefaultParameterSetName = 'Browse')] [OutputType('Ghost.Page')] param( # Id of the page to get. [Parameter(Mandatory, ParameterSetName = 'Id', Position = 0, ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [string] $Id, # Slug of the page to get. [Parameter(Mandatory, ParameterSetName = 'Slug')] [ValidateNotNullOrEmpty()] [string] $Slug, # Filter in the Ghost query language (NQL), such as status:draft or tag:news+featured:true. [Parameter(ParameterSetName = 'Browse')] [string] $Filter, # Sort order, such as 'published_at desc' or 'title asc'. [Parameter(ParameterSetName = 'Browse')] [string] $Order, # Number of pages in a page, 100 at most. Returns a single page instead of every page. [Parameter(ParameterSetName = 'Browse')] [ValidateRange(1, 100)] [int] $Limit, # Number of the page to return. Returns a single page instead of every page. [Parameter(ParameterSetName = 'Browse')] [ValidateRange(1, [int]::MaxValue)] [int] $Page, # Related data to include, such as authors and tags. [string[]] $Include, # Formats to return the content in. Ghost returns lexical when this is not used. [ValidateSet('html', 'plaintext', 'lexical', 'mobiledoc')] [string[]] $Formats, # Names of the properties to return, to limit the size of the response. [string[]] $Fields ) begin { Test-GhostConnection $resources = Get-GhostAPIData -Endpoint $MyInvocation.MyCommand.Name } process { try { # Every page is retrieved unless the caller asked for a specific one. $singlePage = $PSBoundParameters.ContainsKey('Limit') -or $PSBoundParameters.ContainsKey('Page') $paginate = $PSCmdlet.ParameterSetName -eq 'Browse' -and -not $singlePage $uri = New-URIString -Endpoint $resources.URI[$PSCmdlet.ParameterSetName] -Parameters $PSBoundParameters $uri = New-QueryString -Uri $uri -QueryKeys $resources.Query -Parameters $PSBoundParameters $result = Submit-Request -Uri $uri -Method $resources.Method -Success $resources.Success -Paginate:$paginate $result = Test-ReturnFormat -Result $result -Location $resources.Result Set-ObjectTypeName -InputObject $result -TypeName $resources.TypeName } catch { $PSCmdlet.ThrowTerminatingError($_) } } } |