@@ -72,6 +72,7 @@ param (
7272 [string ] $userAgent ,
7373 [string ] $inputCacheFile ,
7474 [string ] $outputCacheFile ,
75+ [string ] $localGithubClonedRoot = " " ,
7576 [string ] $requestTimeoutSec = 15
7677)
7778
@@ -80,6 +81,14 @@ Set-StrictMode -Version 3.0
8081$ProgressPreference = " SilentlyContinue" ; # Disable invoke-webrequest progress dialog
8182
8283function 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+ }
8392 if ($linkUri -match ' ^https?://?github\.com/(?<account>)[^/]+/(?<repo>)[^/]+/wiki/.+' ) {
8493 # in an unauthenticated session, urls for missing pages will redirect to the wiki root
8594 return ProcessRedirectLink $linkUri - invalidStatusCodes 302
@@ -507,6 +516,7 @@ if ($inputCacheFile)
507516 $goodLinks = $cacheContent.Split (" `n " ).Where ({ $_.Trim () -ne " " -and ! $_.StartsWith (" #" ) })
508517
509518 foreach ($goodLink in $goodLinks ) {
519+ $goodLink = $goodLink.Trim ()
510520 $checkedLinks [$goodLink ] = $true
511521 }
512522}
@@ -587,7 +597,7 @@ try {
587597
588598 if ($outputCacheFile )
589599 {
590- $goodLinks = $checkedLinks.Keys.Where ({ " True" -eq $checkedLinks [$_ ].ToString() }) | Sort-Object
600+ $goodLinks = $checkedLinks.Keys.Where ({ " True" -eq $checkedLinks [$_ ].ToString()}) | Sort-Object - Unique
591601
592602 Write-Host " Writing the list of validated links to $outputCacheFile "
593603 $goodLinks | Set-Content $outputCacheFile
0 commit comments