Skip to content

Commit 43c8e19

Browse files
authored
Classification Experiment (#333)
📝 (content): enhance Definition of Done documentation for clarity and depth 🔧 (footer.html): add Masonry layout script for improved UI flexibility ♻️ (list.html): refactor tag list layout for better readability and maintainability The Definition of Done documentation is expanded to provide a more comprehensive understanding of its importance, including organizational and team-specific criteria. This aims to improve transparency, consistency, and quality across teams. The footer now includes the Masonry layout script to enhance the visual presentation of content. The tag list layout is refactored to improve readability and maintainability, ensuring a more organized and user-friendly interface.
2 parents c43ea2d + f2ea296 commit 43c8e19

File tree

7 files changed

+392
-163
lines changed

7 files changed

+392
-163
lines changed

.github/workflows/main.yaml

+32-13
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ jobs:
228228
- name: Setup Hugo
229229
uses: peaceiris/actions-hugo@v3
230230
with:
231-
hugo-version: "${{ vars.HUGO_BUILD_VERSION }}"
231+
hugo-version: "${{ vars.HUGO_BUILD_VERSION }}"
232232
extended: true
233233

234234
- name: Build
@@ -296,7 +296,7 @@ jobs:
296296

297297
# Offload Images
298298
OffloadImages:
299-
name: "Ofload Site Images to Blob Storage"
299+
name: "Cleanup and Ofload to Blob Storage"
300300
runs-on: ubuntu-latest
301301
if: ${{ success() }}
302302
needs: [BuildSite, Setup]
@@ -323,6 +323,11 @@ jobs:
323323
shell: pwsh
324324
run: |
325325
. ./.powershell/_includes/ImagesToBlobStorage.ps1
326+
if ($env:ACTIONS_STEP_DEBUG -eq "true") {
327+
$levelSwitch.MinimumLevel = 'Debug'
328+
} else {
329+
$levelSwitch.MinimumLevel = 'Information'
330+
}
326331
Upload-ImageFiles -LocalPath $env:LOCAL_IMAGE_PATH -BlobUrlBase $env:BLOB_STORAGE_URL -AzureSASToken $env:AZURE_BLOB_STORAGE_SAS_TOKEN
327332
env:
328333
LOCAL_IMAGE_PATH: "./_site/"
@@ -333,26 +338,40 @@ jobs:
333338
shell: pwsh
334339
run: |
335340
. ./.powershell/_includes/ImagesToBlobStorage.ps1
341+
if ($env:ACTIONS_STEP_DEBUG -eq "true") {
342+
$levelSwitch.MinimumLevel = 'Debug'
343+
} else {
344+
$levelSwitch.MinimumLevel = 'Information'
345+
}
336346
Rewrite-ImageLinks -LocalPath $env:LOCAL_IMAGE_PATH -BlobUrl $env:BLOB_URL_BIT
337347
env:
338348
LOCAL_IMAGE_PATH: "./_site/"
339349
BLOB_URL_BIT: ${{needs.Setup.outputs.nkdAgility_BLOB_URL_BIT}}
340-
- name: "Delete Local Images"
350+
- name: "Clean Local Images"
341351
shell: pwsh
342352
run: |
343353
. ./.powershell/_includes/ImagesToBlobStorage.ps1
344-
Delete-LocalImageFiles -LocalPath $env:LOCAL_IMAGE_PATH
354+
if ($env:ACTIONS_STEP_DEBUG -eq "true") {
355+
$levelSwitch.MinimumLevel = 'Debug'
356+
} else {
357+
$levelSwitch.MinimumLevel = 'Information'
358+
}
359+
$deletedImagesCount = Delete-LocalImageFiles -LocalPath $env:LOCAL_IMAGE_PATH
360+
345361
env:
346362
LOCAL_IMAGE_PATH: "./_site/"
347-
# - name: "Build NKDAgility Outputs"
348-
# shell: pwsh
349-
# run: ./.powershell/build/Sync-BlobStorageImages.ps1
350-
# env:
351-
# LOCAL_IMAGE_PATH: "./_site/"
352-
# BLOB_URL_BIT: "/blob"
353-
# BLOB_STORAGE_URL: "https://nkdagilityblobs.blob.core.windows.net/`$web"
354-
# AZURE_BLOB_STORAGE_SAS_TOKEN: ${{ secrets.AZURE_BLOB_STORAGE_SAS_TOKEN }}
355-
# AZCOPY_FAIL_ON_ERROR: "true"
363+
- name: "Clean Local Data Files"
364+
shell: pwsh
365+
run: |
366+
. ./.powershell/_includes/CleanupDataFiles.ps1
367+
if ($env:ACTIONS_STEP_DEBUG -eq "true") {
368+
$levelSwitch.MinimumLevel = 'Debug'
369+
} else {
370+
$levelSwitch.MinimumLevel = 'Information'
371+
}
372+
$deletedCount = Delete-LocalDataFiles -LocalPath $env:LOCAL_DATA_PATH
373+
env:
374+
LOCAL_DATA_PATH: "./_site/resources/"
356375
- uses: actions/upload-artifact@v4
357376
with:
358377
name: Site-Blobbed
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Helpers
2+
. ./.powershell/_includes/LoggingHelper.ps1
3+
4+
function Delete-LocalDataFiles {
5+
param (
6+
[string]$LocalPath
7+
)
8+
$count = 0
9+
try {
10+
Write-InfoLog "Deleting all data files locally from '$LocalPath'..."
11+
$files = Get-ChildItem -Path $LocalPath -Recurse -Include data.captions.*.srt, data.captions.json, data.json, data.index.classifications.json
12+
if ($files.Count -eq 0) {
13+
Write-InfoLog "No files found."
14+
return 0;
15+
}
16+
17+
$totalFiles = $files.Count
18+
$size = ($files | Measure-Object -Property Length -Sum).Sum
19+
$sizeString = "{0:N2} MB" -f ($size / 1MB)
20+
Write-InfoLog "Found ($totalFiles) files totalling $sizeString."
21+
22+
$lastPercentage = 0 # To track when to log progress
23+
$progressInterval = 10 # Percentage interval for logging
24+
25+
$files | ForEach-Object -Begin { $index = 0 } -Process {
26+
try {
27+
Remove-Item -Path $_.FullName -Force
28+
Write-DebugLog "Deleted: $($_.FullName)"
29+
$count++
30+
$index++
31+
32+
# Calculate percentage progress
33+
$percentage = [math]::Round(($index / $totalFiles) * 100, 0)
34+
35+
# Log progress at defined intervals (e.g., every 10%)
36+
if ($percentage -ge $lastPercentage + $progressInterval) {
37+
Write-InfoLog "Progress: $percentage% ($index of $totalFiles files deleted)"
38+
$lastPercentage = $percentage
39+
}
40+
}
41+
catch {
42+
Write-ErrorLog "Error deleting file $($_.FullName): $_"
43+
}
44+
}
45+
}
46+
catch {
47+
Write-ErrorLog "Error during file deletion: $_"
48+
}
49+
Write-InfoLog "Completed: Deleted $count files."
50+
return $count;
51+
}

.powershell/_includes/ImagesToBlobStorage.ps1

+71-26
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ function Upload-ImageFiles {
1212
[string]$AzureSASToken
1313
)
1414
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..."
1616
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."
1818
}
1919
catch {
20-
Write-Debug "Error during upload: $_"
20+
Write-ErrorLog"Error during upload: $_"
2121
}
2222
}
2323

