Types/OpenPackage.Publisher/at.markpub.markdown.ps1
|
<# .SYNOPSIS Publishes at.markpub.markdown .DESCRIPTION Publishes any markdown content in a package as at.markpub.markdown. This will take create a static xrpc endpoint that returns all markdown content within a package. #> [CmdletBinding(PositionalBinding=$false)] param( # The destination path. By default _site. [Parameter(Position=0)] [string] $DestinationPath = './_site', # The namespace identifier. By default `at.markpub.markdown` [Alias('NSID')] [ValidatePattern('(?>\.[^\.]+){3,}')] [string] $NamespaceIdentifier = 'at.markpub.markdown', # One or more input packages. # If no packages is provided, will get all markdown files beneath the current directory. [Parameter(ValueFromPipeline)] [Alias('Package')] [PSObject[]] $InputObject ) $allInput = @($input) if (-not $allInput -and $InputObject) { $allInput += $InputObject } if (-not $allInput) { $excludeWildCard = $DestinationPath -replace '^./', '*' -replace '$', '*' $allInput = @(Get-OpenPackage -FilePath . -Include *.md, *.markdown -Exclude $excludeWildCard) } if (-not $allInput) { return } $allInput = @( foreach ($in in $allInput) { if ($in.Package -is [IO.Packaging.Package]) { $in.Package } else { $in } } ) $openPackageXrpc = $allInput | Format-OpenPackage -View at.markpub.markdown $openPackageXrpcPath = Join-Path $DestinationPath "./xrpc/$NamespaceIdentifier/index.json" New-Item -ItemType File -Path $openPackageXrpcPath -Value ( $openPackageXrpc | ConvertTo-Json -Depth 10 ) -Force |