@@ -12,12 +12,12 @@ function Upload-ImageFiles {
12
12
[string ]$AzureSASToken
13
13
)
14
14
try {
15
- Write-Debug " Uploading image files to Azure Blob Storage using azcopy..."
15
+ Write-InfoLog " Uploading image files to Azure Blob Storage using azcopy..."
16
16
azcopy sync $LocalPath " $BlobUrlBase `?$AzureSASToken " -- recursive= true -- include- pattern " *.jpg;*.jpeg;*.png;*.gif;*.webp;*.svg" -- compare-hash = MD5
17
- Write-Debug " Upload complete."
17
+ Write-InfoLog " Upload complete."
18
18
}
19
19
catch {
20
- Write-Debug " Error during upload: $_ "
20
+ Write-ErrorLog " Error during upload: $_ "
21
21
}
22
22
}
23
23
@@ -84,10 +84,18 @@ function Rewrite-ImageLinks {
84
84
$HtmlFiles = Get-ChildItem - Path $LocalPath - Recurse - Include * .html
85
85
86
86
$totalLinks = 0 ;
87
+ $totalFiles = $HtmlFiles.Count
88
+
89
+ if ($totalFiles -eq 0 ) {
90
+ Write-InfoLog " No .html files found for processing."
91
+ return
92
+ }
93
+
94
+ $lastPercentage = 0 # Tracks when to log progress
95
+ $progressInterval = 10 # Percentage interval for logging
87
96
88
97
foreach ($HtmlFile in $HtmlFiles ) {
89
98
90
- # $FileContent = Get-Content -Path (Resolve-Path $HtmlFile.FullName) -Raw
91
99
$FileContent = Get-Content - LiteralPath $HtmlFile.FullName - Raw
92
100
# Regex to match all src attributes with image paths
93
101
$ImageRegex = " (?i)(src|content|href)\s*=\s*(["" ']?)(?<url>[^\s"" '>]+\.(jpg|jpeg|png|gif|webp|svg))\2"
@@ -120,18 +128,18 @@ function Rewrite-ImageLinks {
120
128
try {
121
129
# Define the regex pattern
122
130
$allowedPattern = ' ^(?:https?:\/\/)?(?:nkdagility\.com|preview\.nkdagility\.com|yellow-pond-042d21b03.*\.westeurope\.5\.azurestaticapps\.net)(\/.*)?$'
123
- if ($OriginalUrl -match $allowedPattern ) {
131
+ if ($OriginalPath -match $allowedPattern ) {
124
132
continue
125
133
}
126
134
127
135
$pattern = ' ^(?:https?:\/\/)?[^\/]+(?<path>\/.*)$'
128
- if ($OriginalUrl -match $pattern ) {
136
+ if ($OriginalPath -match $pattern ) {
129
137
$path = $matches [' path' ]
130
138
$UpdatedPath = " $BlobUrl /" + $path -join ' /'
131
139
}
132
140
}
133
141
catch {
134
- Write-Debug " ERROR HTTP: $OriginalPath -> $UpdatedPath : $_ "
142
+ Write-DebugLog " ERROR HTTP: $OriginalPath -> $UpdatedPath : $_ "
135
143
}
136
144
}
137
145
elseif ($OriginalPath.StartsWith (" /" )) {
@@ -151,7 +159,7 @@ function Rewrite-ImageLinks {
151
159
Write-DebugLog " Combined Path: $CombinedPath "
152
160
153
161
if (-not (Test-Path - Path $CombinedPath )) {
154
- Write-Debug " Path does not exist: $CombinedPath "
162
+ Write-DebugLog " Path does not exist: $CombinedPath "
155
163
continue ;
156
164
}
157
165
# 3. Resolve the full path
@@ -187,9 +195,17 @@ function Rewrite-ImageLinks {
187
195
# Save updated content back to the file
188
196
Set-Content - LiteralPath $HtmlFile.FullName - Value $FileContent
189
197
Write-DebugLog " Updated ($ ( $Matches.count ) ): $ ( $HtmlFile.FullName ) "
198
+
199
+ # **Progress tracking**
200
+ $index ++
201
+ $percentage = [math ]::Round(($index / $totalFiles ) * 100 , 0 )
202
+
203
+ # Log progress every 10%
204
+ if ($percentage -ge $lastPercentage + $progressInterval ) {
205
+ Write-InfoLog " Progress: $percentage % ($index of $totalFiles HTML files processed with $totalLinks links updated)"
206
+ $lastPercentage = $percentage
207
+ }
190
208
191
209
}
192
- Write-InfoLog " HTML link rewriting complete of $totalLinks ."
193
-
194
-
195
- }
210
+ Write-InfoLog " HTML link rewriting complete: $totalLinks links updated across $totalFiles files."
211
+ }
0 commit comments