-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollate.ps1
1581 lines (1336 loc) · 43.3 KB
/
collate.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
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
# =======================================================================
# Add-PropertyValue
# -----------------------------------------------------------------------
# This function adds a value to a property of a page object. If the
# property does not exist, it is created with the specified value. If
# the property already exists, the value is appended to the property
# as an array.
# =======================================================================
function Add-PropertyValue {
param(
[hashtable]$page,
[string]$property,
$value
)
if (-not $page.ContainsKey($property)) {
#
# The property is not defined yet. Add the value.
#
$page[$property] = $value
} else {
#
# The property is already defined. Append to an array.
#
if ($page[$property] -isnot [array]) {
$page[$property] = @($page[$property])
}
$page[$property] += $value
}
}
# =======================================================================
# Debug-Path
# -----------------------------------------------------------------------
# Writes a warning about the file located at a specified path, and keeps
# track of the total number of warnings found. The path is written to
# the console window as a clickable link (press ctl-click to open).
# =======================================================================
#
# Track the total number of warnings or issues found.
#
$script:foundProblems = 0
function Debug-Path() {
param(
[string]$path,
[string]$message
)
$script:foundProblems++
Write-Warning "$(Get-EmojiWarning) $message"
if ($null -ne $path) {
#
# Tip: in VSCode, you can ctrl+click the path to open the file.
#
Write-Host $path
Write-Host
}
}
# =======================================================================
# Debug-Page
# -----------------------------------------------------------------------
# Shortcut to calling Debug-Path with a page instead of a string path.
# =======================================================================
function Debug-Page {
param(
[hashtable]$page,
[string]$message
)
Debug-Path $page["::path"] $message
}
# ========================================================================
# Get-Emoji characters
# ------------------------------------------------------------------------
# These functions return a string containing a single emoji character.
# ========================================================================
function Get-EmojiBookmark() {
return [System.Char]::ConvertFromUtf32(0x1F516)
}
function Get-EmojiCalendar() {
return [System.Char]::ConvertFromUtf32(0x1F4C5)
}
function Get-EmojiCheckbox() {
return [System.Char]::ConvertFromUtf32(0x2611)
}
function Get-EmojiGlobe() {
return [System.Char]::ConvertFromUtf32(0x1F30E)
}
function Get-EmojiLeftRightArrow() {
return [System.Char]::ConvertFromUtf32(0x2194) + `
[System.Char]::ConvertFromUtf32(0xFE0F)
}
function Get-EmojiLink() {
return [System.Char]::ConvertFromUtf32(0x1F517)
}
function Get-EmojiRepeat() {
return [System.Char]::ConvertFromUtf32(0x1F501)
}
function Get-EmojiRunning() {
return [System.Char]::ConvertFromUtf32(0x1F3C3)
}
function Get-EmojiOpenFolder() {
return [System.Char]::ConvertFromUtf32(0x1F4C2)
}
function Get-EmojiQuestionMark() {
return [System.Char]::ConvertFromUtf32(0x2753)
}
function Get-EmojiTag() {
return [System.Char]::ConvertFromUtf32(0x1F3F7)
}
function Get-EmojiWarning() {
return [System.Char]::ConvertFromUtf32(0x26A0) + `
[System.Char]::ConvertFromUtf32(0xFE0F)
}
# ========================================================================
# Get-FrontMatter
# ------------------------------------------------------------------------
# Gets a hashtable of the front matter for the specified file.
# ========================================================================
function Get-FrontMatter($file) {
#
# Get the relative path of the file for output
#
$path = $file.FullName -replace [regex]::Escape($PSScriptRoot + "\"), ''
#
# Check for a common error of a directory with a .md extension
#
if ($file.Attributes -band [System.IO.FileAttributes]::Directory) {
Debug-Path $path "Directory has .md extension (probably a copy-paste error)"
return $null
}
#
# Skip files called README.md
#
if ($file.Name -eq "README.md") {
return $null
}
#
# Get the contents of the file as a string array
#
$content = Get-Content -Path $file.FullName
#
# Make sure the file isn't empty
#
if ($null -eq $content) {
Debug-Path $path "No content loaded"
return $null
}
#
# Make sure the first line is the start of YAML front matter (---)
#
if ($content[0] -ne "---") {
Debug-Path $path "First line must be --- to start YAML front matter"
return $null
}
#
# Get the array index of the second "---" in the lines of the file
#
$endOfYaml = -1
for ($i = 1; $i -lt $content.Length; $i++) {
if ($content[$i] -eq "---") {
$endOfYaml = $i
break
}
}
if ($endOfYaml -eq -1) {
Debug-Path $path "No end of YAML front matter"
return $null
}
#
# Make sure the first property is the title
#
if ($content[1] -notmatch "^title: ") {
Debug-Path $path "Title should be first in front matter by convention"
}
#
# Parse the YAML front matter
#
try {
$yaml = $content[1..($endOfYaml - 1)] | ConvertFrom-Yaml
}
catch {
Debug-Path $path "Error parsing YAML front matter"
return $null
}
#
# Skip files where draft is true
#
if ($yaml["draft"] -eq $true) {
return $null
}
#
# Save the path for later reference. By convention, properties
# defined by the script use a "::" prefix to avoid conflicts
# with user properties.
#
$yaml."::path" = $path
#
# Add another help property with the path relative to the content folder.
#
if ($path -like "content\*") {
$yaml."::content" = $path.Substring(8) -replace '\\', '/'
}
return $yaml
}
# ========================================================================
# Get-Lookup
# ------------------------------------------------------------------------
# Generates a hashtable that maps titles to page indexes. It accepts
# an array or arraylist and returns a case-sensitive hashtable where the
# key is a page title, and the value is the integer page index.
# ========================================================================
function Get-Lookup($pages) {
$hash = [hashtable]::new()
$index = -1;
foreach($page in $pages) {
#
# Track the 0-based index of this item
#
$index++;
if ($null -eq $page.title) {
Debug-Page $page "missing title"
}
else {
#
# Set the index of the title
#
$hash[$page.title] = $index
#
# Set the index of the lowercase variation of the title
#
$lowercaseTitle = $page.title.ToLower()
if ($lowercaseTitle -cne $page.title) {
$hash[$lowercaseTitle] = $index
}
}
}
return $hash
}
# ========================================================================
# Get-Pages
# ------------------------------------------------------------------------
# Loads the page objects of the specified file system objects. Each
# page object is a hashtable containing the front matter properties. The
# return value is an array of hashtables.
# ========================================================================
function Get-Pages {
$count = 0
$lastProgress = -1
$list = New-Object -TypeName System.Collections.ArrayList
$mdFiles = Get-ChildItem -Path $PSScriptRoot -Filter "*.md" -Recurse
foreach ($mdFile in $mdFiles) {
$count++
#
# Calculate the progress (percent done) of the files
#
$progress = [math]::Round(($count / $mdFiles.Count) * 100)
if ($progress -ne $lastProgress) {
$lastProgress = $progress
Write-Progress -Activity "Loading" -Status $mdFile -PercentComplete $progress
}
$fm = Get-FrontMatter $mdFile
if ($null -ne $fm) {
#$fm.GetType()
$idx=$list.Add($fm)
}
}
Write-Progress -Activity "Loading" -Completed
return $list.ToArray()
}
# ========================================================================
# Get-Props
# ------------------------------------------------------------------------
# This function generates a hashtable of properties. The input is an
# array of page objects. The output is a hashtable where the key is the
# property name and the value is a hashtable of distinct values for that
# property. The inner hashtable has the distinct value as the key and an
# array of page titles as the value.
# ========================================================================
function Get-Props($pages) {
$props = [hashtable]::new()
foreach($page in $pages) {
foreach($key in $page.Keys) {
#
# Create the hashtable for this key.
#
if (-not $props.ContainsKey($key)) {
$props[$key] = [hashtable]::new()
}
#
# Get the key value as an array
#
$value = $page[$key]
if ($value -isnot [array]) {
$value = @($value)
}
foreach($v in $value) {
if ($null -eq $v) {
Debug-Page $page "Property '$key' has a null value"
continue
}
if ($v -isnot [string]) {
$v = [string]$v
continue
}
Add-PropertyValue $props[$key] $v $page["title"]
}
}
}
return $props
}
# ========================================================================
# Install powershell-yaml module
# ========================================================================
if (-not (Get-Module -Name powershell-yaml -ListAvailable)) {
Write-Host `
"This script requires the powershell-yaml module." `
-ForegroundColor White `
-BackgroundColor Red
"You can install the module with the following command:"
"Install-Module -Name powershell-yaml -Scope CurrentUser"
"For more info, see https://github.com/cloudbase/powershell-yaml"
# Note: this PowerShell script does not automatically execute
# the installation command as it requires user interaction and
# you may prefer different options than specified.
#
# When installing for the first time, you may get an error message
# that the NuGet provider is required to continue. If so, you can
# install immediately, or exit and install it separately. You
# may also get a warning that the repository is untrusted. As
# long as the repository is PSGallery, you can trust it.
exit
}
# ========================================================================
# Load *.md files
# ========================================================================
#
# Get the front matter for all .md files in all subdirectories
#
Write-Host "$(Get-EmojiOpenFolder) Loading..."
$rootPath = $PSScriptRoot
$script:pages = Get-Pages
#
# Build a hashtable for looking up pages by title or website url
#
Write-Host "$(Get-EmojiRunning) Indexing titles..."
$script:lookup = Get-Lookup $script:pages
#
# Build an index of properties for quick reverse searches
#
Write-Host "Indexing properties..."
$script:props = Get-Props $script:pages
Write-Host "There are $($script:props.Count) distinct properties."
# ========================================================================
# Updaters
# ------------------------------------------------------------------------
# An updater is a function that modifies a page object in some way.
# ========================================================================
function Update-OfProperties($page, $suffix = "of") {
#
# Loop through each property of the page and look for ones that end in ' of'
#
foreach($propkey in $page.Keys) {
if ($propkey -notlike "* $suffix") {
continue
}
#
# Get the property value as an array
#
$proparray = $page[$propkey]
if ($proparray -isnot [array]) {
$proparray = @($proparray)
}
foreach($propvalue in $proparray) {
if ($null -eq $propvalue) {
Debug-Page $page "Property '$propkey' has a null value"
continue
}
#
# Get the index of the page referenced by this value.
#
$propindex = $script:lookup[$propvalue]
#
# If the index is valid...
#
if ($null -ne $propindex) {
#
# Get the page at the index
#
$ofPage = $script:pages[$propindex]
if($ofPage -eq $page) {
Debug-Page $page "Property '$propkey' references itself"
continue
}
#
# Build the name of the property that will be
# added to the referenced page. To do this, trim
# off the suffix and extra space, e.g., " of".
#
$propertyName = $propkey.Substring( `
0, `
$propkey.Length - $suffix.Length - 1)
Add-PropertyValue $ofPage $propertyName $page.title
}
else {
#
# The index does not exist. This is OK if the
# value is a hyperlink. Otherwise issue a warning.
#
if ($propvalue -notmatch "^https?://") {
Debug-Page `
$page `
"Property '$propkey' references non-existent title '$propvalue'"
}
}
}
}
}
function Update-Ofs($suffix = "of") {
Write-Host "$(Get-EmojiRepeat) Of..."
foreach($page in $script:pages) {
Update-OfProperties $page $suffix
}
}
# ========================================================================
# Update-OnThisDay
# ------------------------------------------------------------------------
# This function adds an "on this day" property to each page that has a
# "when" property. The "on this day" property is an array of titles that
# have the same "when" value as the current page. The property is not
# added if it is the ony page with the same "when" value.
# ========================================================================
function Update-OnThisDay($page) {
# TODO: optimize by caching the when values during load
$when = $page["when"]
if ($null -eq $when) {
return
}
# fine all pages that have the same when value
$sameWhen = @()
foreach($other in $script:pages) {
if ($page -eq $other) {
#
# skip this page
#
continue
}
if ($other["when"] -eq $when) {
$sameWhen += $other["title"]
}
}
# only if $sameWhen is not empty
if ($sameWhen.Count -gt 0) {
$page["on this day"] = $sameWhen
}
}
function Update-OnTheseDays() {
Write-Host "$(Get-EmojiCalendar) On these days..."
foreach($page in $script:pages) {
Update-OnThisDay $page
}
}
# ========================================================================
# Update-Plural
# ========================================================================
function Update-Plural($page) {
#
# Get a copy of the keys as an array that will
# not change if the hashtable itself is changed.
# The Keys property is an ICollection that changes
# as the hashtable is modified. Therefore the keys
# cannot be modified during enumeration.
$keys = [string[]]::new($page.Keys.Count)
$page.Keys.CopyTo($keys, 0)
#
# Loop through each property of the page
#
foreach($propkey in $keys) {
#
# Get the index of the page that defines this property
#
$propindex = $script:lookup[$propkey]
if ($null -eq $propindex) {
continue
}
#
# Get the page for this property and skip if it doesn't exist.
#
$proppage = $script:pages[$propindex]
if ($null -eq $proppage) {
continue
}
#
# Check for a plural string of the property
#
$plural = $proppage["plural"]
if ($null -eq $plural) {
continue
}
#
# Only string-type values are supported
#
if ($plural -isnot [string]) {
Debug-Page $proppage "plural property must be a string"
continue
}
#
# Check whether the plural references itself
#
if ($plural -eq $propkey) {
Debug-Page $proppage "plural property should not reference itself"
continue
}
#
# Get the plural property
#
$pluralprop = $page[$plural]
if ($null -eq $pluralprop) {
# The plural property does not exist. If the
# singular property ($propkey) is an array of
# length 2 or more, then the singular property
# should be renamed to the plural property.
if ($page[$propkey] -is [array] -and $page[$propkey].Length -ge 2) {
$page[$plural] = $page[$propkey]
# Remove the singular property.
$page.Remove($propkey)
}
continue
}
else {
#
# Ensure the plural property is an array.
#
if ($pluralprop -isnot [array]) {
$pluralprop = @($pluralprop)
}
#
# Get the "singular" value as an array
#
$propvalue = $page[$propkey]
if ($propvalue -isnot [array]) {
$propvalue = @($propvalue)
}
#
# Add the singular values to the plural property
#
foreach($value in $propvalue) {
$pluralprop += $value
}
#
# Save the plural array and remove the singular property
#
$page[$plural] = $pluralprop
$page.Remove($propkey)
}
}
}
function Update-Plurals() {
$s = [System.Char]::ConvertFromUtf32(0x32) + `
[System.Char]::ConvertFromUtf32(0xFE0F) + `
[System.Char]::ConvertFromUtf32(0x20E3)
Write-Host "$s Plurals..."
foreach($page in $script:pages) {
Update-Plural $page
}
}
# ========================================================================
# Update-Random
# ------------------------------------------------------------------------
# This function adds a "random" property to each page. The property
# contains the title of a random page. Pages with the "isolated page" tag
# are considered sensitive and will not be selected randomly. If a page
# already has a "random" property, it is not changed.
# ========================================================================
function Update-Random($page) {
#
# Skip pages that already have an explicit random link.
#
if ($null -ne $page["random"]) {
return
}
#
# Skip isolated pages
#
do {
$index = Get-Random -Minimum 0 -Maximum $script:pages.Length
$randomPage = $script:pages[$index]
$isolated = $randomPage["tags"] -contains "isolated page"
} while ($isolated)
$page["random"] = $randomPage["title"]
}
function Update-Randoms() {
Write-Host "$(Get-EmojiQuestionMark) Randomize..."
foreach($page in $script:pages) {
Update-Random $page
}
}
# ========================================================================
# Update-ReverseTag
# ------------------------------------------------------------------------
# Adds a "tagged" property containing an array of titles that reference
# the current page.
# ========================================================================
function Update-ReverseTag($page) {
#
# Get the hashtable for tags
#
$tags = $script:props["tags"]
if ($null -eq $tags) {
Debug-Page $page "No tags property"
exit
return
}
#
# Get the titles of all pages that tag this page
#
$tagged = $tags[$page.title]
if ($null -eq $tagged) {
return
}
else {
$page["tagged"] = $tagged
}
}
function Update-ReverseTags() {
Write-Host "$(Get-EmojiBookmark) Reverse tags..."
foreach($page in $script:pages) {
Update-ReverseTag $page
}
}
# ========================================================================
# Update-Sequences
# ========================================================================
function Update-Sequence($page) {
#
# Get the sequence property
#
$sequence = $page["sequence"]
if ($null -eq $sequence) {
return $false
}
#
# Cast the sequence to an array
#
if ($sequence -isnot [array]) {
$sequence = @($sequence)
}
#
# Loop through each element of the sequence except for the last element.
#
for ($i = 0; $i -lt $sequence.Length - 1; $i++) {
$currentElement = $sequence[$i]
$nextElement = $sequence[$i + 1]
#
# Get the page index of the current element
#
$currentIndex = $script:lookup[$currentElement]
if ($null -eq $currentIndex) {
Debug-Page $page "Sequence references non-existent title '$currentElement'"
continue
}
#
# Get the page for the current element
#
$currentPage = $script:pages[$currentIndex]
#
# Add a property with the current page title and set it to the value of the next element
#
$currentPage[$page["title"]] = $nextElement
}
return $true
}
function Update-Sequences() {
Write-Host "$(Get-EmojiLeftRightArrow) Sequences..."
$count = 0
foreach($page in $script:pages) {
if(Update-Sequence $page) {
$count++
}
}
Write-Host "Updated $count sequences"
}
# ========================================================================
# Update-Timeline
# ------------------------------------------------------------------------
# This function updates the timeline property of a page to ensure that
# the pages are ordered by the "when" property. The timeline property
# is an array of titles of pages that are related in time. The function
# will sort the pages by the "when" property and link them together
# with the ➡️ and ⬅️ properties.
# ========================================================================
function Update-Timeline($page) {
#
# If the page has a timeline property...
#
$timeline = $page["timeline"]
if ($null -eq $timeline) {
return
}
if ($timeline -isnot [array]) {
return
}
#
# Loop through the $timeline array and find the page
# for each title (the array contains titles of pages).
# Collect these into a list.
#
$timelinePages = @()
foreach($title in $timeline) {
if ($null -eq $title) {
Debug-Page $page "timeline array item is null"
return
}
$timelineIndex = $script:lookup[$title]
if ($null -eq $timelineIndex) {
Debug-Page $page "Timeline references non-existent '$title'"
return
}
$timelinePage = $script:pages[$timelineIndex]
if ($null -eq $timelinePage["when"]) {
Debug-Page $page "Timeline item '$title' has no 'when' property"
return
}
$timelinePages += $timelinePage
}
#
# Sort the objects by the "when" property
#
$sortedPages = $timelinePages | Sort-Object { $_."when" }
#
# Link next/previous pages together
#
for ($i = 0; $i -lt $sortedPages.Count; $i++) {
$p = $sortedPages[$i]
if ($i -lt $sortedPages.Count - 1) {
$p["➡️"] = $sortedPages[$i+1].title
}
if ($i -gt 0) {
$p["⬅️"] = $sortedPages[$i-1].title
}
}
#
# Convert to an array of titles
#
$timeline = @()
foreach($timelinePage in $sortedPages) {
$timeline += $timelinePage.title
}
$page["timeline"] = $timeline
}
function Update-Timelines() {
Write-Host "$(Get-EmojiLink) Timelines..."
foreach($page in $script:pages) {
Update-Timeline $page
}
}
# ========================================================================
# Update-WikipediaCrossReferences
# ========================================================================
function Update-WikipediaCrossReferencesFor($page) {
$fn = "Update-WikipediaCrossReferencesFor"
if ($page["debug"]) {
Write-Host "$fn\: $($page["title"])"
}
#
# Get the wikipedia property
#
$wikipedia = $page["wikipedia"]
if ($null -eq $wikipedia) {
if ($page["debug"]) {
Write-Host "$fn\: skipped because 'wikipedia' is null"
}
return
}
#
# Get the index of the wikipedia page
#
$wikipediaIndex = $script:lookup[$wikipedia]
if ($null -eq $wikipediaIndex) {
if ($wikipedia -notlike "https?*") {
Debug-Page $page "wikipedia property is not a page title or website url"
}
return
}
#
# Get the wikipedia page
#
$wikipediaPage = $script:pages[$wikipediaIndex]
if ($null -eq $wikipediaPage) {
Debug-Page $page "wikipedia property has no lookup index"
return
}
if ($wikipediaPage -is [array]) {
Debug-Page $page "wikipedia property is an array"
return
}
#
# Loop through each property of the page
#
foreach($propKey in $page.Keys) {
#
# Skip special properties
#
if ($propKey -eq "title" -or
$propKey -eq "random" -or
$propKey -eq "retrieved" -or
$propKey -eq "tag requires property" -or
$propKey -eq "type" -or
$propKey -eq "url" -or
$propKey -eq "wikipedia" -or
$propKey -eq "::path" -or
$propKey -eq "::content" ) {
continue
}
#
# Cast the prop value to an array
#
$propValues = $page[$propKey]
if ($propValues -isnot [array]) {
$propValues = @($propValues)
}
#
# Loop through each property value
#
foreach($propValue in $propValues) {
#
# If not a string, continue.
#
if ($propValue -isnot [string]) {
continue
}
#
# Get the index of the page for this property value
#
$propIndex = $script:lookup[$propValue]
if ($null -eq $propIndex) {
continue
}
#
# Get the page for this property value
#