2020-04-04 16:01:33 -04:00
|
|
|
|
function Test-MarkdownLinks([String]$Path) {
|
|
|
|
|
$unreachable = @()
|
|
|
|
|
# Get markdown files recursively
|
2020-04-06 06:55:12 -04:00
|
|
|
|
$files = Get-ChildItem -Path $Path -Recurse -Include "*.md"
|
2020-04-04 16:01:33 -04:00
|
|
|
|
|
|
|
|
|
$files | ForEach-Object {
|
|
|
|
|
$fileName = $_.Name
|
|
|
|
|
Write-Host "Analyzing $fileName"
|
|
|
|
|
|
|
|
|
|
$urls = Select-String -Path $_ -Pattern "\[.+\]\((http.*?)\)" | ForEach-Object { $_.matches.Groups[1] } | Select-Object
|
|
|
|
|
|
|
|
|
|
$urls | ForEach-Object {
|
|
|
|
|
$url = $_.Value
|
|
|
|
|
Write-Host "Requesting url $url"
|
|
|
|
|
|
|
|
|
|
try {
|
2020-06-26 18:00:43 -04:00
|
|
|
|
$request = Invoke-WebRequest -Uri $url -DisableKeepAlive -UseBasicParsing
|
2020-04-04 16:01:33 -04:00
|
|
|
|
} catch {
|
2020-04-04 16:19:26 -04:00
|
|
|
|
Write-Warning -Message "Found dead url $url in $fileName"
|
2020-04-04 16:01:33 -04:00
|
|
|
|
$unreachable += $url
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-04 16:21:45 -04:00
|
|
|
|
|
2020-04-04 16:46:43 -04:00
|
|
|
|
# Output urls
|
|
|
|
|
return $unreachable
|
2020-04-04 16:21:45 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-06 06:55:12 -04:00
|
|
|
|
$DeadLinks = Test-MarkdownLinks -Path ".\readme.md"
|
|
|
|
|
if ($DeadLinks) {
|
|
|
|
|
Write-Host -Object '--- DEAD LINKS FOUND ---' -ForegroundColor Red
|
|
|
|
|
foreach ($DeadLink in $DeadLinks) {
|
|
|
|
|
Write-Host -Object $DeadLink -ForegroundColor Red
|
|
|
|
|
}
|
|
|
|
|
exit 1
|
2020-06-16 11:31:34 -04:00
|
|
|
|
}
|