<# .SYNOPSIS Liest spezifische Confluence-Seiten per API #> $ConfluenceUrl = "https://arija-confluence.jaas.service.deutschebahn.com" $ApiBase = "$ConfluenceUrl/rest/api" $OutputDir = "project-audit\data\confluence-ttsi" $PageIds = @( @{ id = "424295009"; name = "TAF-TAP-TSI-Programmakte" } @{ id = "428930895"; name = "TAF-TAP-TSI-Programmsteuerung" } @{ id = "490596078"; name = "TAF-TAP-TSI-Fachliche-Dokumentation" } ) [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Write-Host "============================================================" Write-Host " Confluence TTSI-Space Seiten lesen" Write-Host "============================================================" $PAT = Read-Host "Confluence PAT" $Headers = @{ "Authorization" = "Bearer $PAT" } New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null Add-Type -AssemblyName System.Web -ErrorAction SilentlyContinue function Convert-HtmlToText($html) { if ($null -eq $html) { return "" } $text = $html -replace '', "`n" $text = $text -replace ']*>', "`n" $text = $text -replace '

', "" $text = $text -replace ']*>', "`n- " $text = $text -replace ']*>', "`n## " $text = $text -replace '', "`n" $text = $text -replace ']*>', "`n| " $text = $text -replace ']*>', " | " $text = $text -replace ']*>', " | " $text = $text -replace '<[^>]+>', '' try { $text = [System.Web.HttpUtility]::HtmlDecode($text) } catch {} return $text.Trim() } foreach ($Page in $PageIds) { $PageId = $Page.id $PName = $Page.name Write-Host "" Write-Host ">> $PName (ID: $PageId)" -ForegroundColor Yellow $Uri = "$ApiBase/content/$PageId`?expand=body.storage,version,space,children.page" try { $Resp = Invoke-WebRequest -Uri $Uri -Headers $Headers -UseBasicParsing -ErrorAction Stop $Data = $Resp.Content | ConvertFrom-Json Write-Host " Titel: $($Data.title) (v$($Data.version.number))" -ForegroundColor Green # HTML speichern $HtmlContent = "" if ($Data.body -and $Data.body.storage) { $HtmlContent = $Data.body.storage.value } $HtmlContent | Out-File "$OutputDir\$PName.html" -Encoding UTF8 # Markdown speichern $TextContent = Convert-HtmlToText $HtmlContent $MdContent = "# $($Data.title)`n`n> Page ID: $PageId | Version: $($Data.version.number) | Space: $($Data.space.key)`n`n---`n`n$TextContent" $MdContent | Out-File "$OutputDir\$PName.md" -Encoding UTF8 Write-Host " Gespeichert ($($HtmlContent.Length) Zeichen)" # Kindseiten auflisten if ($Data.children -and $Data.children.page -and $Data.children.page.results) { Write-Host " Kindseiten:" -ForegroundColor DarkGray foreach ($Child in $Data.children.page.results) { Write-Host " - $($Child.title) (ID: $($Child.id))" } # Kindseiten auch lesen foreach ($Child in $Data.children.page.results) { Write-Host " >> Kindseite: $($Child.title)..." -NoNewline $ChildUri = "$ApiBase/content/$($Child.id)`?expand=body.storage,version" try { $CResp = Invoke-WebRequest -Uri $ChildUri -Headers $Headers -UseBasicParsing -ErrorAction Stop $CData = $CResp.Content | ConvertFrom-Json $CHtml = "" if ($CData.body -and $CData.body.storage) { $CHtml = $CData.body.storage.value } $CText = Convert-HtmlToText $CHtml $SafeTitle = $Child.title -replace '[\\/:*?"<>|]', '_' if ($SafeTitle.Length -gt 60) { $SafeTitle = $SafeTitle.Substring(0, 60) } $CMd = "# $($Child.title)`n`n> Page ID: $($Child.id) | Parent: $PName`n`n---`n`n$CText" $CMd | Out-File "$OutputDir\$PName`_$SafeTitle.md" -Encoding UTF8 $CHtml | Out-File "$OutputDir\$PName`_$SafeTitle.html" -Encoding UTF8 Write-Host " OK" -ForegroundColor Green } catch { Write-Host " FEHLER" -ForegroundColor Red } } } } catch { Write-Host " FEHLER: $($_.Exception.Message)" -ForegroundColor Red } } Write-Host "" Write-Host "============================================================" -ForegroundColor Green Write-Host " FERTIG! Ergebnisse in $OutputDir" -ForegroundColor Green Write-Host "============================================================" -ForegroundColor Green