-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPSJekyll.types.ps1xml
2102 lines (1869 loc) · 61.8 KB
/
PSJekyll.types.ps1xml
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!-- Generated with EZOut 2.0.6: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<Types>
<Type>
<Name>PSJekyll</Name>
<Members>
<AliasProperty>
<Name>Site</Name>
<ReferencedMemberName>CurrentSite</ReferencedMemberName>
</AliasProperty>
<ScriptMethod>
<Name>FormatMarkdown</Name>
<Script>
<#
.SYNOPSIS
Formats an object as Markdown
.DESCRIPTION
Formats an object as Markdown, with many options to work with
.EXAMPLE
Format-Markdown -ScriptBlock {
Get-Process
}
.EXAMPLE
1..6 | Format-Markdown -HeadingSize { $_ }
#>
param(
[Parameter(ValueFromPipeline,ValueFromPipelineByPropertyName)]
[PSObject]
$InputObject,
# If set, will treat the -InputObject as a paragraph.
# This is the default for strings, booleans, numbers, and other primitive types.
[Parameter(ValueFromPipelineByPropertyName)]
[switch]
$MarkdownParagraph,
# If set, will generate a markdown table.
[Parameter(ValueFromPipelineByPropertyName)]
[switch]
$MarkdownTable,
# If provided, will align columnns in a markdown table.
[Parameter(ValueFromPipelineByPropertyName)]
[ValidateSet("Left","Right","Center", "")]
[string[]]
$MarkdownTableAlignment,
# An array of properties. Providing this implies -MarkdownTable
[Parameter(ValueFromPipelineByPropertyName)]
[PSObject[]]
$Property,
# A heading.
# If provided without -HeadingSize, -HeadingSize will default to 2.
# If provided with -InputObject, -Heading will take priority.
[Parameter(ValueFromPipelineByPropertyName)]
[string]
$Heading,
# The heading size (1-6)
# If provided without -Heading, the -InputObject will be considered to be a heading.
[Parameter(ValueFromPipelineByPropertyName)]
[ValidateRange(1,6)]
[int]
$HeadingSize,
# If set, will create a link. The -InputObject will be used as the link content
[Parameter(ValueFromPipelineByPropertyName)]
[Alias('Hyperlink', 'Href')]
[string]
$Link,
# If set, will create an image link. The -Inputobject will be used as the link content.
[Parameter(ValueFromPipelineByPropertyName)]
[string]
$ImageLink,
# If set, will generate a bullet point list.
[Parameter(ValueFromPipelineByPropertyName)]
[Alias('BulletpointList')]
[switch]
$BulletPoint,
# If set, bullet or numbered list items will have a checkbox.
# Each piped -InputObject will be an additional list item.
[Parameter(ValueFromPipelineByPropertyName)]
[switch]
$Checkbox,
# If set, bullet or numbered list items will be checked.
[Parameter(ValueFromPipelineByPropertyName)]
[switch]
$Checked,
# If set, will generate a numbered list.
# Each piped -InputObject will be an additional list item.
[Parameter(ValueFromPipelineByPropertyName)]
[switch]
$NumberedList,
# If set, will generate a block quote.
# Each line of the -InputObject will be block quoted.
[Parameter(ValueFromPipelineByPropertyName)]
[switch]
$BlockQuote,
# If set, will generate a block quote of a particular depth.
# Each line of the -InputObject will be block quoted.
[Parameter(ValueFromPipelineByPropertyName)]
[ValidateRange(1,3)]
[int]
$BlockQuoteDepth,
# If provided, will create a markdown numbered list with this particular item as the number.
[Parameter(ValueFromPipelineByPropertyName)]
[int]
$Number,
# If set, will generate a horizontal rule.
# If other parameters are provided, the horiztonal rule will be placed after.
[Parameter(ValueFromPipelineByPropertyName)]
[switch]
$HorizontalRule,
# If set, will output the -InputObject as a Markdown code block
[Parameter(ValueFromPipelineByPropertyName)]
[switch]
$Code,
# If set, will output the -InputObject as a Markdown code block, with a given language
# If the -InputObject is a ScriptBlock, -CodeLanguage will be set to PowerShell.
[Parameter(ValueFromPipelineByPropertyName)]
[string]
$CodeLanguage,
# If provided, will output a script block as a Markdown code block.
[Parameter(ValueFromPipelineByPropertyName)]
[ScriptBlock]
$ScriptBlock
)
begin {
$numberedListCounter = 0
$IsFirst = $true
filter LinkInput {
$in = $_
if ($ImageLink) {
""
} elseif ($link) {
"[$in]($link)"
} else {
"$in"
}
}
$markdownLines = @()
}
process {
if ($ScriptBlock -or $inputObject -is [scriptblock]) { # If a -ScriptBlock was provided
$CodeLanguage = 'PowerShell' # use PowerShell as a Code Language.
}
# If a -HeadingSize or a -Heading were provided, render a heading.
if ($HeadingSize -or $Heading)
{
if (-not $HeadingSize) { $HeadingSize = 2} # If the -HeadingSize was not set, set it to 2.
$headingContent = "$(if ($Heading) { $Heading} else { $inputObject | LinkInput})"
$markdownLines +=
if ($HeadingSize -eq 1) {
$headingContent
'=' * [Math]::Max($headingContent.Length, 3)
}
elseif ($HeadingSize -eq 2) {
$headingContent
'-' * [Math]::Max($headingContent.Length, 3)
}
else {
("#"*$HeadingSize) + " $headingContent" # Output the -Heading or the -InputObject.
}
}
# If -Code or -CodeLanguage was provided, render a Markdown code block.
elseif ($Code -or $CodeLanguage)
{
# If the -InputObject was a [ScriptBlock] or there is a -ScriptBlock
if ($InputObject -is [scriptblock] -or $ScriptBlock) {
$CodeLanguage = 'PowerShell' # set the code language to PowerShell.
}
$markdownLines += (
'```' + # Start the code fence,
$(if ($CodeLanguage) { $CodeLanguage}) + # add the language,
[Environment]::newline + # then a newline,
$(
$codeContent = $(if ($ScriptBlock) { "$scriptBlock" } else { $inputObject | LinkInput}) # then the -ScriptBlock or -InputObject
$codeContent
) +
[Environment]::newline + # then a newline
'```' # then close the code fence.
)
}
# If -BulletPoint was passed, render a Bullet Point list.
elseif ($BulletPoint)
{
$markdownLines += "*$(if ($Checkbox) { "[$(if ($Checked) {"x"} else {" "})]"}) $($inputObject | LinkInput)"
}
# If -NumberedList was passed, render a numbered list.
elseif ($NumberedList -or $Number)
{
$numberedListCounter++ # Increment the counter
$markdownLines += "$(if ($number) { $number } else {$numberedListCounter}).$(if ($Checkbox) {" [$(if ($Checked) {"x"} else {" "})]"}) $($inputObject | LinkInput)"
}
elseif ($BlockQuote -or $BlockQuoteDepth) {
if (-not $BlockQuoteDepth) { $BlockQuoteDepth = 1 }
$markdownLines += (">" * $BlockQuoteDepth ) + ' ' + (
"$inputObject" -split '(?>\r\n|\n)' -join (
[Environment]::NewLine + (">" * $BlockQuoteDepth) + ' '
)
)
}
# Otherwise, we have to determine if -InputObject should be a -MarkdownTable or a -MarkdownParagraph.
else
{
# If the input is a primitive type or a string, it should be a markdown paragraph
if (($inputObject.GetType -and $inputObject.GetType().IsPrimitive) -or
$inputObject -is [string]) {
$MarkdownParagraph = $true
}
# If it is a dictionary, it should be a markdown table.
elseif ($inputObject -is [Collections.IDictionary])
{
$MarkdownTable = $true
}
# If the input is an array, apply the same logic:
elseif ($inputObject -is [Object[]] -or $InputObject -is [PSObject[]]) {
$allPrimitives = 1
# if the array was all primitives or strings
foreach ($in in $InputObject) {
$allPrimitives = $allPrimitives -band (
($in.GetType -and $in.GetType().IsPrimitive) -or $in -is [string]
)
}
if ($allPrimitives) { # output as a paragraph.
$MarkdownParagraph = $true
} else {
$MarkdownTable = $true
}
}
# If we're still not sure, output as a table.
else {
$MarkdownTable = $true
}
}
if ($MarkdownParagraph) {
# If we're outputting as a paragraph, add the input and link it if needed.
$markdownLines += $inputObject | LinkInput
} elseif ($MarkdownTable) {
# If we're rendering a table, we need to go row-by-row.
foreach ($in in $InputObject) {
$propertyList = @(
# we first need to get a list of properties.
# If there was a -Property parameter provided, use it.
if ($Property) {
foreach ($prop in $Property) {
if ($prop -is [string]) { # Strings in -Property should be taken as property names
$prop
} elseif ($prop.Name -and $prop.Expression -and $prop.Expression -is [scriptblock]) {
# and anything with a name and expression script block will run the expression script block.
$_ = $psItem = $in
@{name=$prop.Name;Value = . $prop.Expression}
}
}
}
# Otherwise, if the input was a dictionary
elseif ($in -is [Collections.IDictionary])
{
foreach ($k in $in.Keys) { # take all keys from the dictionary
if ($MyInvocation.MyCommand.Parameters[$k]) { continue } # that are not parameters of this function.
$k
}
}
# Otherwise, walk over all properties on the object
else {
foreach ($psProp in $In.psobject.properties) {
# and skip any properties that are parameters of this function.
if ($psProp.Name -notin $MyInvocation.MyCommand.Parameters.Keys) {
$psProp
}
}
}
)
# If we're rendering the first row of a table
if ($IsFirst) {
# Create the header
$markdownLines +=
'|' + (@(foreach ($prop in $propertyList) {
if ($prop -is [string]) {
$prop
} else {
$prop.Name
}
}) -replace ([Environment]::newline), '<br/>' -replace '\|', '\|' -join '|') + '|'
# Then create the alignment row.
$markdownLines +=
'|' + $(
$columnNumber =0
@(
foreach ($prop in $propertyList) {
$colLength =
if ($prop -is [string]) {
$prop.Length
} else {
$prop.Name.Length
}
if ($MarkdownTableAlignment) {
if ($MarkdownTableAlignment[$columnNumber] -eq 'Left') {
':' + ("-" * ([Math]::Max($colLength,2) - 1))
}
elseif ($MarkdownTableAlignment[$columnNumber] -eq 'Right') {
("-" * ([Math]::Max($colLength,2) - 1)) + ':'
}
elseif ($MarkdownTableAlignment[$columnNumber] -eq 'Center') {
':' + ("-" * ([Math]::max($colLength, 3) - 2)) + ':'
} else {
"-" * $colLength
}
} else {
"-" * $colLength
}
$columnNumber++
}
) -replace ([Environment]::newline), '<br/>' -replace '\|', '\|' -join '|') + '|'
$IsFirst = $false
}
# Now we create the row for this object.
$markdownLine = '|' + (
@(
foreach ($prop in $propertyList) {
if ($prop -is [string]) {
$in.$prop | LinkInput
} else {
$prop.Value | LinkInput
}
}
) -replace ([Environment]::newline), '<br/>' -replace '\|', '\|' -join '|') + '|'
$markdownLines += $markdownLine
}
}
if ( # There are a few combinations of parameters that make us want to write the -InputObject as a paragraph:
($ScriptBlock -and $inputObject) -or # * If -ScriptBlock and -InputObject were both provided.
($Heading -and $inputObject) # * if -Heading and -InputObject were both provided
) {
$markdownLines += $InputObject | LinkInput
}
# If we're going to render a horizontal rule (and -MarkdownTable has not been set)
if ($HorizontalRule -and -not $MarkdownTable) {
# add the horizontal rule at the end.
if ($host.UI.RawUI.BufferSize.Width) {
$markdownLines += (([string]$HorizontalRuleCharacter) * ($Host.UI.RawUI.BufferSize.Width - 1))
} else {
$markdownLines += "---"
}
}
}
end {
# Now we need to make one last pass to normalize tables
if ($markdownLines -match '^\|') { # (that is, if we have tables to normalize).
$maxColumnSize = @{} # To normalize the table, we need to track the maximum size per column
foreach ($ml in $markdownLines) {
if ($ml -match '\^|') {
$columnCount = 0
foreach ($tablePart in $ml -split '(?<!\\)\|' -ne '') {
if ((-not $maxColumnSize[$columnCount]) -or $maxColumnSize[$columnCount] -lt $tablePart.Length) {
$maxColumnSize[$columnCount] = [Math]::Max($tablePart.Length, 2)
}
$columnCount++
}
}
}
# One we know the maximum size per column, walk over each line
$markdownLines = @(foreach ($ml in $markdownLines) {
if ($ml -match '\^|') {
$columnCount = 0
# Recreate the line with the right amount of padding.
'|' + (@(foreach ($tablePart in $ml -split '(?<!\\)\|' -ne '') {
if ($tablePart -match '^[:\-]+$') {
if ($tablePart -match '^\:-{0,}\:$') { # If it's an alignment column, make sure to keep the alignment.
if ($maxColumnSize[$columnCount] -gt 2) {
':' + ('-' * ($maxColumnSize[$columnCount] - 2)) + ':'
} else {
'::'
}
}
elseif ($tablePart -match '\:$') {
$tablePart.PadLeft($maxColumnSize[$columnCount], '-')
}
elseif ($tablePart -match '^\:') {
$tablePart.PadRight($maxColumnSize[$columnCount], '-')
}
else {
$tablePart.PadRight($maxColumnSize[$columnCount], '-')
}
} else {
$tablePart.PadRight($maxColumnSize[$columnCount], ' ')
}
$columnCount++
}) -join '|') + '|'
} else {
$ml
}
})
}
$markdownLines -join [Environment]::NewLine
}
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>FormatYAML</Name>
<Script>
<#
.SYNOPSIS
Formats objects as YAML
.DESCRIPTION
Formats an object as YAML.
.EXAMPLE
Format-Yaml -InputObject @("a", "b", "c")
.EXAMPLE
@{a="b";c="d";e=@{f=@('g')}} | Format-Yaml
#>
param(
# The InputObject.
[Parameter(ValueFromPipeline)]
[PSObject]
$InputObject,
# If set, will make a YAML header by adding a YAML Document tag above and below output.
[Alias('YAMLDocument')]
[switch]
$YamlHeader,
[int]
$Indent = 0,
# The maximum depth of objects to include.
# Beyond this depth, an empty string will be returned.
[int]
$Depth
)
begin {
if (-not $Depth) { $depth = $FormatEnumerationLimit }
$toYaml = {
param(
[Parameter(ValueFromPipeline,Position=0)]$Object,
[Object]$Parent,
[Object]$GrandParent,
[int]$Indent = 0)
begin { $n = 0; $mySelf = $myInvocation.MyCommand.ScriptBlock }
process {
$n++
if ($Object -eq $null) { return }
if ($depth) {
$myDepth = $indent / 2
if ($myDepth -gt $depth) {
return ''
}
}
if ($Parent -and $Parent -is [Collections.IList]) {
if ($Parent.IndexOf($Object) -gt 0) { ' ' * $Indent }
'- '
}
#region Primitives
if ( $Object -is [string] ) { # If it's a string
if ($object -match '\n') { # see if it's a multline string.
"|" # If it is, emit the multiline indicator
$indent +=2
foreach ($l in $object -split '(?>\r\n|\n)') { # and emit each line indented
[Environment]::NewLine
' ' * $indent
$l
}
$indent -=2
} elseif ("$object".Contains('*')) {
"'$($Object -replace "'","''")'"
} else {
$object
}
if ($Parent -is [Collections.IList]) { # If the parent object was a list
[Environment]::NewLine # emit a newline.
}
return # Once the string has been emitted, return.
}
if ( $Object.GetType().IsPrimitive ) { # If it is a primitive type
"$Object".ToLower() # Emit it in lowercase.
if ($Parent -is [Collections.IList]) {
[Environment]::NewLine
}
return
}
#endregion Primitives
#region KVP
if ( $Object -is [Collections.DictionaryEntry] -or $object -is [Management.Automation.PSPropertyInfo]) {
if ($Parent -isnot [Collections.IList] -and
($GrandParent -isnot [Collections.IList] -or $n -gt 1)) {
[Environment]::NewLine + (" " * $Indent)
}
if ($object.Key -and $Object.Key -is [string]) {
$Object.Key +": "
} elseif ($object.Name -and $object.Name -is [string]) {
$Object.Name +": "
}
}
if ( $Object -is [Collections.DictionaryEntry] -or $Object -is [Management.Automation.PSPropertyInfo]) {
& $mySelf -Object $Object.Value -Parent $Object -GrandParent $parent -Indent $Indent
return
}
#endregion KVP
#region Nested
if ($parent -and ($Object -is [Collections.IDictionary] -or $Object -is [PSObject])) {
$Indent += 2
}
elseif ($object -is [Collections.IList]) {
$allPrimitive = 1
foreach ($Obj in $Object) {
$allPrimitive = $allPrimitive -band (
$Obj -is [string] -or
$obj.GetType().IsPrimitive
)
}
if ($parent -and -not $allPrimitive) {
$Indent += 2
}
}
if ( $Object -is [Collections.IDictionary] ) {
$Object.GetEnumerator() |
& $mySelf -Parent $Object -GrandParent $Parent -Indent $Indent
} elseif ($Object -is [Collections.IList]) {
[Environment]::NewLine + (' ' * $Indent)
$Object |
& $mySelf -Parent $Object -GrandParent $Parent -Indent $Indent
}
elseif ($object -is [enum]) {
$object.ToString()
}
elseif ($Object.PSObject.Properties) {
$Object.psobject.properties |
& $mySelf -Parent $Object -GrandParent $Parent -Indent $Indent
}
if ($Object -is [Collections.IDictionary] -or $Object -is [PSCustomObject] -or $Object -is [Collections.IList]) {
if ($Parent -is [Collections.IList]) { [Environment]::NewLine }
$Indent -= 2;
}
#endregion Nested
}
}
function IndentString([string]$String,[int]$Indent) {
@(foreach ($line in @($String -split '(?>\r\n|\n)')) {
(' ' * $indent) + $line
}) -join [Environment]::NewLine
}
$inputWasNotPiped = $PSBoundParameters.InputObject -as [bool]
$allInputObjects = @()
}
process {
if ($inputWasNotPiped) {
IndentString ('' + $(if ($YamlHeader) { '---' + [Environment]::NewLine }) + (
(& $toYaml -object $inputObject) -join '' -replace
"$([Environment]::NewLine * 2)", [Environment]::NewLine
) + $(if ($YamlHeader) { [Environment]::NewLine + '---'})) -Indent $Indent
} else {
$allInputObjects += $inputObject
}
}
end {
if (-not $allInputObjects) { return }
if ($allInputObjects.Length -eq 1) {
IndentString ('' + $(if ($YamlHeader) { '---' + [Environment]::NewLine}) + (
(& $toYaml -object $inputObject) -join '' -replace
"$([Environment]::NewLine * 2)", [Environment]::NewLine
) + $(if ($YamlHeader) { [Environment]::NewLine + '---'})) -Indent $Indent
} else {
IndentString ('' + $(if ($YamlHeader) { '---' + [Environment]::NewLine}) + (
(& $toYaml -object $allInputObjects) -join '' -replace
"$([Environment]::NewLine * 2)", [Environment]::NewLine
) + $(if ($YamlHeader) { [Environment]::NewLine + '---'})) -Indent $Indent
}
}
</Script>
</ScriptMethod>
<ScriptProperty>
<Name>CurrentSite</Name>
<GetScriptBlock>
<#
.SYNOPSIS
Gets the current site.
.DESCRIPTION
Gets one or more current Jekyll sites.
The current site is any directory containing a _config.yml.
If no directory is found, it will consider the the current directory to be the site.
.EXAMPLE
$psJekyll.CurrentSite
#>
param(
$this = $PSJekyll
)
$jekyllConfigFiles = Get-ChildItem -Path $pwd -Recurse -Filter _config.yml
if (-not $jekyllConfigFiles) {
$currentFolder = Get-Item $pwd
[PSCustomObject]@{
PSTypeName = 'PSJekyll.Site'
Directory = $currentFolder
SiteName = $currentFolder.Name
}
}
foreach ($jekyllConfigFile in $jekyllConfigFiles) {
[PSCustomObject]@{
PSTypeName = 'PSJekyll.Site'
Directory = $jekyllConfigFile.Directory
SiteName = $jekyllConfigFile.Directory.Name
}
}
</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>Template</Name>
<GetScriptBlock>
[PSCustomObject]@{PSTypeName='PSJekyll.Template'}
</GetScriptBlock>
</ScriptProperty>
</Members>
</Type>
<Type>
<Name>PSJekyll.Site</Name>
<Members>
<AliasProperty>
<Name>Drafts</Name>
<ReferencedMemberName>Draft</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Files</Name>
<ReferencedMemberName>File</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Includes</Name>
<ReferencedMemberName>Include</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Layouts</Name>
<ReferencedMemberName>Layout</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Pages</Name>
<ReferencedMemberName>Page</ReferencedMemberName>
</AliasProperty>
<AliasProperty>
<Name>Posts</Name>
<ReferencedMemberName>Post</ReferencedMemberName>
</AliasProperty>
<ScriptProperty>
<Name>404</Name>
<GetScriptBlock>
<#
.SYNOPSIS
Gets the 404 of the site.
.DESCRIPTION
Gets a custom 404 of a Jekyll site.
This can be provided by a 404.html file in the root of the site.
.EXAMPLE
$psJekyll.CurrentSite.404
#>
param()
$404File = Join-Path $this.Directory "404.html"
if (Test-Path $404File) {
Get-Item -Path $404File
}
</GetScriptBlock>
<SetScriptBlock>
<#
.SYNOPSIS
Sets the 404 of the site.
.DESCRIPTION
Sets a custom 404 of a Jekyll site.
This can be provided by a 404.html file in the root of the site.
.EXAMPLE
$psJekyll.CurrentSite.404 = "File Not Found"
#>
param()
$this.Page = @("404.html") + $args
</SetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>Config</Name>
<GetScriptBlock>
<#
.SYNOPSIS
Gets the config of the site.
.DESCRIPTION
Gets the configuration of the Jekyll site.
This can be provided by a _config.yml file in the root of the site (and essentially marks it as a site)
.EXAMPLE
$psJekyll.CurrentSite.Config
#>
param()
$configFile = Join-Path $this.Directory "_config.yml"
if (Test-Path $configFile) {
Get-Item -Path $configFile
}
</GetScriptBlock>
<SetScriptBlock>
<#
.SYNOPSIS
Gets the config of the site.
.DESCRIPTION
Gets the configuration of the Jekyll site.
This can be provided by a _config.yml file in the root of the site (and essentially marks it as a site)
.EXAMPLE
$psJekyll.CurrentSite.Config = [Ordered]@{
title = 'My Awesome Site'
description = 'This is a site that is awesome.'
permalink = 'pretty'
}
#>
param(
# The new configuration object.
# This will be converted to YAML and added to the _config.yml file.
$Value
)
$configFile = Join-Path $this.Directory "_config.yml"
$valueToAdd =
if ($value -is [string]) {
$value
}
elseif ($value -is [IO.FileInfo]) {
Get-Content -Path $value.FullName
}
else {
& $PSJekyll.FormatYAML.Script $value
}
New-Item -ItemType File -Path $configFile -Force -Value $valueToAdd
</SetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>Data</Name>
<GetScriptBlock>
<#
.SYNOPSIS
Gets data files in a Jekyll site
.DESCRIPTION
Gets data files in a Jekyll site, using PowerShell.
This will return the file objects in the _data folder.
#>
param()
foreach ($specialFile in $this.File -match '[\\/]_data[\\/]') {
$specialFile.pstypenames.add("PSJekyll.DataFile")
$specialFile
}
</GetScriptBlock>
<SetScriptBlock>
<#
.SYNOPSIS
Sets data files in a Jekyll site
.DESCRIPTION
Sets data files in a Jekyll site, using PowerShell.
Data files are a simple and powerful way to add custom data to your site.
Simply use this to set a property, and the data will be available in Jekyll within `site.data`
#>
param()
$unrolledArguments = @($args | . { process { $_ } })
$currentName = ''
filter toJsonFileName {
$_ -replace '(?:\.json)?$', '.json'
}
foreach ($arg in $unrolledArguments) {
if ($arg -is [Collections.IDictionary]) {
foreach ($keyValue in $arg.GetEnumerator()) {
$targetPath =
$this.Directory,"_data",($keyValue.Key | toJsonFileName) -join
[IO.Path]::DirectorySeparatorChar -replace
'[\\/]', [IO.Path]::DirectorySeparatorChar
New-Item -Path $targetPath -ItemType File -Force -Value (
ConvertTo-Json -Depth $FormatEnumerationLimit -InputObject $($keyValue.Value)
)
}
}
elseif ($arg -is [string]) {
$currentName = $arg
}
elseif ($currentName) {
$targetPath = $this.Directory,"_data",($currentName | toJsonFileName) -join
[IO.Path]::DirectorySeparatorChar -replace
'[\\/]', [IO.Path]::DirectorySeparatorChar
New-Item -Path $targetPath -ItemType File -Force -Value (
ConvertTo-Json -Depth ($FormatEnumerationLimit * 2) -InputObject $arg
)
}
}
</SetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>Domain</Name>
<GetScriptBlock>
<#
.SYNOPSIS
Gets the domain name of the site.
.DESCRIPTION
Gets the domain name of the Jekyll site.
This can be provided by a CNAME file in the root of the site.
.EXAMPLE
$PSJekyll.CurrentSite.Domain
#>
$cNamePath = Join-Path $this.Directory "CNAME"
if (Test-Path $cNamePath) {
Get-Content -Path $cNamePath
}
</GetScriptBlock>
<SetScriptBlock>
<#
.SYNOPSIS
Sets the domain name of the site.
.DESCRIPTION
Sets the domain name of the Jekyll site.
This will create a CNAME file in the root of the site.
This will also attempt to resolve the domain name to ensure it is valid, and will write a warning if it is not.
.EXAMPLE
$PSJekyll.CurrentSite.Domain = 'psjekyll.powershellweb.com'
#>
param([string]$cname)
$cNamePath = Join-Path $this.Directory "CNAME"
New-Item -ItemType File -Path $cNamePath -Force -Value $cname
$tryToResolveCName = try {
[Net.Dns]::Resolve($cname)
} catch {
Write-Warning "Could not resolve the domain name '$cname'."
}
</SetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>Draft</Name>
<GetScriptBlock>
<#
.SYNOPSIS
Gets drafts in a Jekyll site.
.DESCRIPTION
Gets drafts in a Jekyll site, using PowerShell.
This will return the file objects in the `_drafts` folder.
#>
param()
foreach ($specialFile in $this.File -match '[\\/]_drafts[\\/]') {
$specialFile.pstypenames.add("PSJekyll.Draft.Post")
$specialFile.pstypenames.add("PSJekyll.Post")
$specialFile
}
</GetScriptBlock>
<SetScriptBlock>
<#
.SYNOPSIS
Sets a draft in a Jekyll site.
.DESCRIPTION
Sets a draft in a Jekyll site, using PowerShell.
This will create a new draft in the `_drafts` folder.
If no metadata is provided, it will default to the current date and the title of the draft.
#>
param()
$unrolledArguments = @($args | . { process { $_ } })
$currentName = ''
filter toMarkdownFileName {
$_ -replace '(?:\.md)?$', '.md' -replace '[\s\p{P}]','-'
}
$name, $content, $metdata = $null, $null, $null
foreach ($arg in $unrolledArguments) {
if ($arg -is [Collections.IDictionary]) {
$metadata = $arg
}
elseif ($arg -is [string] -and -not $name) {
$Name = $arg
}
elseif ($arg -is [string] -and -not $content) {
$content = $arg
}
}
if (-not $metadata) {
$metadata = [Ordered]@{}
}
if (-not $metadata.date) {
$metadata.date = [DateTime]::Now.ToString("yyyy-MM-dd HH:mm:ss K")
}
if (-not $metadata.title) {
$metadata.title = $Name -replace '\.+?$'
}
New-Item -Path (
$this.Directory,"_drafts",($Name | toMarkdownFileName) -join
([IO.Path]::DirectorySeparatorChar) -replace
'^\\' -replace '[\\/]', [IO.Path]::DirectorySeparatorChar
) -Force -Value $(
@(
$metadata | & $psJekyll.FormatYaml.Script -YamlHeader
$content
) -join [Environment]::NewLine
)
</SetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>File</Name>
<GetScriptBlock>
<#
.SYNOPSIS
Gets the files in a site.
.DESCRIPTION
Gets the files in a Jekyll site.
.EXAMPLE
$psJekyll.CurrentSite.File
#>
if ($this.Directory -and -not $this.'.FileList') {
$this.psobject.properties.add([psnoteproperty]::new('.FileList', @($this.Directory.EnumerateFiles("*",'AllDirectories'))))
}
return $this.'.FileList'
</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>Include</Name>
<GetScriptBlock>
<#
.SYNOPSIS
Gets the include files of a site.
.DESCRIPTION
Gets the include files in a Jekyll site.
Include files are used to include content inline in a page.
.LINK
https://jekyllrb.com/docs/includes/
#>