Skip to content

Commit a800618

Browse files
authored
Merge pull request #1911 from hydephp/normalize-media-path-helpers
[2.x] Normalize media path helpers to unify naming with HydePages
2 parents 9ba410a + 4647333 commit a800618

File tree

17 files changed

+166
-116
lines changed

17 files changed

+166
-116
lines changed

app/config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
'MarkdownPage' => \Hyde\Pages\MarkdownPage::class,
106106
'MarkdownPost' => \Hyde\Pages\MarkdownPost::class,
107107
'DocumentationPage' => \Hyde\Pages\DocumentationPage::class,
108+
'MediaFile' => \Hyde\Support\Filesystem\MediaFile::class,
108109
'DataCollection' => \Hyde\Support\DataCollection::class,
109110
'Includes' => \Hyde\Support\Includes::class,
110111
'Feature' => \Hyde\Enums\Feature::class,

docs/_data/partials/hyde-pages-api/hyde-kernel-filesystem-methods.md

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<section id="hyde-kernel-filesystem-methods">
22

33
<!-- Start generated docs for Hyde\Foundation\Concerns\ForwardsFilesystem -->
4-
<!-- Generated by HydePHP DocGen script at 2023-03-11 11:17:34 in 0.10ms -->
4+
<!-- Generated by HydePHP DocGen script at 2024-07-26 15:15:12 in 0.09ms -->
55

66
#### `filesystem()`
77

@@ -27,14 +27,6 @@ No description provided.
2727
Hyde::vendorPath(string $path, string $package): string
2828
```
2929

30-
#### `mediaPath()`
31-
32-
No description provided.
33-
34-
```php
35-
Hyde::mediaPath(string $path): string
36-
```
37-
3830
#### `sitePath()`
3931

4032
No description provided.
@@ -43,14 +35,6 @@ No description provided.
4335
Hyde::sitePath(string $path): string
4436
```
4537

46-
#### `siteMediaPath()`
47-
48-
No description provided.
49-
50-
```php
51-
Hyde::siteMediaPath(string $path): string
52-
```
53-
5438
#### `pathToAbsolute()`
5539

5640
No description provided.

packages/framework/resources/views/layouts/head.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<meta name="viewport" content="width=device-width, initial-scale=1">
33
<title>{{ $page->title() }}</title>
44

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

packages/framework/src/Facades/Asset.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Hyde\Facades;
66

77
use Hyde\Hyde;
8+
use Hyde\Support\Filesystem\MediaFile;
89

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

2526
public static function hasMediaFile(string $file): bool
2627
{
27-
return file_exists(Hyde::mediaPath($file));
28+
return file_exists(MediaFile::sourcePath($file));
2829
}
2930

3031
protected static function getCacheBustKey(string $file): string
3132
{
3233
return Config::getBool('hyde.enable_cache_busting', true)
33-
? '?v='.md5_file(Hyde::mediaPath("$file"))
34+
? '?v='.md5_file(MediaFile::sourcePath("$file"))
3435
: '';
3536
}
3637
}

packages/framework/src/Foundation/Concerns/ForwardsFilesystem.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,11 @@ public function vendorPath(string $path = '', string $package = 'framework'): st
2828
return $this->filesystem->vendorPath($path, $package);
2929
}
3030

31-
public function mediaPath(string $path = ''): string
32-
{
33-
return $this->filesystem->mediaPath($path);
34-
}
35-
3631
public function sitePath(string $path = ''): string
3732
{
3833
return $this->filesystem->sitePath($path);
3934
}
4035

41-
public function siteMediaPath(string $path = ''): string
42-
{
43-
return $this->filesystem->siteMediaPath($path);
44-
}
45-
4636
public function pathToAbsolute(string|array $path): string|array
4737
{
4838
return $this->filesystem->pathToAbsolute($path);

packages/framework/src/Foundation/Kernel/Filesystem.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,6 @@ public function pathToRelative(string $path): string
9191
: $path);
9292
}
9393

