Initial commit

This commit is contained in:
2026-11-18 11:34:55 +08:00
commit d76faefdec
39 changed files with 778 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
@echo off
rem ============================================================
rem Update photos in script.js
rem Scans assets/img for images and rewrites the photos array
rem between /* PHOTOS:START */ and /* PHOTOS:END */ markers.
rem ============================================================
setlocal
cd /d "%~dp0"
if not exist "assets\img" (
echo [ERROR] assets\img folder not found.
pause
exit /b 1
)
if not exist "script.js" (
echo [ERROR] script.js not found.
pause
exit /b 1
)
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$ErrorActionPreference='Stop';" ^
"$exts='.jpg','.jpeg','.png','.gif','.webp','.bmp','.avif';" ^
"$files=@(Get-ChildItem -LiteralPath 'assets/img' -File | Where-Object { $exts -contains $_.Extension.ToLower() } | Sort-Object Name);" ^
"if ($files.Count -eq 0) { Write-Host '[ERROR] No images found in assets/img'; exit 1 };" ^
"$q=[char]34;" ^
"$entries=@($files | ForEach-Object { ' { src: ' + $q + 'assets/img/' + $_.Name + $q + ' }' });" ^
"$nl=[Environment]::NewLine;" ^
"$block='/* PHOTOS:START */' + $nl + ' const photos = [' + $nl + ($entries -join (',' + $nl)) + $nl + ' ];' + $nl + ' /* PHOTOS:END */';" ^
"$content=Get-Content -LiteralPath 'script.js' -Raw -Encoding UTF8;" ^
"if ($content -notmatch 'PHOTOS:START') { Write-Host '[ERROR] PHOTOS markers not found in script.js'; exit 1 };" ^
"$pattern='(?s)/\* PHOTOS:START \*/.*?/\* PHOTOS:END \*/';" ^
"$new=[regex]::Replace($content, $pattern, $block.Replace('$','$$'));" ^
"[System.IO.File]::WriteAllText((Resolve-Path 'script.js').Path, $new, (New-Object System.Text.UTF8Encoding($false)));" ^
"Write-Host ('[OK] ' + $files.Count + ' image(s) written to script.js:');" ^
"$files | ForEach-Object { Write-Host (' - ' + $_.Name) }"
if errorlevel 1 (
echo.
echo Update failed.
pause
exit /b 1
)
echo.
pause