Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supply _media as the path argument in the hyde:rebuild command to copy all media files. #71

Merged
merged 1 commit into from
Apr 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/Commands/HydeRebuildStaticSiteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
}