94-
/**
95-
* Get the absolute path to the media source directory, or a file within it.
96-
*/
97-
public function mediaPath(string $path = ''): string
98-
{
99-
if (empty($path)) {
100-
return $this->path(Hyde::getMediaDirectory());
101-
}
102-
103-
return $this->path(path_join(Hyde::getMediaDirectory(), unslash($path)));
104-
}
105-
10694
/**
10795
* Get the absolute path to the compiled site directory, or a file within it.
10896
*/
@@ -115,20 +103,6 @@ public function sitePath(string $path = ''): string
115103
return $this->path(path_join(Hyde::getOutputDirectory(), unslash($path)));
116104
}
117105

118-
/**
119-
* Get the absolute path to the compiled site's media directory, or a file within it.
120-
*/
121-
public function siteMediaPath(string $path = ''): string
122-
{
123-
if (empty($path)) {
124-
return $this->sitePath(Hyde::getMediaOutputDirectory());
125-
}
126-
127-
$path = unslash($path);
128-
129-
return $this->sitePath(Hyde::getMediaOutputDirectory()."/$path");
130-
}
131-
132106
/**
133107
* Works similarly to the path() function, but returns a file in the Framework package.
134108
*

packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Hyde\Hyde;
88
use Hyde\Facades\Config;
99
use Hyde\Facades\Filesystem;
10+
use Hyde\Support\Filesystem\MediaFile;
1011
use Hyde\Framework\Features\BuildTasks\PreBuildTask;
1112

1213
use function basename;
@@ -22,7 +23,7 @@ public function handle(): void
2223
{
2324
if ($this->isItSafeToCleanOutputDirectory()) {
2425
Filesystem::unlink(glob(Hyde::sitePath('*.{html,json}'), GLOB_BRACE));
25-
Filesystem::cleanDirectory(Hyde::siteMediaPath());
26+
Filesystem::cleanDirectory(MediaFile::outputPath());
2627
}
2728
}
2829

packages/framework/src/Framework/Actions/PreBuildTasks/TransferMediaAssets.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Hyde\Framework\Actions\PreBuildTasks;
66

7-
use Hyde\Hyde;
87
use Hyde\Support\Filesystem\MediaFile;
98
use Hyde\Framework\Features\BuildTasks\PreBuildTask;
109
use Hyde\Framework\Concerns\InteractsWithDirectories;
@@ -17,14 +16,14 @@ class TransferMediaAssets extends PreBuildTask
1716

1817
public function handle(): void
1918
{
20-
$this->needsDirectory(Hyde::siteMediaPath());
19+
$this->needsDirectory(MediaFile::outputPath());
2120

2221
$this->newLine();
2322

2423
$this->withProgressBar(MediaFile::files(), function (string $identifier): void {
25-
$sitePath = Hyde::siteMediaPath($identifier);
24+
$sitePath = MediaFile::outputPath($identifier);
2625
$this->needsParentDirectory($sitePath);
27-
copy(Hyde::mediaPath($identifier), $sitePath);
26+
copy(MediaFile::sourcePath($identifier), $sitePath);
2827
});
2928

3029
$this->newLine();

packages/framework/src/Framework/Features/Blogging/Models/FeaturedImage.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Hyde\Support\BuildWarnings;
1212
use Illuminate\Support\Facades\Http;
1313
use Hyde\Foundation\Kernel\Hyperlinks;
14+
use Hyde\Support\Filesystem\MediaFile;
1415
use Hyde\Framework\Exceptions\FileNotFoundException;
1516
use Hyde\Markdown\Contracts\FrontMatter\SubSchemas\FeaturedImageSchema;
1617

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

214215
protected function getContentLengthForLocalImage(): int
215216
{
216-
$storagePath = Hyde::mediaPath($this->source);
217+
$storagePath = MediaFile::sourcePath($this->source);
217218

218219
if (! file_exists($storagePath)) {
219220
throw new FileNotFoundException(customMessage: sprintf('Featured image [%s] not found.', Hyde::pathToRelative($storagePath)));

packages/framework/src/Framework/Services/ValidationService.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Hyde\Pages\MarkdownPage;
1212
use Hyde\Pages\DocumentationPage;
1313
use Hyde\Enums\Feature;
14+
use Hyde\Support\Filesystem\MediaFile;
1415
use Hyde\Support\Models\ValidationResult as Result;
1516

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

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

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

0 commit comments

Comments
 (0)