@@ -72,6 +72,7 @@ param (
72
72
[string ] $userAgent ,
73
73
[string ] $inputCacheFile ,
74
74
[string ] $outputCacheFile ,
75
+ [string ] $localGithubClonedRoot = " " ,
75
76
[string ] $requestTimeoutSec = 15
76
77
)
77
78
@@ -80,6 +81,14 @@ Set-StrictMode -Version 3.0
80
81
$ProgressPreference = " SilentlyContinue" ; # Disable invoke-webrequest progress dialog
81
82
82
83
function ProcessLink ([System.Uri ]$linkUri ) {
84
+ # To help improve performance and rate limiting issues with github links we try to resolve them based on a local clone if one exists.
85
+ if ($localGithubClonedRoot -and $linkUri -match ' ^https://github.com/Azure/(?<repo>[^/]+)/(?:blob|tree)/(main|.*_[^/]+|.*/v[^/]+)/(?<path>.*)$' ) {
86
+ $localPath = Join-Path $localGithubClonedRoot $matches [' repo' ] $matches [' path' ]
87
+ if (Test-Path $localPath ) {
88
+ return $true
89
+ }
90
+ return ProcessStandardLink $linkUri
91
+ }
83
92
if ($linkUri -match ' ^https?://?github\.com/(?<account>)[^/]+/(?<repo>)[^/]+/wiki/.+' ) {
84
93
# in an unauthenticated session, urls for missing pages will redirect to the wiki root
85
94
return ProcessRedirectLink $linkUri - invalidStatusCodes 302
@@ -507,6 +516,7 @@ if ($inputCacheFile)
507
516
$goodLinks = $cacheContent.Split (" `n " ).Where ({ $_.Trim () -ne " " -and ! $_.StartsWith (" #" ) })
508
517
509
518
foreach ($goodLink in $goodLinks ) {
519
+ $goodLink = $goodLink.Trim ()
510
520
$checkedLinks [$goodLink ] = $true
511
521
}
512
522
}
@@ -587,7 +597,7 @@ try {
587
597
588
598
if ($outputCacheFile )
589
599
{
590
- $goodLinks = $checkedLinks.Keys.Where ({ " True" -eq $checkedLinks [$_ ].ToString() }) | Sort-Object
600
+ $goodLinks = $checkedLinks.Keys.Where ({ " True" -eq $checkedLinks [$_ ].ToString()}) | Sort-Object - Unique
591
601
592
602
Write-Host " Writing the list of validated links to $outputCacheFile "
593
603
$goodLinks | Set-Content $outputCacheFile
0 commit comments