@@ -26,23 +26,52 @@ function Delete-LocalImageFiles {
2626
param (
2727
[string]$LocalPath
2828
)
29+
$count = 0
2930
try {
30-
Write-Debug "Deleting all image files locally..."
31-
Get-ChildItem -Path $LocalPath -Recurse -Include *.jpg, *.jpeg, *.png, *.gif, *.webp, *.svg | ForEach-Object {
31+
Write-InfoLog "Deleting all image files locally..."
32+
$images = Get-ChildItem -Path $LocalPath -Recurse -Include *.jpg, *.jpeg, *.png, *.gif, *.webp, *.svg
33+
if ($images.Count -eq 0) {
34+
Write-InfoLog "No image files found."
35+
return 0;
36+
}
37+
38+
$totalFiles = $images.Count
39+
$size = ($images | Measure-Object -Property Length -Sum).Sum
40+
$sizeString = "{0:N2} MB" -f ($size / 1MB)
41+
Write-InfoLog "Found ($totalFiles) image files totalling $sizeString."
42+
43+
$lastPercentage = 0 # Tracks when to log progress
44+
$progressInterval = 10 # Percentage interval for logging
45+
46+
$images | ForEach-Object -Begin { $index = 0 } -Process {
3247
try {
3348
Remove-Item -Path $_.FullName -Force
34-
Write-Debug "Deleted: $($_.FullName)"
49+
Write-DebugLog "Deleted: $($_.FullName)"
50+
$count++
51+
$index++
52+
53+
# Calculate percentage progress
54+
$percentage = [math]::Round(($index / $totalFiles) * 100, 0)
55+
56+
# Log progress at defined intervals
57+
if ($percentage -ge $lastPercentage + $progressInterval) {
58+
Write-InfoLog "Progress: $percentage% ($index of $totalFiles image files deleted)"
59+
$lastPercentage = $percentage
60+
}
3561
}
3662
catch {
37-
Write-Debug "Error deleting file $($_.FullName): $_"
63+
Write-ErrorLog "Error deleting file $($_.FullName): $_"
3864
}
3965
}
4066
}
4167
catch {
42-
Write-Debug "Error during file deletion: $_"
68+
Write-ErrorLog "Error during image file deletion: $_"
4369
}
70+
Write-InfoLog "Completed: Deleted $count image files."
71+
return $count;
4472
}
4573

74+
4675
# Method 3: Rewrite image links in .html files using regex
4776
function Rewrite-ImageLinks {
4877
param (
@@ -55,10 +84,18 @@ function Rewrite-ImageLinks {
5584
$HtmlFiles = Get-ChildItem -Path $LocalPath -Recurse -Include *.html
5685

5786
$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
5896

5997
foreach ($HtmlFile in $HtmlFiles) {
6098

61-
# $FileContent = Get-Content -Path (Resolve-Path $HtmlFile.FullName) -Raw
6299
$FileContent = Get-Content -LiteralPath $HtmlFile.FullName -Raw
63100
# Regex to match all src attributes with image paths
64101
$ImageRegex = "(?i)(src|content|href)\s*=\s*([""']?)(?<url>[^\s""'>]+\.(jpg|jpeg|png|gif|webp|svg))\2"
@@ -91,18 +128,18 @@ function Rewrite-ImageLinks {
91128
try {
92129
# Define the regex pattern
93130
$allowedPattern = '^(?:https?:\/\/)?(?:nkdagility\.com|preview\.nkdagility\.com|yellow-pond-042d21b03.*\.westeurope\.5\.azurestaticapps\.net)(\/.*)?$'
94-
if ($OriginalUrl -match $allowedPattern) {
131+
if ($OriginalPath -match $allowedPattern) {
95132
continue
96133
}
97134

98135
$pattern = '^(?:https?:\/\/)?[^\/]+(?<path>\/.*)$'
99-
if ($OriginalUrl -match $pattern) {
136+
if ($OriginalPath -match $pattern) {
100137
$path = $matches['path']
101138
$UpdatedPath = "$BlobUrl/" + $path -join '/'
102139
}
103140
}
104141
catch {
105-
Write-Debug " ERROR HTTP: $OriginalPath -> $UpdatedPath : $_"
142+
Write-DebugLog " ERROR HTTP: $OriginalPath -> $UpdatedPath : $_"
106143
}
107144
}
108145
elseif ($OriginalPath.StartsWith("/")) {
@@ -115,52 +152,60 @@ function Rewrite-ImageLinks {
115152
# Relative paths - Ensure consistency by converting to root-relative
116153
# 1. Get the parent directory of the HTML file
117154
$ParentDirectory = Split-Path -Path $HtmlFile.FullName -Parent
118-
Write-Debug "Parent Directory: $ParentDirectory"
155+
Write-DebugLog "Parent Directory: $ParentDirectory"
119156

120157
# 2. Combine the parent directory with the original path
121158
$CombinedPath = Join-Path -Path $ParentDirectory -ChildPath $OriginalPath
122-
Write-Debug "Combined Path: $CombinedPath"
159+
Write-DebugLog "Combined Path: $CombinedPath"
123160

124161
if (-not (Test-Path -Path $CombinedPath)) {
125-
Write-Debug " Path does not exist: $CombinedPath"
162+
Write-DebugLog " Path does not exist: $CombinedPath"
126163
continue;
127164
}
128165
# 3. Resolve the full path
129166
$ResolvedPath = Resolve-Path -Path $CombinedPath
130-
Write-Debug "Resolved Path: $ResolvedPath"
167+
Write-DebugLog "Resolved Path: $ResolvedPath"
131168

132169
# 4. Get the root-relative path
133170
$LocalImagesFullPath = (Get-Item $LocalPath).FullName
134-
Write-Debug "Local Images Full Path: $LocalImagesFullPath"
171+
Write-DebugLog "Local Images Full Path: $LocalImagesFullPath"
135172

136173
$RootRelativePath = $ResolvedPath.Path.Replace($LocalImagesFullPath, "").Replace("\", "/")
137-
Write-Debug "Root Relative Path: $RootRelativePath"
174+
Write-DebugLog "Root Relative Path: $RootRelativePath"
138175

139176
# 5. Construct the updated path
140177
$UpdatedPath = "$BlobUrl/$RootRelativePath"
141-
Write-Debug " Updated Path: $UpdatedPath"
178+
Write-DebugLog " Updated Path: $UpdatedPath"
142179
}
143180
catch {
144-
Write-Debug " Error resolving path: $_"
181+
Write-ErrorLog " Error resolving path: $_"
145182
continue;
146183
}
147184
}
148185

149186
# Replace the original path in the content
150187
if ($OriginalPath -ne $UpdatedPath) {
151188
$FileContent = $FileContent -replace [regex]::Escape($OriginalPath), $UpdatedPath
152-
Write-Debug " Replaced: $OriginalPath -> $UpdatedPath"
189+
Write-DebugLog " Replaced: $OriginalPath -> $UpdatedPath"
153190
$totalLinks += 1;
154191
}
155192

156193
}
157194

158195
# Save updated content back to the file
159196
Set-Content -LiteralPath $HtmlFile.FullName -Value $FileContent
160-
Write-InfoLog "Updated ($($Matches.count)): $($HtmlFile.FullName)"
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+
}
161208

162209
}
163-
Write-InfoLog "HTML link rewriting complete of $totalLinks."
164-
165-
166-
}
210+
Write-InfoLog "HTML link rewriting complete: $totalLinks links updated across $totalFiles files."
211+
}

0 commit comments

Comments
 (0)