From 9e37fba6d02780db263c5c80404ff4ec746680e6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 15:48:32 +0200 Subject: [PATCH 01/33] Add PHPDoc --- .../framework/src/Concerns/FrontMatter/Schemas/PageSchema.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php b/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php index 14735f13c8a..e36e4c331c6 100644 --- a/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php +++ b/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php @@ -15,6 +15,9 @@ trait PageSchema */ public string $title; + /** + * The settings for how the page should be presented in the navigation menu. + */ #[ArrayShape(['title' => 'string', 'hidden' => 'bool', 'priority' => 'int'])] public ?array $navigation = null; From dd71aa960b6c916bef173dfcd7c9f32d0bc6a147 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 15:53:44 +0200 Subject: [PATCH 02/33] Use mocks instead of making new classes --- packages/framework/tests/Feature/AbstractPageTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/framework/tests/Feature/AbstractPageTest.php b/packages/framework/tests/Feature/AbstractPageTest.php index 53037759e23..ba7b02ff036 100644 --- a/packages/framework/tests/Feature/AbstractPageTest.php +++ b/packages/framework/tests/Feature/AbstractPageTest.php @@ -248,12 +248,12 @@ public function test_all_page_models_have_configured_file_extension() public function test_abstract_markdown_page_extends_abstract_page() { - $this->assertInstanceOf(AbstractPage::class, new class extends AbstractMarkdownPage {}); + $this->assertInstanceOf(AbstractPage::class, $this->mock(AbstractMarkdownPage::class)); } public function test_abstract_markdown_page_implements_page_contract() { - $this->assertInstanceOf(PageContract::class, new class extends AbstractMarkdownPage {}); + $this->assertInstanceOf(PageContract::class, $this->mock(AbstractMarkdownPage::class)); } public function test_abstract_markdown_page_has_markdown_document_property() @@ -273,8 +273,8 @@ public function test_abstract_markdown_page_file_extension_property_is_set_to_md public function test_abstract_markdown_page_constructor_arguments_are_optional() { - $page = new class extends AbstractMarkdownPage {}; - $this->assertInstanceOf(AbstractMarkdownPage::class, $page); // If we get this far, we're good as no exception was thrown + $page = $this->mock(AbstractMarkdownPage::class); + $this->assertInstanceOf(AbstractMarkdownPage::class, $page); } public function test_abstract_markdown_page_constructor_assigns_markdown_document_property_if_set() From 9135ff77a3fc16ac5c17593dc6594bffd7c57662 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 15:54:19 +0200 Subject: [PATCH 03/33] Add canonicalUrl property to page schema --- .../src/Concerns/FrontMatter/Schemas/PageSchema.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php b/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php index e36e4c331c6..791d8c9e7ab 100644 --- a/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php +++ b/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php @@ -21,6 +21,12 @@ trait PageSchema #[ArrayShape(['title' => 'string', 'hidden' => 'bool', 'priority' => 'int'])] public ?array $navigation = null; + /** + * The canonical URL of the page. + * @var string|null + */ + public ?string $canonicalUrl = null; + protected function constructPageSchema(): void { $this->title = FindsTitleForPage::run($this); From 96c5f57090200a5cdefc573a56ef6a65b797cd7d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 15:54:28 +0200 Subject: [PATCH 04/33] Construct canonicalUrl property --- .../Concerns/FrontMatter/Schemas/PageSchema.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php b/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php index 791d8c9e7ab..23f86fc31b6 100644 --- a/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php +++ b/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php @@ -4,6 +4,7 @@ use Hyde\Framework\Actions\Constructors\FindsNavigationDataForPage; use Hyde\Framework\Actions\Constructors\FindsTitleForPage; +use Hyde\Framework\Hyde; use JetBrains\PhpStorm\ArrayShape; trait PageSchema @@ -31,5 +32,19 @@ protected function constructPageSchema(): void { $this->title = FindsTitleForPage::run($this); $this->navigation = FindsNavigationDataForPage::run($this); + $this->canonicalUrl = $this->makeCanonicalUrl(); + } + + protected function makeCanonicalUrl(): ?string + { + if (! empty($this->matter('canonicalUrl'))) { + return $this->matter('canonicalUrl'); + } + + if (Hyde::hasSiteUrl() && isset($this->identifier)) { + return $this->getRoute()->getQualifiedUrl(); + } + + return null; } } From 69af2c103c606fda2682589fe89a3aaf8d57b258 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 7 Aug 2022 13:54:39 +0000 Subject: [PATCH 05/33] Apply fixes from StyleCI --- .../framework/src/Concerns/FrontMatter/Schemas/PageSchema.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php b/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php index 23f86fc31b6..26798f013ac 100644 --- a/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php +++ b/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php @@ -24,6 +24,7 @@ trait PageSchema /** * The canonical URL of the page. + * * @var string|null */ public ?string $canonicalUrl = null; From 000c3df3476f694d893fabe82bed20eceb64fa34 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 16:00:20 +0200 Subject: [PATCH 06/33] Test covers PageSchema --- packages/framework/tests/Feature/AbstractPageTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/tests/Feature/AbstractPageTest.php b/packages/framework/tests/Feature/AbstractPageTest.php index ba7b02ff036..ca3f5f93b25 100644 --- a/packages/framework/tests/Feature/AbstractPageTest.php +++ b/packages/framework/tests/Feature/AbstractPageTest.php @@ -24,6 +24,7 @@ * @covers \Hyde\Framework\Contracts\AbstractPage * @covers \Hyde\Framework\Contracts\AbstractMarkdownPage * @covers \Hyde\Framework\Actions\Constructors\FindsNavigationDataForPage + * @covers \Hyde\Framework\Concerns\FrontMatter\Schemas\PageSchema * * @see \Hyde\Framework\Testing\Unit\AbstractPageMetadataTest */ From 5917471b0dc68662f9ef8cbca483a1cee4d17799 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 16:18:09 +0200 Subject: [PATCH 07/33] Page must be made after configuration is changed --- .../tests/Unit/AbstractPageMetadataTest.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/framework/tests/Unit/AbstractPageMetadataTest.php b/packages/framework/tests/Unit/AbstractPageMetadataTest.php index 6d8508cd05c..049c833bc19 100644 --- a/packages/framework/tests/Unit/AbstractPageMetadataTest.php +++ b/packages/framework/tests/Unit/AbstractPageMetadataTest.php @@ -30,34 +30,33 @@ protected function makePage(string $slug = 'foo'): MarkdownPage public function test_get_canonical_url_returns_url_for_top_level_page() { - $page = $this->makePage(); config(['site.url' => 'https://example.com']); + $page = $this->makePage(); $this->assertEquals('https://example.com/foo.html', $page->getCanonicalUrl()); } public function test_get_canonical_url_returns_pretty_url_for_top_level_page() { - $page = $this->makePage(); config(['site.url' => 'https://example.com']); config(['site.pretty_urls' => true]); + $page = $this->makePage(); $this->assertEquals('https://example.com/foo', $page->getCanonicalUrl()); } public function test_get_canonical_url_returns_url_for_nested_page() { - $page = $this->makePage('foo/bar'); config(['site.url' => 'https://example.com']); + $page = $this->makePage('foo/bar'); $this->assertEquals('https://example.com/foo/bar.html', $page->getCanonicalUrl()); } public function test_get_canonical_url_returns_url_for_deeply_nested_page() { - $page = $this->makePage('foo/bar/baz'); - config(['site.url' => 'https://example.com']); + $page = $this->makePage('foo/bar/baz'); $this->assertEquals('https://example.com/foo/bar/baz.html', $page->getCanonicalUrl()); } @@ -95,12 +94,11 @@ public function test_render_page_metadata_returns_string() public function test_render_page_metadata_returns_string_with_merged_metadata() { - $page = $this->makePage(); config(['site.url' => 'https://example.com']); - config(['hyde.meta' => [ Meta::name('foo', 'bar'), ]]); + $page = $this->makePage(); $this->assertStringContainsString( ''."\n". @@ -131,12 +129,11 @@ public function test_get_dynamic_metadata_only_adds_canonical_if_conditions_are_ public function test_get_dynamic_metadata_adds_canonical_url_when_conditions_are_met() { - $page = $this->makePage(); config(['site.url' => 'https://example.com']); - config(['hyde.meta' => [ Meta::name('foo', 'bar'), ]]); + $page = $this->makePage(); $this->assertContains('', $page->getDynamicMetadata() From 6f2f461204939edcdd095a7c4c2b115da97cfda4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 16:19:45 +0200 Subject: [PATCH 08/33] Use canonicalUrl property instead of getter --- packages/framework/src/Contracts/AbstractPage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Contracts/AbstractPage.php b/packages/framework/src/Contracts/AbstractPage.php index 728341f828f..7344f041f93 100644 --- a/packages/framework/src/Contracts/AbstractPage.php +++ b/packages/framework/src/Contracts/AbstractPage.php @@ -177,8 +177,8 @@ public function getDynamicMetadata(): array { $array = []; - if ($this->canUseCanonicalUrl()) { - $array[] = ''; + if ($this->canonicalUrl) { + $array[] = ''; } if (Features::sitemap()) { From 06145be3a913bd095e9c3fcd601dcb939a7c2069 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 16:26:24 +0200 Subject: [PATCH 09/33] Remove getters only used in tests --- .../framework/src/Contracts/AbstractPage.php | 10 ------ .../tests/Unit/AbstractPageMetadataTest.php | 35 +++++++++---------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/packages/framework/src/Contracts/AbstractPage.php b/packages/framework/src/Contracts/AbstractPage.php index 7344f041f93..9fa84c1b912 100644 --- a/packages/framework/src/Contracts/AbstractPage.php +++ b/packages/framework/src/Contracts/AbstractPage.php @@ -163,11 +163,6 @@ public function getBladeView(): string /** @inheritDoc */ abstract public function compile(): string; - public function getCanonicalUrl(): string - { - return $this->getRoute()->getQualifiedUrl(); - } - /** * @return string[] * @@ -218,11 +213,6 @@ public function renderPageMetadata(): string ); } - public function canUseCanonicalUrl(): bool - { - return Hyde::hasSiteUrl() && isset($this->identifier); - } - public function hasTwitterTitleInConfig(): bool { return str_contains(json_encode(config('hyde.meta', [])), 'twitter:title'); diff --git a/packages/framework/tests/Unit/AbstractPageMetadataTest.php b/packages/framework/tests/Unit/AbstractPageMetadataTest.php index 049c833bc19..da55ceb0008 100644 --- a/packages/framework/tests/Unit/AbstractPageMetadataTest.php +++ b/packages/framework/tests/Unit/AbstractPageMetadataTest.php @@ -33,7 +33,7 @@ public function test_get_canonical_url_returns_url_for_top_level_page() config(['site.url' => 'https://example.com']); $page = $this->makePage(); - $this->assertEquals('https://example.com/foo.html', $page->getCanonicalUrl()); + $this->assertEquals('https://example.com/foo.html', $page->canonicalUrl); } public function test_get_canonical_url_returns_pretty_url_for_top_level_page() @@ -42,7 +42,7 @@ public function test_get_canonical_url_returns_pretty_url_for_top_level_page() config(['site.pretty_urls' => true]); $page = $this->makePage(); - $this->assertEquals('https://example.com/foo', $page->getCanonicalUrl()); + $this->assertEquals('https://example.com/foo', $page->canonicalUrl); } public function test_get_canonical_url_returns_url_for_nested_page() @@ -50,7 +50,7 @@ public function test_get_canonical_url_returns_url_for_nested_page() config(['site.url' => 'https://example.com']); $page = $this->makePage('foo/bar'); - $this->assertEquals('https://example.com/foo/bar.html', $page->getCanonicalUrl()); + $this->assertEquals('https://example.com/foo/bar.html', $page->canonicalUrl); } public function test_get_canonical_url_returns_url_for_deeply_nested_page() @@ -58,32 +58,29 @@ public function test_get_canonical_url_returns_url_for_deeply_nested_page() config(['site.url' => 'https://example.com']); $page = $this->makePage('foo/bar/baz'); - $this->assertEquals('https://example.com/foo/bar/baz.html', $page->getCanonicalUrl()); + $this->assertEquals('https://example.com/foo/bar/baz.html', $page->canonicalUrl); } - public function test_can_use_canonical_url_returns_true_when_both_uri_path_and_slug_is_set() + public function test_canonical_url_is_not_set_when_identifier_is_null() { - $page = $this->makePage(); config(['site.url' => 'https://example.com']); - - $this->assertTrue($page->canUseCanonicalUrl()); - } - - public function test_can_use_canonical_url_returns_false_no_conditions_are_met() - { $page = new MarkdownPage(); - $this->assertFalse($page->canUseCanonicalUrl()); + $this->assertNull($page->canonicalUrl); + $this->assertStringNotContainsString( + 'renderPageMetadata() + ); } - public function test_can_use_canonical_url_returns_false_when_only_one_condition_is_met() + public function test_canonical_url_is_not_set_when_site_url_is_null() { - $page = new MarkdownPage(); - $this->assertFalse($page->canUseCanonicalUrl()); - config(['site.url' => null]); $page = $this->makePage(); - - $this->assertFalse($page->canUseCanonicalUrl()); + $this->assertNull($page->canonicalUrl); + $this->assertStringNotContainsString( + 'renderPageMetadata() + ); } public function test_render_page_metadata_returns_string() From 51c651d69187cabb0cfa4dcf3c71641af6977513 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 16:26:35 +0200 Subject: [PATCH 10/33] Check if not empty instead of is set --- .../framework/src/Concerns/FrontMatter/Schemas/PageSchema.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php b/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php index 26798f013ac..5cb5c52772f 100644 --- a/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php +++ b/packages/framework/src/Concerns/FrontMatter/Schemas/PageSchema.php @@ -42,7 +42,7 @@ protected function makeCanonicalUrl(): ?string return $this->matter('canonicalUrl'); } - if (Hyde::hasSiteUrl() && isset($this->identifier)) { + if (Hyde::hasSiteUrl() && ! empty($this->identifier)) { return $this->getRoute()->getQualifiedUrl(); } From dcef1ae8c422366860bd5187560cc31146b9d4fd Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 16:28:56 +0200 Subject: [PATCH 11/33] Test custom canonical link can be set in front matter --- .../framework/tests/Unit/AbstractPageMetadataTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/framework/tests/Unit/AbstractPageMetadataTest.php b/packages/framework/tests/Unit/AbstractPageMetadataTest.php index da55ceb0008..ac852e11a4d 100644 --- a/packages/framework/tests/Unit/AbstractPageMetadataTest.php +++ b/packages/framework/tests/Unit/AbstractPageMetadataTest.php @@ -83,6 +83,17 @@ public function test_canonical_url_is_not_set_when_site_url_is_null() ); } + public function test_custom_canonical_link_can_be_set_in_front_matter() + { + config(['site.url' => 'https://example.com']); + $page = MarkdownPage::make(matter: ['canonicalUrl' => 'foo/bar']); + $this->assertEquals('foo/bar', $page->canonicalUrl); + $this->assertStringContainsString( + '', + $page->renderPageMetadata() + ); + } + public function test_render_page_metadata_returns_string() { $page = $this->makePage(); From 7f6c1f4336a0c874517b0d58702f290a2eb9dbab Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 16:31:15 +0200 Subject: [PATCH 12/33] Inline setup method --- .../tests/Unit/AbstractPageMetadataTest.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/framework/tests/Unit/AbstractPageMetadataTest.php b/packages/framework/tests/Unit/AbstractPageMetadataTest.php index ac852e11a4d..b46ac74bd3b 100644 --- a/packages/framework/tests/Unit/AbstractPageMetadataTest.php +++ b/packages/framework/tests/Unit/AbstractPageMetadataTest.php @@ -13,16 +13,6 @@ */ class AbstractPageMetadataTest extends TestCase { - protected function setUp(): void - { - parent::setUp(); - - config(['hyde.meta' => []]); - config(['site.url' => null]); - config(['site.pretty_urls' => false]); - config(['site.generate_sitemap' => false]); - } - protected function makePage(string $slug = 'foo'): MarkdownPage { return new MarkdownPage(identifier: $slug); @@ -117,6 +107,8 @@ public function test_render_page_metadata_returns_string_with_merged_metadata() public function test_render_page_metadata_only_adds_canonical_if_conditions_are_met() { + config(['site.url' => null]); + config(['hyde.meta' => []]); $page = $this->makePage(); $this->assertEquals( @@ -127,6 +119,8 @@ public function test_render_page_metadata_only_adds_canonical_if_conditions_are_ public function test_get_dynamic_metadata_only_adds_canonical_if_conditions_are_met() { + config(['site.url' => null]); + config(['hyde.meta' => []]); $page = $this->makePage(); $this->assertEquals( @@ -214,6 +208,7 @@ public function test_has_open_graph_title_in_config_returns_false_when_not_prese public function test_get_dynamic_metadata_adds_twitter_and_open_graph_title_when_conditions_are_met() { + config(['site.url' => null]); config(['hyde.meta' => [ Meta::name('twitter:title', 'foo'), Meta::property('title', 'foo'), From 7b46b86a526ea0f180b03c1da0e967936a0731d3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 16:34:16 +0200 Subject: [PATCH 13/33] Inline helper method --- .../tests/Unit/AbstractPageMetadataTest.php | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/packages/framework/tests/Unit/AbstractPageMetadataTest.php b/packages/framework/tests/Unit/AbstractPageMetadataTest.php index b46ac74bd3b..cc465a4e3b0 100644 --- a/packages/framework/tests/Unit/AbstractPageMetadataTest.php +++ b/packages/framework/tests/Unit/AbstractPageMetadataTest.php @@ -13,15 +13,10 @@ */ class AbstractPageMetadataTest extends TestCase { - protected function makePage(string $slug = 'foo'): MarkdownPage - { - return new MarkdownPage(identifier: $slug); - } - public function test_get_canonical_url_returns_url_for_top_level_page() { config(['site.url' => 'https://example.com']); - $page = $this->makePage(); + $page = new MarkdownPage('foo'); $this->assertEquals('https://example.com/foo.html', $page->canonicalUrl); } @@ -30,7 +25,7 @@ public function test_get_canonical_url_returns_pretty_url_for_top_level_page() { config(['site.url' => 'https://example.com']); config(['site.pretty_urls' => true]); - $page = $this->makePage(); + $page = new MarkdownPage('foo'); $this->assertEquals('https://example.com/foo', $page->canonicalUrl); } @@ -38,7 +33,7 @@ public function test_get_canonical_url_returns_pretty_url_for_top_level_page() public function test_get_canonical_url_returns_url_for_nested_page() { config(['site.url' => 'https://example.com']); - $page = $this->makePage('foo/bar'); + $page = new MarkdownPage('foo/bar'); $this->assertEquals('https://example.com/foo/bar.html', $page->canonicalUrl); } @@ -46,7 +41,7 @@ public function test_get_canonical_url_returns_url_for_nested_page() public function test_get_canonical_url_returns_url_for_deeply_nested_page() { config(['site.url' => 'https://example.com']); - $page = $this->makePage('foo/bar/baz'); + $page = new MarkdownPage('foo/bar/baz'); $this->assertEquals('https://example.com/foo/bar/baz.html', $page->canonicalUrl); } @@ -65,7 +60,7 @@ public function test_canonical_url_is_not_set_when_identifier_is_null() public function test_canonical_url_is_not_set_when_site_url_is_null() { config(['site.url' => null]); - $page = $this->makePage(); + $page = new MarkdownPage('foo'); $this->assertNull($page->canonicalUrl); $this->assertStringNotContainsString( 'makePage(); + $page = new MarkdownPage('foo'); $this->assertIsString($page->renderPageMetadata()); } @@ -96,7 +91,7 @@ public function test_render_page_metadata_returns_string_with_merged_metadata() config(['hyde.meta' => [ Meta::name('foo', 'bar'), ]]); - $page = $this->makePage(); + $page = new MarkdownPage('foo'); $this->assertStringContainsString( ''."\n". @@ -109,7 +104,7 @@ public function test_render_page_metadata_only_adds_canonical_if_conditions_are_ { config(['site.url' => null]); config(['hyde.meta' => []]); - $page = $this->makePage(); + $page = new MarkdownPage('foo'); $this->assertEquals( '', @@ -121,7 +116,7 @@ public function test_get_dynamic_metadata_only_adds_canonical_if_conditions_are_ { config(['site.url' => null]); config(['hyde.meta' => []]); - $page = $this->makePage(); + $page = new MarkdownPage('foo'); $this->assertEquals( [], @@ -135,7 +130,7 @@ public function test_get_dynamic_metadata_adds_canonical_url_when_conditions_are config(['hyde.meta' => [ Meta::name('foo', 'bar'), ]]); - $page = $this->makePage(); + $page = new MarkdownPage('foo'); $this->assertContains('', $page->getDynamicMetadata() @@ -144,7 +139,7 @@ public function test_get_dynamic_metadata_adds_canonical_url_when_conditions_are public function test_get_dynamic_metadata_adds_sitemap_link_when_conditions_are_met() { - $page = $this->makePage(); + $page = new MarkdownPage('foo'); config(['site.url' => 'https://example.com']); config(['site.generate_sitemap' => true]); @@ -156,7 +151,7 @@ public function test_get_dynamic_metadata_adds_sitemap_link_when_conditions_are_ public function test_get_dynamic_metadata_does_not_add_sitemap_link_when_conditions_are_not_met() { - $page = $this->makePage(); + $page = new MarkdownPage('foo'); config(['site.url' => 'https://example.com']); config(['site.generate_sitemap' => false]); From acfdded6d3680fecdc7717c8774dfe714b402271 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 16:34:35 +0200 Subject: [PATCH 14/33] Remove self-referencing link --- packages/framework/tests/Unit/AbstractPageMetadataTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/framework/tests/Unit/AbstractPageMetadataTest.php b/packages/framework/tests/Unit/AbstractPageMetadataTest.php index cc465a4e3b0..d1f7243a59d 100644 --- a/packages/framework/tests/Unit/AbstractPageMetadataTest.php +++ b/packages/framework/tests/Unit/AbstractPageMetadataTest.php @@ -8,8 +8,6 @@ /** * @covers \Hyde\Framework\Contracts\AbstractPage - * - * @see \Hyde\Framework\Testing\Unit\AbstractPageMetadataTest */ class AbstractPageMetadataTest extends TestCase { From 9babe8f262b7752aaf32ffcf89258469d257c61f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 16:35:59 +0200 Subject: [PATCH 15/33] Merge unit test into main feature test --- .../tests/Feature/AbstractPageTest.php | 209 ++++++++++++++++- .../tests/Unit/AbstractPageMetadataTest.php | 219 ------------------ 2 files changed, 207 insertions(+), 221 deletions(-) delete mode 100644 packages/framework/tests/Unit/AbstractPageMetadataTest.php diff --git a/packages/framework/tests/Feature/AbstractPageTest.php b/packages/framework/tests/Feature/AbstractPageTest.php index ca3f5f93b25..2e2887b4616 100644 --- a/packages/framework/tests/Feature/AbstractPageTest.php +++ b/packages/framework/tests/Feature/AbstractPageTest.php @@ -5,6 +5,7 @@ use Hyde\Framework\Contracts\AbstractMarkdownPage; use Hyde\Framework\Contracts\AbstractPage; use Hyde\Framework\Contracts\PageContract; +use Hyde\Framework\Helpers\Meta; use Hyde\Framework\Hyde; use Hyde\Framework\Models\Markdown; use Hyde\Framework\Models\Pages\BladePage; @@ -25,8 +26,6 @@ * @covers \Hyde\Framework\Contracts\AbstractMarkdownPage * @covers \Hyde\Framework\Actions\Constructors\FindsNavigationDataForPage * @covers \Hyde\Framework\Concerns\FrontMatter\Schemas\PageSchema - * - * @see \Hyde\Framework\Testing\Unit\AbstractPageMetadataTest */ class AbstractPageTest extends TestCase { @@ -512,4 +511,210 @@ public function test_navigation_menu_title_falls_back_to_hyde_make_title_from_sl $page = MarkdownPage::make('foo'); $this->assertEquals('Foo', $page->navigationMenuTitle()); } + + public function test_get_canonical_url_returns_url_for_top_level_page() + { + config(['site.url' => 'https://example.com']); + $page = new MarkdownPage('foo'); + + $this->assertEquals('https://example.com/foo.html', $page->canonicalUrl); + } + + public function test_get_canonical_url_returns_pretty_url_for_top_level_page() + { + config(['site.url' => 'https://example.com']); + config(['site.pretty_urls' => true]); + $page = new MarkdownPage('foo'); + + $this->assertEquals('https://example.com/foo', $page->canonicalUrl); + } + + public function test_get_canonical_url_returns_url_for_nested_page() + { + config(['site.url' => 'https://example.com']); + $page = new MarkdownPage('foo/bar'); + + $this->assertEquals('https://example.com/foo/bar.html', $page->canonicalUrl); + } + + public function test_get_canonical_url_returns_url_for_deeply_nested_page() + { + config(['site.url' => 'https://example.com']); + $page = new MarkdownPage('foo/bar/baz'); + + $this->assertEquals('https://example.com/foo/bar/baz.html', $page->canonicalUrl); + } + + public function test_canonical_url_is_not_set_when_identifier_is_null() + { + config(['site.url' => 'https://example.com']); + $page = new MarkdownPage(); + $this->assertNull($page->canonicalUrl); + $this->assertStringNotContainsString( + 'renderPageMetadata() + ); + } + + public function test_canonical_url_is_not_set_when_site_url_is_null() + { + config(['site.url' => null]); + $page = new MarkdownPage('foo'); + $this->assertNull($page->canonicalUrl); + $this->assertStringNotContainsString( + 'renderPageMetadata() + ); + } + + public function test_custom_canonical_link_can_be_set_in_front_matter() + { + config(['site.url' => 'https://example.com']); + $page = MarkdownPage::make(matter: ['canonicalUrl' => 'foo/bar']); + $this->assertEquals('foo/bar', $page->canonicalUrl); + $this->assertStringContainsString( + '', + $page->renderPageMetadata() + ); + } + + public function test_render_page_metadata_returns_string() + { + $page = new MarkdownPage('foo'); + $this->assertIsString($page->renderPageMetadata()); + } + + public function test_render_page_metadata_returns_string_with_merged_metadata() + { + config(['site.url' => 'https://example.com']); + config(['hyde.meta' => [ + Meta::name('foo', 'bar'), + ]]); + $page = new MarkdownPage('foo'); + + $this->assertStringContainsString( + ''."\n". + '', + $page->renderPageMetadata() + ); + } + + public function test_render_page_metadata_only_adds_canonical_if_conditions_are_met() + { + config(['site.url' => null]); + config(['hyde.meta' => []]); + $page = new MarkdownPage('foo'); + + $this->assertEquals( + '', + $page->renderPageMetadata() + ); + } + + public function test_get_dynamic_metadata_only_adds_canonical_if_conditions_are_met() + { + config(['site.url' => null]); + config(['hyde.meta' => []]); + $page = new MarkdownPage('foo'); + + $this->assertEquals( + [], + $page->getDynamicMetadata() + ); + } + + public function test_get_dynamic_metadata_adds_canonical_url_when_conditions_are_met() + { + config(['site.url' => 'https://example.com']); + config(['hyde.meta' => [ + Meta::name('foo', 'bar'), + ]]); + $page = new MarkdownPage('foo'); + + $this->assertContains('', + $page->getDynamicMetadata() + ); + } + + public function test_get_dynamic_metadata_adds_sitemap_link_when_conditions_are_met() + { + $page = new MarkdownPage('foo'); + + config(['site.url' => 'https://example.com']); + config(['site.generate_sitemap' => true]); + + $this->assertContains('', + $page->getDynamicMetadata() + ); + } + + public function test_get_dynamic_metadata_does_not_add_sitemap_link_when_conditions_are_not_met() + { + $page = new MarkdownPage('foo'); + + config(['site.url' => 'https://example.com']); + config(['site.generate_sitemap' => false]); + + $this->assertNotContains('', + $page->getDynamicMetadata() + ); + } + + public function test_has_twitter_title_in_config_returns_true_when_present_in_config() + { + config(['hyde.meta' => [ + Meta::name('twitter:title', 'foo'), + ]]); + + $page = new MarkdownPage(); + + $this->assertTrue($page->hasTwitterTitleInConfig()); + } + + public function test_has_twitter_title_in_config_returns_false_when_not_present_in_config() + { + config(['hyde.meta' => []]); + + $page = new MarkdownPage(); + + $this->assertFalse($page->hasTwitterTitleInConfig()); + } + + public function test_has_open_graph_title_in_config_returns_true_when_present_in_config() + { + config(['hyde.meta' => [ + Meta::property('title', 'foo'), + ]]); + + $page = new MarkdownPage(); + + $this->assertTrue($page->hasOpenGraphTitleInConfig()); + } + + public function test_has_open_graph_title_in_config_returns_false_when_not_present_in_config() + { + config(['hyde.meta' => []]); + + $page = new MarkdownPage(); + + $this->assertFalse($page->hasOpenGraphTitleInConfig()); + } + + public function test_get_dynamic_metadata_adds_twitter_and_open_graph_title_when_conditions_are_met() + { + config(['site.url' => null]); + config(['hyde.meta' => [ + Meta::name('twitter:title', 'foo'), + Meta::property('title', 'foo'), + ]]); + + $page = MarkdownPage::make(matter: ['title' => 'Foo Bar']); + + $this->assertEquals([ + '', + '', + ], + $page->getDynamicMetadata() + ); + } } diff --git a/packages/framework/tests/Unit/AbstractPageMetadataTest.php b/packages/framework/tests/Unit/AbstractPageMetadataTest.php deleted file mode 100644 index d1f7243a59d..00000000000 --- a/packages/framework/tests/Unit/AbstractPageMetadataTest.php +++ /dev/null @@ -1,219 +0,0 @@ - 'https://example.com']); - $page = new MarkdownPage('foo'); - - $this->assertEquals('https://example.com/foo.html', $page->canonicalUrl); - } - - public function test_get_canonical_url_returns_pretty_url_for_top_level_page() - { - config(['site.url' => 'https://example.com']); - config(['site.pretty_urls' => true]); - $page = new MarkdownPage('foo'); - - $this->assertEquals('https://example.com/foo', $page->canonicalUrl); - } - - public function test_get_canonical_url_returns_url_for_nested_page() - { - config(['site.url' => 'https://example.com']); - $page = new MarkdownPage('foo/bar'); - - $this->assertEquals('https://example.com/foo/bar.html', $page->canonicalUrl); - } - - public function test_get_canonical_url_returns_url_for_deeply_nested_page() - { - config(['site.url' => 'https://example.com']); - $page = new MarkdownPage('foo/bar/baz'); - - $this->assertEquals('https://example.com/foo/bar/baz.html', $page->canonicalUrl); - } - - public function test_canonical_url_is_not_set_when_identifier_is_null() - { - config(['site.url' => 'https://example.com']); - $page = new MarkdownPage(); - $this->assertNull($page->canonicalUrl); - $this->assertStringNotContainsString( - 'renderPageMetadata() - ); - } - - public function test_canonical_url_is_not_set_when_site_url_is_null() - { - config(['site.url' => null]); - $page = new MarkdownPage('foo'); - $this->assertNull($page->canonicalUrl); - $this->assertStringNotContainsString( - 'renderPageMetadata() - ); - } - - public function test_custom_canonical_link_can_be_set_in_front_matter() - { - config(['site.url' => 'https://example.com']); - $page = MarkdownPage::make(matter: ['canonicalUrl' => 'foo/bar']); - $this->assertEquals('foo/bar', $page->canonicalUrl); - $this->assertStringContainsString( - '', - $page->renderPageMetadata() - ); - } - - public function test_render_page_metadata_returns_string() - { - $page = new MarkdownPage('foo'); - $this->assertIsString($page->renderPageMetadata()); - } - - public function test_render_page_metadata_returns_string_with_merged_metadata() - { - config(['site.url' => 'https://example.com']); - config(['hyde.meta' => [ - Meta::name('foo', 'bar'), - ]]); - $page = new MarkdownPage('foo'); - - $this->assertStringContainsString( - ''."\n". - '', - $page->renderPageMetadata() - ); - } - - public function test_render_page_metadata_only_adds_canonical_if_conditions_are_met() - { - config(['site.url' => null]); - config(['hyde.meta' => []]); - $page = new MarkdownPage('foo'); - - $this->assertEquals( - '', - $page->renderPageMetadata() - ); - } - - public function test_get_dynamic_metadata_only_adds_canonical_if_conditions_are_met() - { - config(['site.url' => null]); - config(['hyde.meta' => []]); - $page = new MarkdownPage('foo'); - - $this->assertEquals( - [], - $page->getDynamicMetadata() - ); - } - - public function test_get_dynamic_metadata_adds_canonical_url_when_conditions_are_met() - { - config(['site.url' => 'https://example.com']); - config(['hyde.meta' => [ - Meta::name('foo', 'bar'), - ]]); - $page = new MarkdownPage('foo'); - - $this->assertContains('', - $page->getDynamicMetadata() - ); - } - - public function test_get_dynamic_metadata_adds_sitemap_link_when_conditions_are_met() - { - $page = new MarkdownPage('foo'); - - config(['site.url' => 'https://example.com']); - config(['site.generate_sitemap' => true]); - - $this->assertContains('', - $page->getDynamicMetadata() - ); - } - - public function test_get_dynamic_metadata_does_not_add_sitemap_link_when_conditions_are_not_met() - { - $page = new MarkdownPage('foo'); - - config(['site.url' => 'https://example.com']); - config(['site.generate_sitemap' => false]); - - $this->assertNotContains('', - $page->getDynamicMetadata() - ); - } - - public function test_has_twitter_title_in_config_returns_true_when_present_in_config() - { - config(['hyde.meta' => [ - Meta::name('twitter:title', 'foo'), - ]]); - - $page = new MarkdownPage(); - - $this->assertTrue($page->hasTwitterTitleInConfig()); - } - - public function test_has_twitter_title_in_config_returns_false_when_not_present_in_config() - { - config(['hyde.meta' => []]); - - $page = new MarkdownPage(); - - $this->assertFalse($page->hasTwitterTitleInConfig()); - } - - public function test_has_open_graph_title_in_config_returns_true_when_present_in_config() - { - config(['hyde.meta' => [ - Meta::property('title', 'foo'), - ]]); - - $page = new MarkdownPage(); - - $this->assertTrue($page->hasOpenGraphTitleInConfig()); - } - - public function test_has_open_graph_title_in_config_returns_false_when_not_present_in_config() - { - config(['hyde.meta' => []]); - - $page = new MarkdownPage(); - - $this->assertFalse($page->hasOpenGraphTitleInConfig()); - } - - public function test_get_dynamic_metadata_adds_twitter_and_open_graph_title_when_conditions_are_met() - { - config(['site.url' => null]); - config(['hyde.meta' => [ - Meta::name('twitter:title', 'foo'), - Meta::property('title', 'foo'), - ]]); - - $page = MarkdownPage::make(matter: ['title' => 'Foo Bar']); - - $this->assertEquals([ - '', - '', - ], - $page->getDynamicMetadata() - ); - } -} From 93f0d0c4c3880b53076568e532c690709f21985a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 16:46:13 +0200 Subject: [PATCH 16/33] Use more granular tests --- packages/framework/tests/Feature/AbstractPageTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/framework/tests/Feature/AbstractPageTest.php b/packages/framework/tests/Feature/AbstractPageTest.php index 2e2887b4616..1176f96afa2 100644 --- a/packages/framework/tests/Feature/AbstractPageTest.php +++ b/packages/framework/tests/Feature/AbstractPageTest.php @@ -605,8 +605,8 @@ public function test_render_page_metadata_only_adds_canonical_if_conditions_are_ config(['hyde.meta' => []]); $page = new MarkdownPage('foo'); - $this->assertEquals( - '', + $this->assertStringNotContainsString( + 'renderPageMetadata() ); } @@ -617,9 +617,9 @@ public function test_get_dynamic_metadata_only_adds_canonical_if_conditions_are_ config(['hyde.meta' => []]); $page = new MarkdownPage('foo'); - $this->assertEquals( - [], - $page->getDynamicMetadata() + $this->assertStringNotContainsString( + 'getDynamicMetadata()) ); } From a117ff4bca9b1157aefd6b7a55989838d631a72d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 16:49:53 +0200 Subject: [PATCH 17/33] Always add title metadata when a title is set --- .../framework/src/Contracts/AbstractPage.php | 20 ++----- .../tests/Feature/AbstractPageTest.php | 53 +++++-------------- 2 files changed, 15 insertions(+), 58 deletions(-) diff --git a/packages/framework/src/Contracts/AbstractPage.php b/packages/framework/src/Contracts/AbstractPage.php index 9fa84c1b912..21d68e4f82d 100644 --- a/packages/framework/src/Contracts/AbstractPage.php +++ b/packages/framework/src/Contracts/AbstractPage.php @@ -184,13 +184,9 @@ public function getDynamicMetadata(): array $array[] = $this->makeRssFeedLink(); } - if (isset($this->title)) { - if ($this->hasTwitterTitleInConfig()) { - $array[] = ''; - } - if ($this->hasOpenGraphTitleInConfig()) { - $array[] = ''; - } + if (! empty($this->title)) { + $array[] = ''; + $array[] = ''; } if ($this instanceof MarkdownPost) { @@ -213,16 +209,6 @@ public function renderPageMetadata(): string ); } - public function hasTwitterTitleInConfig(): bool - { - return str_contains(json_encode(config('hyde.meta', [])), 'twitter:title'); - } - - public function hasOpenGraphTitleInConfig(): bool - { - return str_contains(json_encode(config('hyde.meta', [])), 'og:title'); - } - protected function makeRssFeedLink(): string { return '', + '', + ], + $page->getDynamicMetadata() + ); } - public function test_get_dynamic_metadata_adds_twitter_and_open_graph_title_when_conditions_are_met() + public function test_get_dynamic_metadata_does_not_add_twitter_and_open_graph_title_when_no_title_is_set() { config(['site.url' => null]); config(['hyde.meta' => [ @@ -708,12 +682,9 @@ public function test_get_dynamic_metadata_adds_twitter_and_open_graph_title_when Meta::property('title', 'foo'), ]]); - $page = MarkdownPage::make(matter: ['title' => 'Foo Bar']); + $page = MarkdownPage::make(matter: ['title' => null]); - $this->assertEquals([ - '', - '', - ], + $this->assertEquals([], $page->getDynamicMetadata() ); } From 4be50cc064e45d512b79101eb1e6270b5428c320 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 16:54:38 +0200 Subject: [PATCH 18/33] Use the Meta facade --- packages/framework/src/Contracts/AbstractPage.php | 4 ++-- packages/framework/tests/Feature/AbstractPageTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/framework/src/Contracts/AbstractPage.php b/packages/framework/src/Contracts/AbstractPage.php index 21d68e4f82d..fd314ecd8bf 100644 --- a/packages/framework/src/Contracts/AbstractPage.php +++ b/packages/framework/src/Contracts/AbstractPage.php @@ -185,8 +185,8 @@ public function getDynamicMetadata(): array } if (! empty($this->title)) { - $array[] = ''; - $array[] = ''; + $array[] = Meta::name('twitter:title', $this->htmlTitle()); + $array[] = Meta::property('title', $this->htmlTitle()); } if ($this instanceof MarkdownPost) { diff --git a/packages/framework/tests/Feature/AbstractPageTest.php b/packages/framework/tests/Feature/AbstractPageTest.php index 0a7268fb201..6835f9735e9 100644 --- a/packages/framework/tests/Feature/AbstractPageTest.php +++ b/packages/framework/tests/Feature/AbstractPageTest.php @@ -667,8 +667,8 @@ public function test_get_dynamic_metadata_adds_twitter_and_open_graph_title_when $page = MarkdownPage::make(matter: ['title' => 'Foo Bar']); $this->assertEquals([ - '', - '', + '', + '', ], $page->getDynamicMetadata() ); From 09571363391b840c9bab5229c4bd5f723037ed9b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 16:54:50 +0200 Subject: [PATCH 19/33] Escape output to ensure tags are valid --- packages/framework/src/Contracts/AbstractPage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Contracts/AbstractPage.php b/packages/framework/src/Contracts/AbstractPage.php index fd314ecd8bf..3d5063baa31 100644 --- a/packages/framework/src/Contracts/AbstractPage.php +++ b/packages/framework/src/Contracts/AbstractPage.php @@ -173,11 +173,11 @@ public function getDynamicMetadata(): array $array = []; if ($this->canonicalUrl) { - $array[] = ''; + $array[] = ''; } if (Features::sitemap()) { - $array[] = ''; + $array[] = ''; } if (Features::rss()) { From b45aef5f96949e5a92b6a071f0b49388facfd386 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 16:58:08 +0200 Subject: [PATCH 20/33] Remove trailing slash from meta tags --- packages/framework/tests/Feature/AbstractPageTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/framework/tests/Feature/AbstractPageTest.php b/packages/framework/tests/Feature/AbstractPageTest.php index 6835f9735e9..a7ce36da135 100644 --- a/packages/framework/tests/Feature/AbstractPageTest.php +++ b/packages/framework/tests/Feature/AbstractPageTest.php @@ -573,7 +573,7 @@ public function test_custom_canonical_link_can_be_set_in_front_matter() $page = MarkdownPage::make(matter: ['canonicalUrl' => 'foo/bar']); $this->assertEquals('foo/bar', $page->canonicalUrl); $this->assertStringContainsString( - '', + '', $page->renderPageMetadata() ); } @@ -594,7 +594,7 @@ public function test_render_page_metadata_returns_string_with_merged_metadata() $this->assertStringContainsString( ''."\n". - '', + '', $page->renderPageMetadata() ); } @@ -631,7 +631,7 @@ public function test_get_dynamic_metadata_adds_canonical_url_when_conditions_are ]]); $page = new MarkdownPage('foo'); - $this->assertContains('', + $this->assertContains('', $page->getDynamicMetadata() ); } @@ -643,7 +643,7 @@ public function test_get_dynamic_metadata_adds_sitemap_link_when_conditions_are_ config(['site.url' => 'https://example.com']); config(['site.generate_sitemap' => true]); - $this->assertContains('', + $this->assertContains('', $page->getDynamicMetadata() ); } @@ -655,7 +655,7 @@ public function test_get_dynamic_metadata_does_not_add_sitemap_link_when_conditi config(['site.url' => 'https://example.com']); config(['site.generate_sitemap' => false]); - $this->assertNotContains('', + $this->assertNotContains('', $page->getDynamicMetadata() ); } From 40ab6c7dd75b4b20f976d4bcc25695c11e5a0427 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 17:06:27 +0200 Subject: [PATCH 21/33] Normalize expected attribute order --- packages/framework/tests/Feature/AbstractPageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/AbstractPageTest.php b/packages/framework/tests/Feature/AbstractPageTest.php index a7ce36da135..8924c11d084 100644 --- a/packages/framework/tests/Feature/AbstractPageTest.php +++ b/packages/framework/tests/Feature/AbstractPageTest.php @@ -643,7 +643,7 @@ public function test_get_dynamic_metadata_adds_sitemap_link_when_conditions_are_ config(['site.url' => 'https://example.com']); config(['site.generate_sitemap' => true]); - $this->assertContains('', + $this->assertContains('', $page->getDynamicMetadata() ); } From a649e246e1321ea3f8b2f674f6068d9bc3e47da3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 17:06:53 +0200 Subject: [PATCH 22/33] Merge unit tests into feature test --- .../tests/Feature/AbstractPageTest.php | 59 ++++++++++++++ .../AbstractPageMetadataRssFeedLinkTest.php | 76 ------------------- 2 files changed, 59 insertions(+), 76 deletions(-) delete mode 100644 packages/framework/tests/Unit/AbstractPageMetadataRssFeedLinkTest.php diff --git a/packages/framework/tests/Feature/AbstractPageTest.php b/packages/framework/tests/Feature/AbstractPageTest.php index 8924c11d084..1f8402e162a 100644 --- a/packages/framework/tests/Feature/AbstractPageTest.php +++ b/packages/framework/tests/Feature/AbstractPageTest.php @@ -688,4 +688,63 @@ public function test_get_dynamic_metadata_does_not_add_twitter_and_open_graph_ti $page->getDynamicMetadata() ); } + + protected function assertPageHasFeedLink($page) + { + $this->assertStringContainsString( + '', + $page->renderPageMetadata() + ); + } + + public function test_can_use_rss_feed_link_adds_meta_link_for_markdown_posts() + { + config(['site.url' => 'foo']); + $this->assertPageHasFeedLink(new MarkdownPost()); + } + + public function test_can_use_rss_feed_link_adds_meta_link_for_all_pages() + { + config(['site.url' => 'foo']); + $this->assertPageHasFeedLink(new BladePage('')); + $this->assertPageHasFeedLink(new MarkdownPage()); + $this->assertPageHasFeedLink(new MarkdownPost()); + $this->assertPageHasFeedLink(new DocumentationPage()); + } + + public function test_can_use_rss_feed_uses_configured_site_url() + { + config(['site.url' => 'foo']); + config(['site.url' => 'foo']); + $page = new MarkdownPost(); + + $this->assertStringContainsString( + '', + $page->renderPageMetadata() + ); + } + + public function test_can_use_rss_feed_uses_configured_rss_file_name() + { + config(['site.url' => 'foo']); + config(['hyde.rss_filename' => 'posts.rss']); + $page = new MarkdownPost(); + + $this->assertStringContainsString( + '', + $page->renderPageMetadata() + ); + } + + public function test_link_is_not_added_if_site_url_is_not_set() + { + config(['site.url' => 'foo']); + config(['site.url' => '']); + $page = new MarkdownPost(); + + $this->assertStringNotContainsString( + 'renderPageMetadata() + ); + } } diff --git a/packages/framework/tests/Unit/AbstractPageMetadataRssFeedLinkTest.php b/packages/framework/tests/Unit/AbstractPageMetadataRssFeedLinkTest.php deleted file mode 100644 index 1a7c12d3584..00000000000 --- a/packages/framework/tests/Unit/AbstractPageMetadataRssFeedLinkTest.php +++ /dev/null @@ -1,76 +0,0 @@ - 'foo']); - } - - protected function assertPageHasFeedLink($page) - { - $this->assertStringContainsString( - '', - $page->renderPageMetadata() - ); - } - - public function test_can_use_rss_feed_link_adds_meta_link_for_markdown_posts() - { - $this->assertPageHasFeedLink(new MarkdownPost()); - } - - public function test_can_use_rss_feed_link_adds_meta_link_for_all_pages() - { - $this->assertPageHasFeedLink(new BladePage('')); - $this->assertPageHasFeedLink(new MarkdownPage()); - $this->assertPageHasFeedLink(new MarkdownPost()); - $this->assertPageHasFeedLink(new DocumentationPage()); - } - - public function test_can_use_rss_feed_uses_configured_site_url() - { - config(['site.url' => 'foo']); - $page = new MarkdownPost(); - - $this->assertStringContainsString( - '', - $page->renderPageMetadata() - ); - } - - public function test_can_use_rss_feed_uses_configured_rss_file_name() - { - config(['hyde.rss_filename' => 'posts.rss']); - $page = new MarkdownPost(); - - $this->assertStringContainsString( - '', - $page->renderPageMetadata() - ); - } - - public function test_link_is_not_added_if_site_url_is_not_set() - { - config(['site.url' => '']); - $page = new MarkdownPost(); - - $this->assertStringNotContainsString( - 'renderPageMetadata() - ); - } -} From d1c7f0c7be38deecbd904da32309c316c2212eb1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 17:08:08 +0200 Subject: [PATCH 23/33] Normalize expected link format --- packages/framework/tests/Feature/AbstractPageTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/framework/tests/Feature/AbstractPageTest.php b/packages/framework/tests/Feature/AbstractPageTest.php index 1f8402e162a..863b04a5a08 100644 --- a/packages/framework/tests/Feature/AbstractPageTest.php +++ b/packages/framework/tests/Feature/AbstractPageTest.php @@ -692,7 +692,7 @@ public function test_get_dynamic_metadata_does_not_add_twitter_and_open_graph_ti protected function assertPageHasFeedLink($page) { $this->assertStringContainsString( - '', + '', $page->renderPageMetadata() ); } @@ -719,7 +719,7 @@ public function test_can_use_rss_feed_uses_configured_site_url() $page = new MarkdownPost(); $this->assertStringContainsString( - '', + '', $page->renderPageMetadata() ); } @@ -731,7 +731,7 @@ public function test_can_use_rss_feed_uses_configured_rss_file_name() $page = new MarkdownPost(); $this->assertStringContainsString( - '', + '', $page->renderPageMetadata() ); } From 525fd2205c5af0f1ba8e8fa713f1e82bdba3b543 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 17:17:41 +0200 Subject: [PATCH 24/33] Create new Meta::link() helper --- RELEASE_NOTES.md | 1 + packages/framework/src/Helpers/Meta.php | 13 ++++++++++ .../tests/Feature/MetadataHelperTest.php | 24 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index df757e050ab..b3d343051a0 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -10,6 +10,7 @@ The update makes large changes to how dynamic data is constructed. Instead of ge - Added `compile()` method to `Facades\Markdown`, replacing the `parse()` method of the same class - Adds new actions to handle complex dynamic constructors - Adds new front matter schema traits to define the public API for front matter and hold their data +- Adds new Meta::link() helper to create `` tags ### Changed - Breaking: Rename AbstractMarkdownPage constructor parameter `slug` to `identifier` diff --git a/packages/framework/src/Helpers/Meta.php b/packages/framework/src/Helpers/Meta.php index 6a391857f31..4f6d42fd946 100644 --- a/packages/framework/src/Helpers/Meta.php +++ b/packages/framework/src/Helpers/Meta.php @@ -21,6 +21,19 @@ public static function property(string $property, string $content): string return ''; } + public static function link(string $rel, string $href, array $attr = []): string + { + if (! $attr) { + return ''; + } + + $attributes = collect($attr)->map(function ($value, $key) { + return e($key).'="'.e($value).'"'; + })->implode(' '); + + return ''; + } + public static function render(array $withMergedData = []): string { return implode( diff --git a/packages/framework/tests/Feature/MetadataHelperTest.php b/packages/framework/tests/Feature/MetadataHelperTest.php index f7f87feb650..de06994f3e7 100644 --- a/packages/framework/tests/Feature/MetadataHelperTest.php +++ b/packages/framework/tests/Feature/MetadataHelperTest.php @@ -49,6 +49,30 @@ public function test_property_method_accepts_property_without_og_prefix() ); } + public function test_link_method_returns_a_valid_html_link_string() + { + $this->assertEquals( + '', + Meta::link('foo', 'bar') + ); + } + + public function test_link_method_returns_a_valid_html_link_string_with_attributes() + { + $this->assertEquals( + '', + Meta::link('foo', 'bar', ['title' => 'baz']) + ); + } + + public function test_link_method_returns_a_valid_html_link_string_with_multiple_attributes() + { + $this->assertEquals( + '', + Meta::link('foo', 'bar', ['title' => 'baz', 'type' => 'text/css']) + ); + } + public function test_render_method_implodes_an_array_of_meta_tags_into_a_formatted_string() { $this->assertEquals( From 5481f3ef7521adcb1c883713ca10d85405d8ff6b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 17:17:51 +0200 Subject: [PATCH 25/33] Use the new Meta::link helper --- .../framework/src/Contracts/AbstractPage.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/framework/src/Contracts/AbstractPage.php b/packages/framework/src/Contracts/AbstractPage.php index 3d5063baa31..c4592dd7bc9 100644 --- a/packages/framework/src/Contracts/AbstractPage.php +++ b/packages/framework/src/Contracts/AbstractPage.php @@ -173,15 +173,19 @@ public function getDynamicMetadata(): array $array = []; if ($this->canonicalUrl) { - $array[] = ''; + $array[] = Meta::link('canonical', $this->canonicalUrl); } if (Features::sitemap()) { - $array[] = ''; + $array[] = Meta::link('sitemap', Hyde::url('sitemap.xml'), [ + 'type' => 'application/xml', 'title' => 'Sitemap' + ]); } if (Features::rss()) { - $array[] = $this->makeRssFeedLink(); + $array[] = Meta::link('alternate', Hyde::url(RssFeedService::getDefaultOutputFilename()), [ + 'type' => 'application/rss+xml', 'title' => RssFeedService::getDescription() + ]); } if (! empty($this->title)) { @@ -209,12 +213,6 @@ public function renderPageMetadata(): string ); } - protected function makeRssFeedLink(): string - { - return ''; - } - public function showInNavigation(): bool { return ! $this->navigation['hidden']; From 81d80f932faa4f3f7fb5be2ae5f4c2a1a599b35f Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 7 Aug 2022 15:18:08 +0000 Subject: [PATCH 26/33] Apply fixes from StyleCI --- packages/framework/src/Contracts/AbstractPage.php | 4 ++-- packages/framework/src/Helpers/Meta.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Contracts/AbstractPage.php b/packages/framework/src/Contracts/AbstractPage.php index c4592dd7bc9..004da6616f2 100644 --- a/packages/framework/src/Contracts/AbstractPage.php +++ b/packages/framework/src/Contracts/AbstractPage.php @@ -178,13 +178,13 @@ public function getDynamicMetadata(): array if (Features::sitemap()) { $array[] = Meta::link('sitemap', Hyde::url('sitemap.xml'), [ - 'type' => 'application/xml', 'title' => 'Sitemap' + 'type' => 'application/xml', 'title' => 'Sitemap', ]); } if (Features::rss()) { $array[] = Meta::link('alternate', Hyde::url(RssFeedService::getDefaultOutputFilename()), [ - 'type' => 'application/rss+xml', 'title' => RssFeedService::getDescription() + 'type' => 'application/rss+xml', 'title' => RssFeedService::getDescription(), ]); } diff --git a/packages/framework/src/Helpers/Meta.php b/packages/framework/src/Helpers/Meta.php index 4f6d42fd946..94ee03346a0 100644 --- a/packages/framework/src/Helpers/Meta.php +++ b/packages/framework/src/Helpers/Meta.php @@ -31,7 +31,7 @@ public static function link(string $rel, string $href, array $attr = []): string return e($key).'="'.e($value).'"'; })->implode(' '); - return ''; + return ''; } public static function render(array $withMergedData = []): string From c93a9adcc31b67a6b53bed057d8c52eba0e447a3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 17:37:48 +0200 Subject: [PATCH 27/33] Check if not empty --- packages/framework/src/Contracts/AbstractPage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Contracts/AbstractPage.php b/packages/framework/src/Contracts/AbstractPage.php index 004da6616f2..705b8f6d10b 100644 --- a/packages/framework/src/Contracts/AbstractPage.php +++ b/packages/framework/src/Contracts/AbstractPage.php @@ -172,7 +172,7 @@ public function getDynamicMetadata(): array { $array = []; - if ($this->canonicalUrl) { + if (! empty($this->canonicalUrl)) { $array[] = Meta::link('canonical', $this->canonicalUrl); } From 87ee16e2d9d2cb23b5a8ea4b33daf81780d9d9a7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 17:38:30 +0200 Subject: [PATCH 28/33] Move up assignment to group similar ones --- packages/framework/src/Contracts/AbstractPage.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/framework/src/Contracts/AbstractPage.php b/packages/framework/src/Contracts/AbstractPage.php index 705b8f6d10b..c0995ead73f 100644 --- a/packages/framework/src/Contracts/AbstractPage.php +++ b/packages/framework/src/Contracts/AbstractPage.php @@ -176,6 +176,11 @@ public function getDynamicMetadata(): array $array[] = Meta::link('canonical', $this->canonicalUrl); } + if (! empty($this->title)) { + $array[] = Meta::name('twitter:title', $this->htmlTitle()); + $array[] = Meta::property('title', $this->htmlTitle()); + } + if (Features::sitemap()) { $array[] = Meta::link('sitemap', Hyde::url('sitemap.xml'), [ 'type' => 'application/xml', 'title' => 'Sitemap', @@ -188,11 +193,6 @@ public function getDynamicMetadata(): array ]); } - if (! empty($this->title)) { - $array[] = Meta::name('twitter:title', $this->htmlTitle()); - $array[] = Meta::property('title', $this->htmlTitle()); - } - if ($this instanceof MarkdownPost) { $array[] = "\n"; foreach ($this->getMetadata() as $name => $content) { From 8e9bf6b974b74bc765c225fa46ed768182bdc608 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 17:49:32 +0200 Subject: [PATCH 29/33] Mark method as internal --- packages/framework/src/Contracts/AbstractPage.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/src/Contracts/AbstractPage.php b/packages/framework/src/Contracts/AbstractPage.php index c0995ead73f..f63aab5e6c2 100644 --- a/packages/framework/src/Contracts/AbstractPage.php +++ b/packages/framework/src/Contracts/AbstractPage.php @@ -164,6 +164,7 @@ public function getBladeView(): string abstract public function compile(): string; /** + * @internal * @return string[] * * @psalm-return list From 3b759328e14d2ba7c34818ead9724cf5ed3d8ba8 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 7 Aug 2022 15:49:43 +0000 Subject: [PATCH 30/33] Apply fixes from StyleCI --- packages/framework/src/Contracts/AbstractPage.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/src/Contracts/AbstractPage.php b/packages/framework/src/Contracts/AbstractPage.php index f63aab5e6c2..ea2e94c37b5 100644 --- a/packages/framework/src/Contracts/AbstractPage.php +++ b/packages/framework/src/Contracts/AbstractPage.php @@ -165,6 +165,7 @@ abstract public function compile(): string; /** * @internal + * * @return string[] * * @psalm-return list From e40e157efa8e8c68a539c34343e893a4b819ce2d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 17:49:55 +0200 Subject: [PATCH 31/33] Move global page metadata to Meta class --- .../framework/src/Contracts/AbstractPage.php | 12 --- packages/framework/src/Helpers/Meta.php | 30 +++++++ .../tests/Feature/AbstractPageTest.php | 82 ----------------- .../tests/Feature/MetadataHelperTest.php | 88 +++++++++++++++++++ 4 files changed, 118 insertions(+), 94 deletions(-) diff --git a/packages/framework/src/Contracts/AbstractPage.php b/packages/framework/src/Contracts/AbstractPage.php index f63aab5e6c2..4ddecf251aa 100644 --- a/packages/framework/src/Contracts/AbstractPage.php +++ b/packages/framework/src/Contracts/AbstractPage.php @@ -182,18 +182,6 @@ public function getDynamicMetadata(): array $array[] = Meta::property('title', $this->htmlTitle()); } - if (Features::sitemap()) { - $array[] = Meta::link('sitemap', Hyde::url('sitemap.xml'), [ - 'type' => 'application/xml', 'title' => 'Sitemap', - ]); - } - - if (Features::rss()) { - $array[] = Meta::link('alternate', Hyde::url(RssFeedService::getDefaultOutputFilename()), [ - 'type' => 'application/rss+xml', 'title' => RssFeedService::getDescription(), - ]); - } - if ($this instanceof MarkdownPost) { $array[] = "\n"; foreach ($this->getMetadata() as $name => $content) { diff --git a/packages/framework/src/Helpers/Meta.php b/packages/framework/src/Helpers/Meta.php index 94ee03346a0..8717aac951f 100644 --- a/packages/framework/src/Helpers/Meta.php +++ b/packages/framework/src/Helpers/Meta.php @@ -2,6 +2,9 @@ namespace Hyde\Framework\Helpers; +use Hyde\Framework\Hyde; +use Hyde\Framework\Services\RssFeedService; + /** * Helpers to fluently declare HTML meta tags. * @@ -65,6 +68,33 @@ protected static function filterUnique(array $meta): array } public static function getGlobalMeta(): array + { + return array_merge( + static::getDynamicMeta(), + static::getConfiguredMeta() + ); + } + + protected static function getDynamicMeta(): array + { + $array = []; + + if (Features::sitemap()) { + $array[] = Meta::link('sitemap', Hyde::url('sitemap.xml'), [ + 'type' => 'application/xml', 'title' => 'Sitemap', + ]); + } + + if (Features::rss()) { + $array[] = Meta::link('alternate', Hyde::url(RssFeedService::getDefaultOutputFilename()), [ + 'type' => 'application/rss+xml', 'title' => RssFeedService::getDescription(), + ]); + } + + return $array; + } + + protected static function getConfiguredMeta(): array { return config('hyde.meta', []); } diff --git a/packages/framework/tests/Feature/AbstractPageTest.php b/packages/framework/tests/Feature/AbstractPageTest.php index 863b04a5a08..ef6da28874a 100644 --- a/packages/framework/tests/Feature/AbstractPageTest.php +++ b/packages/framework/tests/Feature/AbstractPageTest.php @@ -636,30 +636,6 @@ public function test_get_dynamic_metadata_adds_canonical_url_when_conditions_are ); } - public function test_get_dynamic_metadata_adds_sitemap_link_when_conditions_are_met() - { - $page = new MarkdownPage('foo'); - - config(['site.url' => 'https://example.com']); - config(['site.generate_sitemap' => true]); - - $this->assertContains('', - $page->getDynamicMetadata() - ); - } - - public function test_get_dynamic_metadata_does_not_add_sitemap_link_when_conditions_are_not_met() - { - $page = new MarkdownPage('foo'); - - config(['site.url' => 'https://example.com']); - config(['site.generate_sitemap' => false]); - - $this->assertNotContains('', - $page->getDynamicMetadata() - ); - } - public function test_get_dynamic_metadata_adds_twitter_and_open_graph_title_when_title_is_set() { config(['site.url' => null]); @@ -689,62 +665,4 @@ public function test_get_dynamic_metadata_does_not_add_twitter_and_open_graph_ti ); } - protected function assertPageHasFeedLink($page) - { - $this->assertStringContainsString( - '', - $page->renderPageMetadata() - ); - } - - public function test_can_use_rss_feed_link_adds_meta_link_for_markdown_posts() - { - config(['site.url' => 'foo']); - $this->assertPageHasFeedLink(new MarkdownPost()); - } - - public function test_can_use_rss_feed_link_adds_meta_link_for_all_pages() - { - config(['site.url' => 'foo']); - $this->assertPageHasFeedLink(new BladePage('')); - $this->assertPageHasFeedLink(new MarkdownPage()); - $this->assertPageHasFeedLink(new MarkdownPost()); - $this->assertPageHasFeedLink(new DocumentationPage()); - } - - public function test_can_use_rss_feed_uses_configured_site_url() - { - config(['site.url' => 'foo']); - config(['site.url' => 'foo']); - $page = new MarkdownPost(); - - $this->assertStringContainsString( - '', - $page->renderPageMetadata() - ); - } - - public function test_can_use_rss_feed_uses_configured_rss_file_name() - { - config(['site.url' => 'foo']); - config(['hyde.rss_filename' => 'posts.rss']); - $page = new MarkdownPost(); - - $this->assertStringContainsString( - '', - $page->renderPageMetadata() - ); - } - - public function test_link_is_not_added_if_site_url_is_not_set() - { - config(['site.url' => 'foo']); - config(['site.url' => '']); - $page = new MarkdownPost(); - - $this->assertStringNotContainsString( - 'renderPageMetadata() - ); - } } diff --git a/packages/framework/tests/Feature/MetadataHelperTest.php b/packages/framework/tests/Feature/MetadataHelperTest.php index de06994f3e7..1ce2ec66aa0 100644 --- a/packages/framework/tests/Feature/MetadataHelperTest.php +++ b/packages/framework/tests/Feature/MetadataHelperTest.php @@ -3,6 +3,10 @@ namespace Hyde\Framework\Testing\Feature; use Hyde\Framework\Helpers\Meta; +use Hyde\Framework\Models\Pages\BladePage; +use Hyde\Framework\Models\Pages\DocumentationPage; +use Hyde\Framework\Models\Pages\MarkdownPage; +use Hyde\Framework\Models\Pages\MarkdownPost; use Hyde\Testing\TestCase; /** @@ -15,6 +19,7 @@ protected function setUp(): void parent::setUp(); config(['hyde.meta' => []]); + config(['site.url' => null]); } public function test_name_method_returns_a_valid_html_meta_string() @@ -153,4 +158,87 @@ public function test_render_method_gives_precedence_to_supplied_meta_tags() ]) ); } + + + public function test_get_dynamic_metadata_adds_sitemap_link_when_conditions_are_met() + { + config(['site.url' => 'https://example.com']); + config(['site.generate_sitemap' => true]); + $page = new MarkdownPage('foo'); + + $this->assertStringContainsString('', + $page->renderPageMetadata() + ); + } + + public function test_get_dynamic_metadata_does_not_add_sitemap_link_when_conditions_are_not_met() + { + $page = new MarkdownPage('foo'); + + config(['site.url' => 'https://example.com']); + config(['site.generate_sitemap' => false]); + + $this->assertStringNotContainsString('', + $page->renderPageMetadata() + ); + } + + protected function assertPageHasFeedLink($page) + { + $this->assertStringContainsString( + '', + $page->renderPageMetadata() + ); + } + + public function test_can_use_rss_feed_link_adds_meta_link_for_markdown_posts() + { + config(['site.url' => 'foo']); + $this->assertPageHasFeedLink(new MarkdownPost()); + } + + public function test_can_use_rss_feed_link_adds_meta_link_for_all_pages() + { + config(['site.url' => 'foo']); + $this->assertPageHasFeedLink(new BladePage('')); + $this->assertPageHasFeedLink(new MarkdownPage()); + $this->assertPageHasFeedLink(new MarkdownPost()); + $this->assertPageHasFeedLink(new DocumentationPage()); + } + + public function test_can_use_rss_feed_uses_configured_site_url() + { + config(['site.url' => 'foo']); + config(['site.url' => 'foo']); + $page = new MarkdownPage(); + + $this->assertStringContainsString( + '', + $page->renderPageMetadata() + ); + } + + public function test_can_use_rss_feed_uses_configured_rss_file_name() + { + config(['site.url' => 'foo']); + config(['hyde.rss_filename' => 'posts.rss']); + $page = new MarkdownPage(); + + $this->assertStringContainsString( + '', + $page->renderPageMetadata() + ); + } + + public function test_link_is_not_added_if_site_url_is_not_set() + { + config(['site.url' => 'foo']); + config(['site.url' => '']); + $page = new MarkdownPage(); + + $this->assertStringNotContainsString( + 'renderPageMetadata() + ); + } } From f3e75c85072441081c9fe2e1177bc9517a67d8b1 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 7 Aug 2022 15:52:25 +0000 Subject: [PATCH 32/33] Apply fixes from StyleCI --- packages/framework/src/Contracts/AbstractPage.php | 2 -- packages/framework/tests/Feature/AbstractPageTest.php | 1 - packages/framework/tests/Feature/MetadataHelperTest.php | 1 - 3 files changed, 4 deletions(-) diff --git a/packages/framework/src/Contracts/AbstractPage.php b/packages/framework/src/Contracts/AbstractPage.php index 17a32c11046..aa2d90663b5 100644 --- a/packages/framework/src/Contracts/AbstractPage.php +++ b/packages/framework/src/Contracts/AbstractPage.php @@ -4,14 +4,12 @@ use Hyde\Framework\Actions\SourceFileParser; use Hyde\Framework\Concerns\FrontMatter\Schemas\PageSchema; -use Hyde\Framework\Helpers\Features; use Hyde\Framework\Helpers\Meta; use Hyde\Framework\Hyde; use Hyde\Framework\Models\FrontMatter; use Hyde\Framework\Models\Pages\MarkdownPost; use Hyde\Framework\Models\Route; use Hyde\Framework\Services\DiscoveryService; -use Hyde\Framework\Services\RssFeedService; use Illuminate\Support\Collection; /** diff --git a/packages/framework/tests/Feature/AbstractPageTest.php b/packages/framework/tests/Feature/AbstractPageTest.php index ef6da28874a..6fb9777e47c 100644 --- a/packages/framework/tests/Feature/AbstractPageTest.php +++ b/packages/framework/tests/Feature/AbstractPageTest.php @@ -664,5 +664,4 @@ public function test_get_dynamic_metadata_does_not_add_twitter_and_open_graph_ti $page->getDynamicMetadata() ); } - } diff --git a/packages/framework/tests/Feature/MetadataHelperTest.php b/packages/framework/tests/Feature/MetadataHelperTest.php index 1ce2ec66aa0..44e47ed2207 100644 --- a/packages/framework/tests/Feature/MetadataHelperTest.php +++ b/packages/framework/tests/Feature/MetadataHelperTest.php @@ -159,7 +159,6 @@ public function test_render_method_gives_precedence_to_supplied_meta_tags() ); } - public function test_get_dynamic_metadata_adds_sitemap_link_when_conditions_are_met() { config(['site.url' => 'https://example.com']); From 45c21b9b4b3ddbd3337b265f1341a7beeceab921 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Aug 2022 17:53:02 +0200 Subject: [PATCH 33/33] Update RELEASE_NOTES.md --- RELEASE_NOTES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index b3d343051a0..64445fabed6 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -6,6 +6,8 @@ This update contains **breaking changes** to the internal API regarding page mod The update makes large changes to how dynamic data is constructed. Instead of generating page data at runtime, now the data is generated when constructing a page object. This gives the major benefit of being able to see all dynamic data right away, without having to render the page. +The way metadata tags are handled internally is also refactored. The rendered result should not be affected. + ### Added - Added `compile()` method to `Facades\Markdown`, replacing the `parse()` method of the same class - Adds new actions to handle complex dynamic constructors