Private/Get-GhostContentCount.ps1
|
function Get-GhostContentCount { <# .SYNOPSIS Returns how many posts and pages the Ghost site has. .DESCRIPTION Asks for one post and for one page, and adds up the totals that Ghost reports with them. Drafts count too. Import-GhostContent uses the number to see that an import has arrived: Ghost runs an import in the background and has no request that tells how far it is. .EXAMPLE Get-GhostContentCount Returns 12 for a site with ten posts and two pages. #> [CmdletBinding()] [OutputType([int])] param() $total = 0 foreach ($kind in 'posts', 'pages') { $uri = '{0}?limit=1&fields=id' -f (New-URIString -Endpoint "/$kind/") $answer = Submit-Request -Uri $uri -Method 'Get' $meta = if ($answer) { $answer.PSObject.Properties['meta'] } if ($meta -and $meta.Value -and $meta.Value.PSObject.Properties['pagination']) { $total += [int] $meta.Value.pagination.total } } $total } |