Private/Get-GhostSyncFile.ps1

function Get-GhostSyncFile {
    <#
    .SYNOPSIS
        Returns the Markdown files that a Sync command works on.

    .DESCRIPTION
        A path can be a file, a folder or a pattern with wildcards. A file is returned as it is. A folder gives
        its Markdown files, the ones that end in .md, and with Recurse those in the folders below it as well. A
        file that is named README.md says what a folder is for. It is never a post, a page or a tag.

        A path that exists is taken literally, so that brackets in a file name are not read as wildcards.

        The files of one path are returned in the order of their full path. That makes a run do the same thing
        in the same order on every machine.

    .EXAMPLE
        Get-GhostSyncFile -Path ./posts -Recurse

        Returns every .md file in the folder posts and the folders below it, except the README.md files.

    .EXAMPLE
        Get-GhostSyncFile -Path ./tags/news.md

        Returns that one file.
    #>

    [CmdletBinding()]
    [OutputType([System.IO.FileInfo])]
    param(
        # Files, folders or patterns with wildcards.
        [Parameter(Mandatory)]
        [string[]] $Path,

        # Also return the .md files in the folders below a folder.
        [switch] $Recurse
    )

    foreach ($item in $Path) {
        $found = if (Test-Path -LiteralPath $item) {
            Get-Item -LiteralPath $item
        }
        else {
            Get-Item -Path $item
        }
        $files = foreach ($entry in $found) {
            if ($entry.PSIsContainer) {
                Get-ChildItem -LiteralPath $entry.FullName -File -Recurse:$Recurse |
                    Where-Object { $_.Extension -eq '.md' -and $_.BaseName -ne 'README' }
            }
            else {
                $entry
            }
        }

        $files | Sort-Object -Property FullName
    }
}