Skip to content

Commit 586deb0

Browse files
committed
♻️ (ImagesToBlobStorage.ps1, Sync-BlobStorageImages.ps1): refactor logging and improve URL handling logic
Refactor the logging mechanism to use `Write-InfoLog` instead of `Write-Host` for better log management and consistency. Enhance the URL handling logic in `Rewrite-ImageLinks` to ensure paths are correctly updated only when they match the allowed pattern. This change improves the clarity and maintainability of the script by ensuring that only valid URLs are processed and others are logged for debugging.
1 parent 43c8e19 commit 586deb0

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

.powershell/_includes/ImagesToBlobStorage.ps1

+10-7
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,17 @@ function Rewrite-ImageLinks {
129129
# Define the regex pattern
130130
$allowedPattern = '^(?:https?:\/\/)?(?:nkdagility\.com|preview\.nkdagility\.com|yellow-pond-042d21b03.*\.westeurope\.5\.azurestaticapps\.net)(\/.*)?$'
131131
if ($OriginalPath -match $allowedPattern) {
132-
continue
132+
$pattern = '^(?:https?:\/\/)?[^\/]+(?<path>\/.*)$'
133+
if ($OriginalPath -match $pattern) {
134+
$path = $matches['path']
135+
$UpdatedPath = "$BlobUrl/" + $path -join '/'
136+
}
137+
133138
}
134-
135-
$pattern = '^(?:https?:\/\/)?[^\/]+(?<path>\/.*)$'
136-
if ($OriginalPath -match $pattern) {
137-
$path = $matches['path']
138-
$UpdatedPath = "$BlobUrl/" + $path -join '/'
139-
}
139+
else {
140+
Write-DebugLog " Skipping : $OriginalPath"
141+
}
142+
140143
}
141144
catch {
142145
Write-DebugLog " ERROR HTTP: $OriginalPath -> $UpdatedPath : $_"

.powershell/dev/Sync-BlobStorageImages.ps1

+12-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@
22

33
. ./.powershell/_includes/ImagesToBlobStorage.ps1
44

5-
Write-Host "Starting process..."
5+
#Write-InfoLog "Remove existing public content..."
6+
#Remove-Item -Path .\public\* -Recurse -Force
7+
Write-InfoLog "Build new public content.."
8+
#hugo --source site --config "hugo.yaml, hugo.local.yaml"
9+
Write-InfoLog "Starting process..."
10+
11+
612

713
# Variables
814
if (-not $env:LOCAL_IMAGE_PATH) {
915
$env:LOCAL_IMAGE_PATH = ".\public\resources\blog\announcing-evidence-based-management-training-with-certification-from-scrum-org\" # Local folder containing images and HTML files
1016

1117
}
12-
Write-Host "Local Image Path: $env:LOCAL_IMAGE_PATH"
18+
Write-InfoLog "Local Image Path: $env:LOCAL_IMAGE_PATH"
19+
1320
if (-not $env:BLOB_URL_BIT) {
1421
$env:BLOB_URL_BIT = "https://nkdagilityblobs.blob.core.windows.net/`$web" #"/blob" # URL to be used for rewriting - can be full URL or "blob" for relative paths
1522
}
16-
Write-Host "Blob URL Bit: $env:BLOB_URL_BIT"
23+
Write-InfoLog "Blob URL Bit: $env:BLOB_URL_BIT"
24+
1725
if (-not $env:BLOB_STORAGE_URL) {
1826
$env:BLOB_STORAGE_URL = "https://nkdagilityblobs.blob.core.windows.net/`$web" # Base URL for Blob storage
1927
}
@@ -30,4 +38,4 @@ Rewrite-ImageLinks -LocalPath $env:LOCAL_IMAGE_PATH -BlobUrl $env:BLOB_URL_BIT
3038

3139
#Delete-LocalImageFiles -LocalPath $env:LOCAL_IMAGE_PATH
3240

33-
Write-Host "Process complete!"
41+
Write-InfoLog "Process complete!"

0 commit comments

Comments
 (0)