Skip to content

Commit

Permalink
Update deprecated method usages with new helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jul 26, 2024
1 parent 36d10ed commit 61d0e96
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/framework/resources/views/layouts/head.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ $page->title() }}</title>

@if (file_exists(Hyde::mediaPath('favicon.ico')))
@if (file_exists(MediaFile::sourcePath('favicon.ico')))
<link rel="shortcut icon" href="{{ Hyde::relativeLink('media/favicon.ico') }}" type="image/x-icon">
@endif

Expand Down
5 changes: 3 additions & 2 deletions packages/framework/src/Facades/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Hyde\Facades;

use Hyde\Hyde;
use Hyde\Support\Filesystem\MediaFile;

use function md5_file;
use function file_exists;
Expand All @@ -24,13 +25,13 @@ public static function mediaLink(string $file): string

public static function hasMediaFile(string $file): bool
{
return file_exists(Hyde::mediaPath($file));
return file_exists(MediaFile::sourcePath($file));
}

protected static function getCacheBustKey(string $file): string
{
return Config::getBool('hyde.enable_cache_busting', true)
? '?v='.md5_file(Hyde::mediaPath("$file"))
? '?v='.md5_file(MediaFile::sourcePath("$file"))
: '';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Hyde\Hyde;
use Hyde\Facades\Config;
use Hyde\Facades\Filesystem;
use Hyde\Support\Filesystem\MediaFile;
use Hyde\Framework\Features\BuildTasks\PreBuildTask;

use function basename;
Expand All @@ -22,7 +23,7 @@ public function handle(): void
{
if ($this->isItSafeToCleanOutputDirectory()) {
Filesystem::unlink(glob(Hyde::sitePath('*.{html,json}'), GLOB_BRACE));
Filesystem::cleanDirectory(Hyde::siteMediaPath());
Filesystem::cleanDirectory(MediaFile::outputPath());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Hyde\Framework\Actions\PreBuildTasks;

use Hyde\Hyde;
use Hyde\Support\Filesystem\MediaFile;
use Hyde\Framework\Features\BuildTasks\PreBuildTask;
use Hyde\Framework\Concerns\InteractsWithDirectories;
Expand All @@ -17,14 +16,14 @@ class TransferMediaAssets extends PreBuildTask

public function handle(): void
{
$this->needsDirectory(Hyde::siteMediaPath());
$this->needsDirectory(MediaFile::outputPath());

$this->newLine();

$this->withProgressBar(MediaFile::files(), function (string $identifier): void {
$sitePath = Hyde::siteMediaPath($identifier);
$sitePath = MediaFile::outputPath($identifier);
$this->needsParentDirectory($sitePath);
copy(Hyde::mediaPath($identifier), $sitePath);
copy(MediaFile::sourcePath($identifier), $sitePath);
});

$this->newLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Hyde\Support\BuildWarnings;
use Illuminate\Support\Facades\Http;
use Hyde\Foundation\Kernel\Hyperlinks;
use Hyde\Support\Filesystem\MediaFile;
use Hyde\Framework\Exceptions\FileNotFoundException;
use Hyde\Markdown\Contracts\FrontMatter\SubSchemas\FeaturedImageSchema;

Expand Down Expand Up @@ -213,7 +214,7 @@ protected function has(string $property): bool

protected function getContentLengthForLocalImage(): int
{
$storagePath = Hyde::mediaPath($this->source);
$storagePath = MediaFile::sourcePath($this->source);

if (! file_exists($storagePath)) {
throw new FileNotFoundException(customMessage: sprintf('Featured image [%s] not found.', Hyde::pathToRelative($storagePath)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Hyde\Pages\MarkdownPage;
use Hyde\Pages\DocumentationPage;
use Hyde\Enums\Feature;
use Hyde\Support\Filesystem\MediaFile;
use Hyde\Support\Models\ValidationResult as Result;

use function count;
Expand Down Expand Up @@ -102,12 +103,12 @@ public function check_documentation_site_has_an_index_page(Result $result): Resu

public function check_site_has_an_app_css_stylesheet(Result $result): Result
{
if (file_exists(Hyde::siteMediaPath('/app.css')) || file_exists(Hyde::mediaPath('app.css'))) {
if (file_exists(MediaFile::outputPath('/app.css')) || file_exists(MediaFile::sourcePath('app.css'))) {
return $result->pass('Your site has an app.css stylesheet');
}

return $result->fail(sprintf('Could not find an app.css file in the %s or %s directory!',
Hyde::pathToRelative(Hyde::siteMediaPath()), Hyde::getMediaDirectory()
Hyde::pathToRelative(MediaFile::outputPath()), Hyde::getMediaDirectory()
))->withTip('You may need to run `npm run dev`.`');
}

Expand Down
16 changes: 8 additions & 8 deletions packages/framework/tests/Feature/Foundation/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,20 +263,20 @@ public function testHelperForDocumentationPages()

public function testHelperForMediaPath()
{
$this->assertSame(Hyde::path('_media'), Hyde::mediaPath());
$this->assertSame(MediaFile::sourcePath(), Hyde::mediaPath());
$this->assertSame(Hyde::path('_media'), MediaFile::sourcePath());
$this->assertSame(MediaFile::sourcePath(), MediaFile::sourcePath());

$this->assertSame(Hyde::path('_media/foo.png'), Hyde::mediaPath('foo.png'));
$this->assertSame(MediaFile::sourcePath('foo.png'), Hyde::mediaPath('foo.png'));
$this->assertSame(Hyde::path('_media/foo.png'), MediaFile::sourcePath('foo.png'));
$this->assertSame(MediaFile::sourcePath('foo.png'), MediaFile::sourcePath('foo.png'));
}

public function testHelperForMediaOutputPath()
{
$this->assertSame(Hyde::path('_site/media'), Hyde::siteMediaPath());
$this->assertSame(MediaFile::outputPath(), Hyde::siteMediaPath());
$this->assertSame(Hyde::path('_site/media'), MediaFile::outputPath());
$this->assertSame(MediaFile::outputPath(), MediaFile::outputPath());

$this->assertSame(Hyde::path('_site/media/foo.png'), Hyde::siteMediaPath('foo.png'));
$this->assertSame(MediaFile::outputPath('foo.png'), Hyde::siteMediaPath('foo.png'));
$this->assertSame(Hyde::path('_site/media/foo.png'), MediaFile::outputPath('foo.png'));
$this->assertSame(MediaFile::outputPath('foo.png'), MediaFile::outputPath('foo.png'));
}

public function testHelperForSiteOutputPath()
Expand Down
11 changes: 6 additions & 5 deletions packages/framework/tests/Feature/HydeKernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Hyde\Foundation\HydeKernel;
use Hyde\Enums\Feature;
use Hyde\Foundation\Kernel\Filesystem;
use Hyde\Support\Filesystem\MediaFile;
use Hyde\Framework\HydeServiceProvider;
use Hyde\Hyde;
use Hyde\Pages\BladePage;
Expand Down Expand Up @@ -262,9 +263,9 @@ public function testFluentModelSourcePathHelpers()
$this->assertSame(Hyde::path('_pages'), MarkdownPage::path());
$this->assertSame(Hyde::path('_docs'), DocumentationPage::path());

$this->assertSame(Hyde::path('_media'), Hyde::mediaPath());
$this->assertSame(Hyde::path('_media'), MediaFile::sourcePath());
$this->assertSame(Hyde::path('_site/media'), MediaFile::outputPath());
$this->assertSame(Hyde::path('_site'), Hyde::sitePath());
$this->assertSame(Hyde::path('_site/media'), Hyde::siteMediaPath());
}

public function testPathToRelativeHelperReturnsRelativePathForGivenPath()
Expand Down Expand Up @@ -395,15 +396,15 @@ public function testCanGetSiteMediaOutputDirectory()
{
// Todo: Move to MediaFileTest

$this->assertSame(Hyde::path('_site/media'), Hyde::siteMediaPath());
$this->assertSame(Hyde::path('_site/media'), MediaFile::outputPath());
}

public function testGetSiteMediaOutputDirectoryUsesTrimmedVersionOfMediaSourceDirectory()
{
// Todo: Move to MediaFileTest

Hyde::setMediaDirectory('_foo');
$this->assertSame(Hyde::path('_site/foo'), Hyde::siteMediaPath());
$this->assertSame(Hyde::path('_site/foo'), MediaFile::outputPath());
}

public function testGetSiteMediaOutputDirectoryUsesConfiguredSiteOutputDirectory()
Expand All @@ -413,7 +414,7 @@ public function testGetSiteMediaOutputDirectoryUsesConfiguredSiteOutputDirectory
Hyde::setOutputDirectory(Hyde::path('foo'));
Hyde::setMediaDirectory('bar');

$this->assertSame(Hyde::path('foo/bar'), Hyde::siteMediaPath());
$this->assertSame(Hyde::path('foo/bar'), MediaFile::outputPath());
}

public function testMediaOutputDirectoryCanBeChangedInConfiguration()
Expand Down

0 comments on commit 61d0e96

Please sign in to comment.