[Console]::OutputEncoding = [System.Text.Encoding]::UTF8 $wikiPath = 'D:\Applications\app\kepano-obsidian-main\wiki' $vaultPath = 'D:\Applications\app\kepano-obsidian-main' $wikiFiles = Get-ChildItem -Path $wikiPath -Filter '*.md' -File $pageNames = $wikiFiles | ForEach-Object { $_.BaseName } $allMd = Get-ChildItem -Path $vaultPath -Filter '*.md' -File -Recurse | Where-Object { $_.Length -lt 500KB } $allContent = @{} foreach ($f in $allMd) { try { $allContent[$f.FullName] = [System.IO.File]::ReadAllText($f.FullName) } catch {} } $orphans = @() foreach ($pn in $pageNames) { if ($pn -eq 'index' -or $pn -eq 'log') { continue } $linkPattern = '[[' + $pn + ']' $hasInbound = $false foreach ($fp in $allContent.Keys) { $baseF = [System.IO.Path]::GetFileNameWithoutExtension($fp) if ($baseF -eq $pn) { continue } if ($allContent[$fp] -match [regex]::Escape($linkPattern)) { $hasInbound = $true break } } if (-not $hasInbound) { $orphans += $pn } } Write-Output "ORPHAN_COUNT: $($orphans.Count)" $orphans | ForEach-Object { Write-Output $_ }