# .SYNOPSIS Push local markdown files from /pages/ folder as Confluence pages .DESCRIPTION Reads all .md files from the /pages/ directory, converts them to HTML, and creates/updates them as child pages under the configured root page. .USAGE powershell -ExecutionPolicy Bypass -File scripts/confluence-push.ps1 #> . "$PSScriptRoot/../config.ps1" . "$PSScriptRoot/lib/confluence-api.ps1" Write-Host "============================================================" Write-Host " Confluence Push - $SpaceKey" Write-Host "============================================================" Write-Host " Target: $ConfluenceUrl/spaces/$SpaceKey" Write-Host " Parent: $RootPageId" Write-Host "" # Test connection Write-Host ">> Testing connection..." -ForegroundColor Yellow $Test = Invoke-ConfluenceApi -Endpoint "/content/$RootPageId" if (-not $Test) { Write-Host " Connection failed!" -ForegroundColor Red; exit 1 } Write-Host " Target page: $($Test.title)" -ForegroundColor Green # Find markdown files to push $PagesPath = Join-Path $ProjectDir "pages" if (-not (Test-Path $PagesPath)) { Write-Host " No /pages/ directory found. Create it and add .md files." -ForegroundColor Yellow exit 0 } $MdFiles = Get-ChildItem -Path $PagesPath -Filter "*.md" | Sort-Object Name if ($MdFiles.Count -eq 0) { Write-Host " No .md files found in /pages/" -ForegroundColor Yellow exit 0 } Write-Host "" Write-Host ">> Pushing $($MdFiles.Count) pages..." -ForegroundColor Yellow function Convert-MdToHtml($mdContent) { # Simple markdown to Confluence storage format conversion $html = $mdContent # Headers $html = $html -replace '^#### (.+)$', '
$1'
# Paragraphs (lines not already tagged)
$lines = $html -split "`n"
$result = @()
foreach ($line in $lines) {
if ($line -match '^<' -or $line.Trim() -eq '') {
$result += $line
} else {
$result += "$line
" } } return $result -join "`n" } foreach ($File in $MdFiles) { $Content = Get-Content $File.FullName -Raw -Encoding UTF8 # Use filename (without .md) as page title, or first # heading $Title = $File.BaseName if ($Content -match '^# (.+)$') { $Title = $Matches[1] } Write-Host " $Title..." -NoNewline $HtmlBody = Convert-MdToHtml $Content $PageId = Create-Or-Update-Page -Title $Title -HtmlBody $HtmlBody -ParentId $RootPageId if ($PageId) { Write-Host "" } } Write-Host "" Write-Host "============================================================" -ForegroundColor Green Write-Host " Done! $($MdFiles.Count) pages processed." -ForegroundColor Green Write-Host "============================================================" -ForegroundColor Green