feat(cms): sync site assets, revalidate webhook, and document download naming

This commit is contained in:
2026-02-10 23:38:31 +08:00
parent c4969cd4d2
commit b6e18a83ec
27 changed files with 1019 additions and 26 deletions

View File

@@ -30,7 +30,7 @@ class ImportHugoContent extends Command
private int $tagsCreated = 0;
private int $imagescopied = 0;
private int $imagesCopied = 0;
private int $skipped = 0;
@@ -140,7 +140,7 @@ class ImportHugoContent extends Command
['Pages created', $this->pagesCreated],
['Categories created', $this->categoriesCreated],
['Tags created', $this->tagsCreated],
['Images copied', $this->imagescopied],
['Images copied', $this->imagesCopied],
['Skipped (_index.md etc.)', $this->skipped],
]
);
@@ -360,7 +360,15 @@ class ImportHugoContent extends Command
{
$this->info("Copying images from: {$imagesPath}");
$destPath = storage_path('app/public/migrated-images');
$nextPublicRoot = config('services.nextjs.public_path');
if (! is_string($nextPublicRoot) || $nextPublicRoot === '' || ! is_dir($nextPublicRoot)) {
$nextPublicRoot = base_path('../usher-site/public');
}
$nextPublicImages = rtrim($nextPublicRoot, '/').'/images';
$destPath = is_dir($nextPublicImages)
? $nextPublicImages
: storage_path('app/public/migrated-images');
if (! $isDryRun && ! is_dir($destPath)) {
File::makeDirectory($destPath, 0755, true);
@@ -382,7 +390,12 @@ class ImportHugoContent extends Command
File::copy($file->getPathname(), $destFile);
}
$this->imagescopied++;
$this->imagesCopied++;
}
// If we copied into the Next.js repo, optionally auto-push the new assets.
if (str_ends_with($destPath, '/images') && is_dir(dirname($destPath).'/.git')) {
\App\Services\NextjsRepoSyncService::scheduleAssetsPush();
}
}
@@ -511,7 +524,7 @@ class ImportHugoContent extends Command
/**
* Convert Hugo image paths to migrated storage paths.
* Hugo: "images/blog/Update.jpg" "migrated-images/blog/Update.jpg"
* Hugo: "images/blog/Update.jpg" "images/blog/Update.jpg"
*/
private function resolveImagePath(?string $hugoPath): ?string
{
@@ -519,9 +532,13 @@ class ImportHugoContent extends Command
return null;
}
// Remove leading "images/" prefix
$relativePath = preg_replace('#^images/#', '', $hugoPath);
$path = ltrim($hugoPath, '/');
return "migrated-images/{$relativePath}";
// Normalize to "images/..." so it can be served from Next.js public/images/.
if (! str_starts_with($path, 'images/')) {
$path = 'images/'.ltrim($path, '/');
}
return $path;
}
}