Skip to content

Commit

Permalink
Merge pull request #1980 from hydephp/rename-cache-busting-config-set…
Browse files Browse the repository at this point in the history
…ting

Rename config option `hyde.enable_cache_busting` to `hyde.cache_busting`
  • Loading branch information
caendesilva authored Oct 5, 2024
2 parents d4d8af3 + 9c3f9f8 commit 2cc2a8f
Show file tree
Hide file tree
Showing 22 changed files with 42 additions and 39 deletions.
7 changes: 5 additions & 2 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ This serves two purposes:
- **Breaking:** The `Author::get()` method now returns `null` if an author is not found, rather than creating a new instance. For more information, see below.
- **Breaking:** The custom navigation item configuration now uses array inputs instead of the previous format. For more information, see the upgrade guide below.
- **Breaking:** Renamed the `hyde.navigation.subdirectories` configuration option to `hyde.navigation.subdirectory_display`.
- **Breaking:** Renamed the `hyde.enable_cache_busting` configuration option to `hyde.cache_busting` in https://github.com/hydephp/develop/pull/1980
- Medium: The `route` function will now throw a `RouteNotFoundException` if the route does not exist in https://github.com/hydephp/develop/pull/1741
- Minor: Navigation menu items are now no longer filtered by duplicates (meaning two items with the same label can now exist in the same menu) in https://github.com/hydephp/develop/pull/1573
- Minor: Due to changes in the navigation system, it is possible that existing configuration files will need to be adjusted in order for menus to look the same (in terms of ordering etc.)
Expand Down Expand Up @@ -349,9 +350,11 @@ Once you have determined that you need to update your code, here are the steps y
$config = HydeFront::injectTailwindConfig();
```

6. Remove any references to `hyde.hydefront_version` and `hyde.hydefront_cdn_url` in your config files as these options have been removed.
6. Rename the option `hyde.enable_cache_busting` to `hyde.cache_busting` in your configuration file.

7. If you were using `AssetService` directly, refactor your code to use the new `Asset` facade, `MediaFile` class, or `HydeFront` facade as appropriate.
7. Remove any references to `hyde.hydefront_version` and `hyde.hydefront_cdn_url` in your config files as these options have been removed.

8. If you were using `AssetService` directly, refactor your code to use the new `Asset` facade, `MediaFile` class, or `HydeFront` facade as appropriate.

These changes simplify the Asset API and provide more robust handling of media files. The new `MediaFile` class offers additional functionality for working with assets.

Expand Down
2 changes: 1 addition & 1 deletion config/hyde.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@
|
*/

'enable_cache_busting' => true,
'cache_busting' => true,

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/config/hyde.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@
|
*/

'enable_cache_busting' => true,
'cache_busting' => true,

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Support/Filesystem/MediaFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function toArray(): array

protected function getCacheBustKey(): string
{
return Config::getBool('hyde.enable_cache_busting', true)
return Config::getBool('hyde.cache_busting', true)
? '?v='.$this->getHash()
: '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function setUp(): void
{
parent::setUp();

config(['hyde.enable_cache_busting' => false]);
config(['hyde.cache_busting' => false]);
}

public function testBasicDynamicMarkdownLinks()
Expand Down
4 changes: 2 additions & 2 deletions packages/framework/tests/Feature/FeaturedImageFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function setUp(): void
{
parent::setUp();

config(['hyde.enable_cache_busting' => false]);
config(['hyde.cache_busting' => false]);

$this->file('_media/foo');
}
Expand Down Expand Up @@ -135,7 +135,7 @@ public function testImagePathsAreNormalizedForCustomizedMediaDirectoryWithoutUnd

public function testImagePathsWithCacheBusting()
{
config(['hyde.enable_cache_busting' => true]);
config(['hyde.cache_busting' => true]);

$this->assertSourceIsSame('media/foo?v=00000000', ['image' => 'foo']);
$this->assertSourceIsSame('media/foo?v=00000000', ['image' => 'media/foo']);
Expand Down
4 changes: 2 additions & 2 deletions packages/framework/tests/Feature/FeaturedImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function setUp(): void
{
parent::setUp();

config(['hyde.enable_cache_busting' => false]);
config(['hyde.cache_busting' => false]);

$this->file('_media/foo', 'test');
$this->file('_media/source');
Expand Down Expand Up @@ -118,7 +118,7 @@ public function testGetSourceMethod()

public function testImagePathsWithCacheBusting()
{
config(['hyde.enable_cache_busting' => true]);
config(['hyde.cache_busting' => true]);

$this->assertSame('media/foo?v=accf8b33', (new FeaturedImage('_media/foo', ...$this->defaultArguments()))->getSource());
$this->assertSame('media/foo?v=accf8b33', FeaturedImageFactory::make(new FrontMatter(['image.source' => 'foo']))->getSource());
Expand Down
4 changes: 2 additions & 2 deletions packages/framework/tests/Feature/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function setUp(): void
{
parent::setUp();

config(['hyde.enable_cache_busting' => false]);
config(['hyde.cache_busting' => false]);
}

/** @covers ::hyde */
Expand Down Expand Up @@ -89,7 +89,7 @@ public function testAssetFunction()
/** @covers ::asset */
public function testAssetFunctionWithCacheBusting()
{
config(['hyde.enable_cache_busting' => true]);
config(['hyde.cache_busting' => true]);

$this->assertInstanceOf(MediaFile::class, asset('app.css'));
$this->assertEquals(new MediaFile('media/app.css'), asset('app.css'));
Expand Down
10 changes: 5 additions & 5 deletions packages/framework/tests/Feature/HydeKernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public function testAssetHelperWithoutCacheBusting()
{
$this->file('_media/foo.jpg');

Config::set('hyde.enable_cache_busting', false);
Config::set('hyde.cache_busting', false);

$this->assertSame('media/foo.jpg', (string) Hyde::asset('foo.jpg'));
}
Expand All @@ -241,11 +241,11 @@ public function testAssetHelperWithoutCacheBustingWithChangedSettingInTheSameLif

$this->assertSame('media/foo.jpg?v=00000000', (string) Hyde::asset('foo.jpg'));

Config::set('hyde.enable_cache_busting', false);
Config::set('hyde.cache_busting', false);

$this->assertSame('media/foo.jpg', (string) Hyde::asset('foo.jpg'));

Config::set('hyde.enable_cache_busting', true);
Config::set('hyde.cache_busting', true);

$this->assertSame('media/foo.jpg?v=00000000', (string) Hyde::asset('foo.jpg'));
}
Expand All @@ -258,11 +258,11 @@ public function testAssetHelperWithoutCacheBustingWithChangedSettingInTheSameLif

$this->assertSame('media/foo.jpg?v=00000000', (string) $instance);

Config::set('hyde.enable_cache_busting', false);
Config::set('hyde.cache_busting', false);

$this->assertSame('media/foo.jpg', (string) $instance);

Config::set('hyde.enable_cache_busting', true);
Config::set('hyde.cache_busting', true);

$this->assertSame('media/foo.jpg?v=00000000', (string) $instance);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/tests/Feature/MarkdownPostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,6 @@ public function testBlogPostFeedCanBeRenderedWhenPostHasNoFrontMatter()
protected function setupMediaFileAndCacheBusting(bool $enableCacheBusting = false): void
{
$this->file('_media/foo.png', 'test content');
config(['hyde.enable_cache_busting' => $enableCacheBusting]);
config(['hyde.cache_busting' => $enableCacheBusting]);
}
}
2 changes: 1 addition & 1 deletion packages/framework/tests/Feature/MetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ public function testDynamicPostMetaPropertiesContainsImageMetadataWhenFeaturedIm

public function testDynamicPostMetaPropertiesContainsImageLinkWithoutCacheBusting()
{
config(['hyde.enable_cache_busting' => false]);
config(['hyde.cache_busting' => false]);

$this->file('_media/foo.jpg');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function setUp(): void

// Todo: No way to mock media files, so we are using app.css as a test asset for now.

self::mockConfig(['hyde.enable_cache_busting' => false]);
self::mockConfig(['hyde.cache_busting' => false]);
}

public function testRouteReplacement()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function testXmlChannelDataCanBeCustomized()

public function testMarkdownBlogPostsAreAddedToRssFeedThroughAutodiscovery()
{
config(['hyde.enable_cache_busting' => false]);
config(['hyde.cache_busting' => false]);

file_put_contents(Hyde::path('_posts/rss.md'), <<<'MD'
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected function setUp(): void
parent::setUp();

$this->withSiteUrl();
config(['hyde.enable_cache_busting' => false]);
config(['hyde.cache_busting' => false]);
}

protected function build(?string $page = null): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testAssetReturnsMediaPathWithCacheKey()

public function testAssetReturnsMediaPathWithoutCacheKeyIfCacheBustingIsDisabled()
{
self::mockConfig(['hyde.enable_cache_busting' => false]);
self::mockConfig(['hyde.cache_busting' => false]);

$path = (string) Asset::get('app.css');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function setUp(): void
{
parent::setUp();

config(['hyde.enable_cache_busting' => false]);
config(['hyde.cache_busting' => false]);
config(['hyde.navigation.subdirectory_display' => 'flat']);

$this->needsDirectory('_pages/nested');
Expand Down
18 changes: 9 additions & 9 deletions packages/framework/tests/Unit/Support/MediaFileUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected function setUp(): void
\Illuminate\Support\Facades\View::swap(Mockery::mock(Factory::class)->makePartial());
Render::swap(new RenderData());

self::mockConfig(['hyde.enable_cache_busting' => false]);
self::mockConfig(['hyde.cache_busting' => false]);
}

protected function tearDown(): void
Expand Down Expand Up @@ -463,7 +463,7 @@ public function testGetLinkWithCustomMediaDirectory()

public function testGetLinkWithPrettyUrls()
{
self::mockConfig(['hyde.enable_cache_busting' => false, 'hyde.pretty_urls' => true]);
self::mockConfig(['hyde.cache_busting' => false, 'hyde.pretty_urls' => true]);
$file = MediaFile::make('foo.txt');
$this->assertSame('media/foo.txt', $file->getLink());
}
Expand All @@ -476,15 +476,15 @@ public function testGetLinkWithNestedFile()

public function testGetLinkWithBaseUrl()
{
self::mockConfig(['hyde.enable_cache_busting' => false, 'hyde.url' => 'https://example.com']);
self::mockConfig(['hyde.cache_busting' => false, 'hyde.url' => 'https://example.com']);
$file = MediaFile::make('foo.txt');
$this->assertSame('https://example.com/media/foo.txt', $file->getLink());
}

public function testGetLinkWithBaseUrlAndPrettyUrls()
{
self::mockConfig([
'hyde.enable_cache_busting' => false,
'hyde.cache_busting' => false,
'hyde.url' => 'https://example.com',
'hyde.pretty_urls' => true,
]);
Expand All @@ -494,7 +494,7 @@ public function testGetLinkWithBaseUrlAndPrettyUrls()

public function testGetLinkWithCacheBusting()
{
self::mockConfig(['hyde.enable_cache_busting' => true]);
self::mockConfig(['hyde.cache_busting' => true]);
$this->mockFilesystem->shouldReceive('hash')
->andReturn('abc123');
$file = MediaFile::make('foo.txt');
Expand All @@ -503,7 +503,7 @@ public function testGetLinkWithCacheBusting()

public function testGetLinkWithCacheBustingDisabled()
{
self::mockConfig(['hyde.enable_cache_busting' => false]);
self::mockConfig(['hyde.cache_busting' => false]);
$file = MediaFile::make('foo.txt');
$this->assertSame('media/foo.txt', $file->getLink());
}
Expand Down Expand Up @@ -547,7 +547,7 @@ public function testStringCastWithCustomMediaDirectory()

public function testStringCastWithPrettyUrls()
{
self::mockConfig(['hyde.enable_cache_busting' => false, 'hyde.pretty_urls' => true]);
self::mockConfig(['hyde.cache_busting' => false, 'hyde.pretty_urls' => true]);
$file = new MediaFile('foo.txt');
$this->assertSame('media/foo.txt', (string) $file);
}
Expand All @@ -560,14 +560,14 @@ public function testStringCastWithNestedFile()

public function testStringCastWithBaseUrl()
{
self::mockConfig(['hyde.enable_cache_busting' => false, 'hyde.url' => 'https://example.com']);
self::mockConfig(['hyde.cache_busting' => false, 'hyde.url' => 'https://example.com']);
$file = new MediaFile('foo.txt');
$this->assertSame('https://example.com/media/foo.txt', (string) $file);
}

public function testStringCastWithCacheBusting()
{
self::mockConfig(['hyde.enable_cache_busting' => true]);
self::mockConfig(['hyde.cache_busting' => true]);
$this->mockFilesystem->shouldReceive('hash')
->andReturn('abc123');
$file = new MediaFile('foo.txt');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function testItempropImageIsAddedWhenThereIsAnImageWithLocalPathNoCache()
{
$this->file('_media/image.jpg');

config(['hyde.enable_cache_busting' => false]);
config(['hyde.cache_busting' => false]);

$viewLocalNoCache = $this->renderTestView(MarkdownPost::make(matter: [
'image' => 'image.jpg',
Expand Down
4 changes: 2 additions & 2 deletions packages/framework/tests/Unit/Views/FeaturedImageViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function setUp(): void
{
parent::setUp();
$this->file('_media/foo.jpg', 'test content');
config(['hyde.enable_cache_busting' => false]);
config(['hyde.cache_busting' => false]);
}

public function testTheView()
Expand Down Expand Up @@ -259,7 +259,7 @@ public function testFluentAttributionLogicCreatesFluentMessages7()

public function testCacheBusting()
{
config(['hyde.enable_cache_busting' => true]);
config(['hyde.cache_busting' => true]);
$component = $this->renderComponent();
$this->assertStringContainsString('src="media/foo.jpg?v=98b41d87"', $component);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testLinkToFaviconDoesNotUseCacheBustingWhenDisabled()
$this->file('_media/favicon.ico');
$this->mockPage(currentPage: 'foo/bar');

config(['hyde.enable_cache_busting' => false]);
config(['hyde.cache_busting' => false]);

$this->assertStringContainsString('<link rel="shortcut icon" href="../media/favicon.ico" type="image/x-icon">', $this->renderTestView());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ScriptsComponentViewTest extends TestCase

protected function renderTestView(): string
{
config(['hyde.enable_cache_busting' => false]);
config(['hyde.cache_busting' => false]);
$this->mockCurrentPage($this->mockCurrentPage ?? '');

return Blade::render(file_get_contents(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class StylesComponentViewTest extends TestCase

protected function renderTestView(): string
{
config(['hyde.enable_cache_busting' => false]);
config(['hyde.cache_busting' => false]);
$this->mockCurrentPage($this->mockCurrentPage ?? '');

return Blade::render(file_get_contents(
Expand Down

0 comments on commit 2cc2a8f

Please sign in to comment.