[CmdletBinding()] param( [string]$Url = 'http://127.0.0.1:8000/', [switch]$Json ) $ErrorActionPreference = 'Stop' try { $page = Invoke-WebRequest -Uri $Url -UseBasicParsing } catch { Write-Error ("Page failed: {0}" -f $_.Exception.Message) exit 1 } $html = $page.Content $images = [regex]::Matches($html, ']*>', 'IgnoreCase') $missingAlt = @($images | Where-Object { $_.Value -notmatch '\balt\s*=' }).Count $emptyLinks = [regex]::Matches($html, ']*>\s*', 'IgnoreCase').Count $ids = [regex]::Matches($html, '\bid\s*=\s*["'']([^"'']+)["'']', 'IgnoreCase') | ForEach-Object { $_.Groups[1].Value } $duplicateIds = @($ids | Group-Object | Where-Object { $_.Count -gt 1 }) $missingLabel = 0 $inputs = [regex]::Matches($html, ']*>', 'IgnoreCase') foreach ($field in $inputs) { if ($field.Value -match 'type\s*=\s*["''](hidden|submit|button|reset|image)["'']') { continue } $idMatch = [regex]::Match($field.Value, 'id\s*=\s*["'']([^"'']+)["'']', 'IgnoreCase') if (-not $idMatch.Success) { $missingLabel++ continue } $escaped = [regex]::Escape($idMatch.Groups[1].Value) if ($html -notmatch ('for\s*=\s*["'']' + $escaped + '["'']')) { $missingLabel++ } } $checks = [ordered]@{ lang = [regex]::IsMatch($html, ']+lang\s*=', 'IgnoreCase') title = [regex]::IsMatch($html, '\s*\S', 'IgnoreCase') viewport = [regex]::IsMatch($html, '<meta[^>]+name=["'']viewport["'']', 'IgnoreCase') images = $images.Count missing_alt = $missingAlt inputs = $inputs.Count missing_label = $missingLabel empty_links = $emptyLinks duplicate_ids = $duplicateIds.Count } if ($Json) { $checks | ConvertTo-Json -Depth 4 } else { Write-Host ("lang: {0}" -f $checks.lang) Write-Host ("title: {0}" -f $checks.title) Write-Host ("viewport: {0}" -f $checks.viewport) Write-Host ("images: {0}, missing alt: {1}" -f $checks.images, $checks.missing_alt) Write-Host ("inputs: {0}, missing label: {1}" -f $checks.inputs, $checks.missing_label) Write-Host ("empty links: {0}" -f $checks.empty_links) Write-Host ("duplicate ids: {0}" -f $checks.duplicate_ids) foreach ($group in $duplicateIds) { Write-Host (" id={0} count={1}" -f $group.Name, $group.Count) } } if (-not $checks.lang -or -not $checks.title -or $missingAlt -gt 0) { exit 1 }