public/Write-CmdletFrontMatter.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51


function Write-CmdletFrontMatter() {
    Param(
        [Parameter(Position = 0)]
        [PsCustomObject] $Model
    )
    $name = $Model.Name;

    if($name) {
        $hyphenatedName = $model.HyphenatedName
        $now = [DateTime]::UtcNow
        $now = $now.ToString()

        $out = "---`n"
        $out += "title: $name`n"
        if($model.Author) {
            $out += "authors: [`"$($model.Author)`"]`n"
        }
        if($model.PublishedAt) {
            $out += "publishedAt: $($model.PublishedAt)`n"
        }
        if($model.Company) {
            $out += "company: $($model.PublishedAt)`n"
        }
        if($model.Version) {
            $out += "version: $($model.Version)`n"
        }
        if($model.ModuleName) {
            $out += "module: $($model.ModuleName)`n"
        }
        if($model.UpdatedAt) {
            $out += "updatedAt: $($model.UpdatedAt)`n"
        }
        $uri = $hyphenatedName + ".md"
        if($model.BaseUri) {
            $uri = $model.BaseUri + "/" + $hyphenatedName + ".md"
        }
        if($model.Tags -and $model.Tags.Count) {
            $tags = [String]::Join("`",`"", $model.Tags)
            $out += "tags: [`"$tags`"]`n"
        }
        $out += "uri: $uri`n"

        $out += "---`n`n"

        return $out;
    }

    return ""
}