From 3fa62a5be3fb524c0f4751fa872f586f1068acd1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 7 Apr 2022 22:09:01 +0200 Subject: [PATCH] Implement the functionality --- src/Commands/HydeRebuildStaticSiteCommand.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/Commands/HydeRebuildStaticSiteCommand.php b/src/Commands/HydeRebuildStaticSiteCommand.php index a910c062..20c3d825 100644 --- a/src/Commands/HydeRebuildStaticSiteCommand.php +++ b/src/Commands/HydeRebuildStaticSiteCommand.php @@ -50,6 +50,10 @@ public function handle(): int { $time_start = microtime(true); + if ($this->argument('path') === '_media') { + return $this->handleMediaFiles(); + } + $this->path = $this->sanitizePathString($this->argument('path')); try { @@ -142,4 +146,37 @@ public function createClickableFilepath(string $filepath): string realpath($filepath) ); } + + /** + * Handle the media files command. + * + * @return int + */ + public function handleMediaFiles(): int + { + $collection = glob(Hyde::path('_media/*.{png,svg,jpg,jpeg,gif,ico,css,js}'), GLOB_BRACE); + $collection = array_merge($collection, [ + Hyde::path('resources/frontend/hyde.css'), + Hyde::path('resources/frontend/hyde.js'), + ]); + if (sizeof($collection) < 1) { + $this->line('No Media Assets found. Skipping...'); + $this->newLine(); + } else { + $this->comment('Transferring Media Assets...'); + $this->withProgressBar( + $collection, + function ($filepath) { + if ($this->getOutput()->isVeryVerbose()) { + $this->line(' > Copying media file ' + .basename($filepath).' to the output media directory'); + } + copy($filepath, Hyde::path('_site/media/'.basename($filepath))); + } + ); + $this->newLine(2); + } + + return 1; + } }