From d6f92a6ed83a32137f7a377244104373aa198dbb Mon Sep 17 00:00:00 2001 From: caendesilva Date: Sun, 22 May 2022 12:15:16 +0000 Subject: [PATCH 01/45] Automatic Changelog Update --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f984f95..359f26c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [v0.27.12-beta](https://github.com/hydephp/framework/compare/v0.27.11-beta...v0.27.12-beta) + +> 22 May 2022 + +- Code cleanup without affecting functionality [`#440`](https://github.com/hydephp/framework/pull/440) +- Apply fixes from StyleCI [`#439`](https://github.com/hydephp/framework/pull/439) +- Update Changelog [`#438`](https://github.com/hydephp/framework/pull/438) +- Add missing return type declarations [`684b792`](https://github.com/hydephp/framework/commit/684b792796e330c958a312d914057771eb72f2da) +- Automatic Changelog Update [`5705faa`](https://github.com/hydephp/framework/commit/5705faa543b83c6b0d61d3dc4ab4ac8a9b3ac178) +- Add PHPDoc comments with @throws tags [`ae44806`](https://github.com/hydephp/framework/commit/ae44806cb3c23249bc68a39bd1ede6fa0c4e8e56) + #### [v0.27.11-beta](https://github.com/hydephp/framework/compare/v0.27.10-beta...v0.27.11-beta) > 21 May 2022 From 4ba0ef0e96b38127d8dd6489f8155e24347aeaea Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 May 2022 18:56:46 +0200 Subject: [PATCH 02/45] Rename config keys to use snake_case --- config/hyde.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/config/hyde.php b/config/hyde.php index 8c6bb5cc..12e0a5d3 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -58,9 +58,9 @@ 'site_url' => env('SITE_URL', null), - 'prettyUrls' => false, + 'pretty_urls' => false, - 'generateSitemap' => true, + 'generate_sitemap' => true, /* |-------------------------------------------------------------------------- @@ -141,8 +141,8 @@ | */ - 'loadHydeAssetsUsingCDN' => true, - // 'cdnVersionOverride' => 'v1.0.0', + 'load_hyde_assets_using_cdn' => true, + // 'cdn_version_override' => 'v1.0.0', /* |-------------------------------------------------------------------------- @@ -178,7 +178,7 @@ | */ - 'navigationMenuLinks' => [ + 'navigation_menu_links' => [ // [ // 'title' => 'GitHub', // 'destination' => 'https://github.com/hydephp/hyde', @@ -199,7 +199,7 @@ | */ - 'navigationMenuBlacklist' => [ + 'navigation_menu_blacklist' => [ '404', ], @@ -213,7 +213,7 @@ | */ - 'docsSidebarHeaderTitle' => $siteName.' Docs', + 'docs_sidebar_header_title' => $siteName.' Docs', /* |-------------------------------------------------------------------------- @@ -234,7 +234,7 @@ /** * @deprecated version 0.25.0, will be renamed to documentationOutputPath */ - 'docsDirectory' => 'docs', + 'docs_directory' => 'docs', /* |-------------------------------------------------------------------------- @@ -249,7 +249,7 @@ | */ - 'siteOutputPath' => Hyde\Framework\Hyde::path('_site'), + 'site_output_path' => Hyde\Framework\Hyde::path('_site'), /* |-------------------------------------------------------------------------- @@ -264,7 +264,7 @@ | */ - 'documentationPageOrder' => [ + 'documentation_page_order' => [ 'readme', 'installation', 'getting-started', @@ -281,7 +281,7 @@ | */ - 'documentationPageTableOfContents' => [ + 'documentation_page_table_of_contents' => [ 'enabled' => true, 'minHeadingLevel' => 2, 'maxHeadingLevel' => 4, @@ -298,6 +298,6 @@ | */ - 'warnAboutOutdatedConfig' => true, + 'warn_about_outdated_config' => true, ]; From 95075144e8d0dcceff56bae61b6ce51ef754e039 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 May 2022 19:17:57 +0200 Subject: [PATCH 03/45] Remove "Asset Locations and Versions" config setting --- .github/dev-docs/managing-assets.md | 2 +- config/hyde.php | 21 --------------------- src/Concerns/Internal/AssetManager.php | 6 +++--- src/Services/AssetService.php | 2 +- tests/Feature/AssetServiceTest.php | 15 --------------- 5 files changed, 5 insertions(+), 41 deletions(-) diff --git a/.github/dev-docs/managing-assets.md b/.github/dev-docs/managing-assets.md index eaacde2a..8093a36d 100644 --- a/.github/dev-docs/managing-assets.md +++ b/.github/dev-docs/managing-assets.md @@ -14,7 +14,7 @@ But as always with Hyde, you can customize everything if you want to. Hyde ships with a complete frontend where base styles and scripts are included through [HydeFront](https://github.com/hydephp/hydefront) which adds accessibility and mobile support as well as interactions for dark mode switching and navigation and sidebar interactions. -HydeFront is split into two files, `hyde.css` and `hyde.js`. These are loaded in the default Blade views using the [jsDelivr CDN](https://www.jsdelivr.com/package/npm/hydefront). This is the recommended way to load the base styles as the [Hyde Framework](https://github.com/hydephp/framework) automatically makes sure that the correct HydeFront version for the current version of Hyde is loaded. You can disable the CDN in the `config/hyde.php` file by setting `'loadHydeAssetsUsingCDN'` to `false`. +HydeFront is split into two files, `hyde.css` and `hyde.js`. These are loaded in the default Blade views using the [jsDelivr CDN](https://www.jsdelivr.com/package/npm/hydefront). This is the recommended way to load the base styles as the [Hyde Framework](https://github.com/hydephp/framework) automatically makes sure that the correct HydeFront version for the current version of Hyde is loaded. If you don't want to use HydeFribtm you can customize the `styles.blade.php` file. The bulk of the frontend is built with [TailwindCSS](https://tailwindcss.com/). To get you started, when installing Hyde, all the Tailwind styles you need come precompiled and minified into `_media/app.css`. diff --git a/config/hyde.php b/config/hyde.php index 12e0a5d3..ad261246 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -123,27 +123,6 @@ Features::torchlight(), ], - /* - |-------------------------------------------------------------------------- - | Asset Locations and Versions - |-------------------------------------------------------------------------- - | - | Since v0.15.0, the default Hyde styles are no longer included as - | publishable resources. This is to make updating easier, and to - | reduce complexity. Instead, the assets are loaded through the - | jsDelivr CDN. - | - | The CDN version is defined in the AssetService class, - | but can be changed here to a valid HydeFront tag. - | - | If you load HydeFront through Laravel Mix using the NPM package, - | you should disable the HydeFront CDN feature. - | - */ - - 'load_hyde_assets_using_cdn' => true, - // 'cdn_version_override' => 'v1.0.0', - /* |-------------------------------------------------------------------------- | Footer Text diff --git a/src/Concerns/Internal/AssetManager.php b/src/Concerns/Internal/AssetManager.php index c49242c8..2e521a7d 100644 --- a/src/Concerns/Internal/AssetManager.php +++ b/src/Concerns/Internal/AssetManager.php @@ -24,9 +24,9 @@ public static function assetManager(): AssetServiceContract /** * Return the Hyde stylesheet. */ - public static function styles(): string|false + public static function styles(): string { - return config('hyde.loadHydeAssetsUsingCDN', true) ? static::assetManager()->stylePath() : false; + return static::assetManager()->stylePath(); } /** @@ -34,6 +34,6 @@ public static function styles(): string|false */ public static function scripts(): string { - return config('hyde.loadHydeAssetsUsingCDN', true) ? static::assetManager()->scriptPath() : false; + return static::assetManager()->scriptPath(); } } diff --git a/src/Services/AssetService.php b/src/Services/AssetService.php index 5a039bc8..119b2111 100644 --- a/src/Services/AssetService.php +++ b/src/Services/AssetService.php @@ -16,7 +16,7 @@ class AssetService implements AssetServiceContract public function version(): string { - return config('hyde.cdnVersionOverride', $this->version); + return $this->version; } public function stylePath(): string diff --git a/tests/Feature/AssetServiceTest.php b/tests/Feature/AssetServiceTest.php index 0ae37a18..7e1f06da 100644 --- a/tests/Feature/AssetServiceTest.php +++ b/tests/Feature/AssetServiceTest.php @@ -3,7 +3,6 @@ namespace Tests\Feature; use Hyde\Framework\Services\AssetService; -use Illuminate\Support\Facades\Config; use Tests\TestCase; /** @@ -30,13 +29,6 @@ public function test_version_method_returns_version_property_when_config_overrid $this->assertEquals($service->version, $service->version()); } - public function test_can_change_version_in_config() - { - $service = new AssetService(); - Config::set('hyde.cdnVersionOverride', '2.0.0'); - $this->assertEquals('2.0.0', $service->version()); - } - public function test_style_path_method_returns_cdn_path() { $service = new AssetService(); @@ -57,11 +49,4 @@ public function test_cdn_path_constructor_returns_cdn_uri() $this->assertIsString($path = $service->constructCdnPath('styles.css')); $this->assertStringContainsString('styles.css', $path); } - - public function test_cdn_path_constructor_uses_selected_version() - { - $service = new AssetService(); - Config::set('hyde.cdnVersionOverride', '1.2.3'); - $this->assertStringContainsString('@1.2.3', $service->constructCdnPath('styles.css')); - } } From 2e890658da27d65d646d4c41df7f1f84a252ac31 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 May 2022 19:56:43 +0200 Subject: [PATCH 04/45] Change config keys to lowercase --- .github/dev-docs/documentation-pages.md | 16 ++++++++-------- config/hyde.php | 4 ++-- src/Actions/GeneratesTableOfContents.php | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/dev-docs/documentation-pages.md b/.github/dev-docs/documentation-pages.md index 095b97ad..8ab3b162 100644 --- a/.github/dev-docs/documentation-pages.md +++ b/.github/dev-docs/documentation-pages.md @@ -165,8 +165,8 @@ If you want to store the compiled documentation pages in a different directory t for example to specify a version like the Hyde docs does, you can specify the output directory in the Hyde configuration file. ```php -'docsDirectory' => 'docs' // Default -'docsDirectory' => 'docs/master' // What the Hyde docs use +'docs_directory' => 'docs' // default +'docs_directory' => 'docs/master' // What the Hyde docs use ``` ### Sidebar header name @@ -175,7 +175,7 @@ By default, the site title shown in the sidebar header is generated from the con You can change this in the Hyde configuration file. ```php -'docsSidebarHeaderTitle' => 'API Documentation', +'docs_sidebar_header_title' => 'API Documentation', ``` ### Sidebar page order @@ -184,7 +184,7 @@ To quickly arrange the order of items in the sidebar, you can reorder the page s Link items without an entry here will have fall back to the default priority of 999, putting them last. ```php -'documentationPageOrder' => [ +'documentation_page_order' => [ 'readme', 'installation', 'getting-started', @@ -200,10 +200,10 @@ In the Hyde config you can configure the behavior, content, and the look and fee You can also disable the feature completely. ```php -'documentationPageTableOfContents' => [ +'documentation_page_table_of_contents' => [ 'enabled' => true, - 'minHeadingLevel' => 2, - 'maxHeadingLevel' => 4, - 'smoothPageScrolling' => true, + 'min_heading_level' => 2, + 'max_heading_level' => 4, + 'smooth_page_scrolling' => true, ], ``` diff --git a/config/hyde.php b/config/hyde.php index ad261246..0d8c208e 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -262,8 +262,8 @@ 'documentation_page_table_of_contents' => [ 'enabled' => true, - 'minHeadingLevel' => 2, - 'maxHeadingLevel' => 4, + 'min_heading_level' => 2, + 'max_heading_level' => 4, 'smoothPageScrolling' => true, ], diff --git a/src/Actions/GeneratesTableOfContents.php b/src/Actions/GeneratesTableOfContents.php index 66b6bd42..ae939194 100644 --- a/src/Actions/GeneratesTableOfContents.php +++ b/src/Actions/GeneratesTableOfContents.php @@ -30,8 +30,8 @@ public function execute(): string 'html_class' => 'table-of-contents', 'position' => 'top', 'style' => 'bullet', - 'min_heading_level' => config('hyde.documentationPageTableOfContents.minHeadingLevel', 2), - 'max_heading_level' => config('hyde.documentationPageTableOfContents.maxHeadingLevel', 4), + 'min_heading_level' => config('hyde.documentation_page_table_of_contents.min_heading_level', 2), + 'max_heading_level' => config('hyde.documentation_page_table_of_contents.max_heading_level', 4), 'normalize' => 'relative', ], 'heading_permalink' => [ From 8ebdef3de9fd6a97ae39792491ebb678f9a67c56 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 May 2022 19:56:58 +0200 Subject: [PATCH 05/45] Remove unused "smoothPageScrolling" config option --- config/hyde.php | 1 - 1 file changed, 1 deletion(-) diff --git a/config/hyde.php b/config/hyde.php index 0d8c208e..f9640f53 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -264,7 +264,6 @@ 'enabled' => true, 'min_heading_level' => 2, 'max_heading_level' => 4, - 'smoothPageScrolling' => true, ], /* From ea5d2204d500c49342c7e9e93379051b29a2c676 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 May 2022 21:18:24 +0200 Subject: [PATCH 06/45] Fix wrong variable name causing TOC not to show --- .../components/docs/labeled-sidebar-navigation-menu.blade.php | 4 ++-- .../views/components/docs/sidebar-navigation-menu.blade.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/views/components/docs/labeled-sidebar-navigation-menu.blade.php b/resources/views/components/docs/labeled-sidebar-navigation-menu.blade.php index 38390492..dc698430 100644 --- a/resources/views/components/docs/labeled-sidebar-navigation-menu.blade.php +++ b/resources/views/components/docs/labeled-sidebar-navigation-menu.blade.php @@ -7,9 +7,9 @@
  • $item->destination === basename($currentPage)]) role="listitem"> @if($item->destination === basename($currentPage)) {{ $item->label }} - @if(isset($docs->tableOfContents)) + @if(isset($page->tableOfContents)) Table of contents - {!! ($docs->tableOfContents) !!} + {!! ($page->tableOfContents) !!} @endif @else {{ $item->label }} diff --git a/resources/views/components/docs/sidebar-navigation-menu.blade.php b/resources/views/components/docs/sidebar-navigation-menu.blade.php index 8d22fd47..1bef7f07 100644 --- a/resources/views/components/docs/sidebar-navigation-menu.blade.php +++ b/resources/views/components/docs/sidebar-navigation-menu.blade.php @@ -5,9 +5,9 @@ {{ $item->label }} - @if(isset($docs->tableOfContents)) + @if(isset($page->tableOfContents)) Table of contents - {!! ($docs->tableOfContents) !!} + {!! ($page->tableOfContents) !!} @endif @else {{ $item->label }} From 62bc5c3c0abd77f82d0c589bfd60de7f8c5dda55 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 May 2022 21:18:32 +0200 Subject: [PATCH 07/45] Change config key case to snake_case --- resources/views/layouts/docs.blade.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/views/layouts/docs.blade.php b/resources/views/layouts/docs.blade.php index ab210d41..a6def2f7 100644 --- a/resources/views/layouts/docs.blade.php +++ b/resources/views/layouts/docs.blade.php @@ -15,10 +15,10 @@ @if(Hyde::docsIndexPath() !== false) - {{ config('hyde.docsSidebarHeaderTitle', 'Documentation') }} + {{ config('hyde.docs_sidebar_header_title', 'Documentation') }} @else - {{ config('hyde.docsSidebarHeaderTitle', 'Documentation') }} + {{ config('hyde.docs_sidebar_header_title', 'Documentation') }} @endif @include('hyde::components.navigation.theme-toggle-button') @@ -35,10 +35,10 @@ @if(Hyde::docsIndexPath() !== false) - {{ config('hyde.docsSidebarHeaderTitle', 'Documentation') }} + {{ config('hyde.docs_sidebar_header_title', 'Documentation') }} @else - {{ config('hyde.docsSidebarHeaderTitle', 'Documentation') }} + {{ config('hyde.docs_sidebar_header_title', 'Documentation') }} @endif @include('hyde::components.navigation.theme-toggle-button') From 807d085e08df377d93a50fc7d232931d1b3d2e30 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 May 2022 21:21:22 +0200 Subject: [PATCH 08/45] Update config keys to snake_case --- src/Actions/GeneratesNavigationMenu.php | 4 ++-- src/Commands/HydeUpdateConfigsCommand.php | 2 +- src/Concerns/HasTableOfContents.php | 2 +- src/Concerns/Internal/FileHelpers.php | 4 ++-- src/Concerns/Markdown/HasMarkdownFeatures.php | 2 +- src/Services/RssFeedService.php | 6 +++--- src/Services/SitemapService.php | 2 +- ...TestBuildStaticSiteCommandFlagToEnablePrettyUrlsTest.php | 6 +++--- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Actions/GeneratesNavigationMenu.php b/src/Actions/GeneratesNavigationMenu.php index 8505657d..e1cc06b0 100644 --- a/src/Actions/GeneratesNavigationMenu.php +++ b/src/Actions/GeneratesNavigationMenu.php @@ -93,7 +93,7 @@ private function getLinks(): array // Remove config defined blacklisted links foreach ($links as $key => $link) { - if (in_array(Str::slug($link['title']), config('hyde.navigationMenuBlacklist', []))) { + if (in_array(Str::slug($link['title']), config('hyde.navigation_menu_blacklist', []))) { unset($links[$key]); } } @@ -113,7 +113,7 @@ private function getLinks(): array */ public function getLinksFromConfig(): array { - $configLinks = config('hyde.navigationMenuLinks', []); + $configLinks = config('hyde.navigation_menu_links', []); $links = []; diff --git a/src/Commands/HydeUpdateConfigsCommand.php b/src/Commands/HydeUpdateConfigsCommand.php index a50d3352..f0bbed21 100644 --- a/src/Commands/HydeUpdateConfigsCommand.php +++ b/src/Commands/HydeUpdateConfigsCommand.php @@ -21,7 +21,7 @@ public function __construct() { parent::__construct(); - if ($this->checkIfConfigIsOutOfDate() && config('hyde.warnAboutOutdatedConfig', true)) { + if ($this->checkIfConfigIsOutOfDate() && config('hyde.warn_about_outdated_config', true)) { $this->setDescription( '⚠ Your configuration may be out of date. '. 'Run this command to update them.' diff --git a/src/Concerns/HasTableOfContents.php b/src/Concerns/HasTableOfContents.php index 260eb3ac..06c584d9 100644 --- a/src/Concerns/HasTableOfContents.php +++ b/src/Concerns/HasTableOfContents.php @@ -15,7 +15,7 @@ trait HasTableOfContents public function constructTableOfContents(): void { - if (config('hyde.documentationPageTableOfContents.enabled', true)) { + if (config('hyde.documentation_page_table_of_contents.enabled', true)) { $this->tableOfContents = (new GeneratesTableOfContents($this->body))->execute(); } } diff --git a/src/Concerns/Internal/FileHelpers.php b/src/Concerns/Internal/FileHelpers.php index 27a25762..2ad85cac 100644 --- a/src/Concerns/Internal/FileHelpers.php +++ b/src/Concerns/Internal/FileHelpers.php @@ -25,7 +25,7 @@ trait FileHelpers */ public static function docsDirectory(): string { - return trim(config('hyde.docsDirectory', 'docs'), '/\\'); + return trim(config('hyde.docs_directory', 'docs'), '/\\'); } /** @@ -86,7 +86,7 @@ public static function vendorPath(string $path = ''): string */ public static function pageLink(string $destination): string { - if (config('hyde.prettyUrls', false) === true) { + if (config('hyde.pretty_urls', false) === true) { if (str_ends_with($destination, '.html')) { if ($destination === 'index.html') { return '/'; diff --git a/src/Concerns/Markdown/HasMarkdownFeatures.php b/src/Concerns/Markdown/HasMarkdownFeatures.php index 1a8b9cd0..74d3f274 100644 --- a/src/Concerns/Markdown/HasMarkdownFeatures.php +++ b/src/Concerns/Markdown/HasMarkdownFeatures.php @@ -11,6 +11,6 @@ trait HasMarkdownFeatures { public static function hasTableOfContents(): bool { - return config('hyde.documentationPageTableOfContents.enabled', true); + return config('hyde.documentation_page_table_of_contents.enabled', true); } } diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index 485449de..5eb1d5f9 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -99,7 +99,7 @@ protected function addAdditionalChannelData(): void protected function getDescription(): string { return static::xmlEscape( - config('hyde.rssDescription', + config('hyde.rss_description', static::getTitle().' RSS Feed') ); } @@ -127,7 +127,7 @@ public static function getLink(): string public static function getDefaultOutputFilename(): string { - return config('hyde.rssFilename', 'feed.xml'); + return config('hyde.rss_filename', 'feed.xml'); } public static function generateFeed(): string @@ -137,6 +137,6 @@ public static function generateFeed(): string public static function canGenerateFeed(): bool { - return (Hyde::uriPath() !== false) && config('hyde.generateRssFeed', true) && Features::hasBlogPosts(); + return (Hyde::uriPath() !== false) && config('hyde.generate_rss_feed', true) && Features::hasBlogPosts(); } } diff --git a/src/Services/SitemapService.php b/src/Services/SitemapService.php index 0f812f84..a4942f51 100644 --- a/src/Services/SitemapService.php +++ b/src/Services/SitemapService.php @@ -120,6 +120,6 @@ public static function generateSitemap(): string public static function canGenerateSitemap(): bool { - return (Hyde::uriPath() !== false) && config('hyde.generateSitemap', true); + return (Hyde::uriPath() !== false) && config('hyde.generate_sitemap', true); } } diff --git a/tests/Unit/TestBuildStaticSiteCommandFlagToEnablePrettyUrlsTest.php b/tests/Unit/TestBuildStaticSiteCommandFlagToEnablePrettyUrlsTest.php index 3aae4513..14f625d1 100644 --- a/tests/Unit/TestBuildStaticSiteCommandFlagToEnablePrettyUrlsTest.php +++ b/tests/Unit/TestBuildStaticSiteCommandFlagToEnablePrettyUrlsTest.php @@ -11,17 +11,17 @@ class TestBuildStaticSiteCommandFlagToEnablePrettyUrlsTest extends TestCase { public function test_pretty_urls_can_be_enabled_with_flag() { - config(['hyde.prettyUrls' => false]); + config(['hyde.pretty_urls' => false]); $this->artisan('build --pretty-urls') ->expectsOutput('Generating site with pretty URLs') ->assertExitCode(0); - $this->assertTrue(config('hyde.prettyUrls', false)); + $this->assertTrue(config('hyde.pretty_urls', false)); } public function test_config_change_is_not_persisted() { - $this->assertFalse(config('hyde.prettyUrls', false)); + $this->assertFalse(config('hyde.pretty_urls', false)); } } From 92b9ae5fc4f2c7743206ebcfce48d81e4df7746d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 May 2022 21:46:11 +0200 Subject: [PATCH 09/45] Extract documentation configuration options to docs.php --- .github/dev-docs/RELEASE-NOTES-DRAFT.md | 26 ++++++ .github/dev-docs/documentation-pages.md | 19 +++-- config/docs.php | 84 +++++++++++++++++++ config/hyde.php | 68 +-------------- resources/views/layouts/docs.blade.php | 8 +- src/Actions/GeneratesTableOfContents.php | 4 +- src/Concerns/HasTableOfContents.php | 2 +- src/Concerns/Internal/FileHelpers.php | 4 +- src/Concerns/Markdown/HasMarkdownFeatures.php | 2 +- src/Models/DocumentationSidebarItem.php | 2 +- .../DocumentationSidebarServiceTest.php | 8 +- .../HasConfigurableMarkdownFeaturesTest.php | 2 +- tests/Feature/StaticPageBuilderTest.php | 2 +- tests/Unit/HasMarkdownFeaturesTest.php | 4 +- 14 files changed, 140 insertions(+), 95 deletions(-) create mode 100644 .github/dev-docs/RELEASE-NOTES-DRAFT.md create mode 100644 config/docs.php diff --git a/.github/dev-docs/RELEASE-NOTES-DRAFT.md b/.github/dev-docs/RELEASE-NOTES-DRAFT.md new file mode 100644 index 00000000..29403b4c --- /dev/null +++ b/.github/dev-docs/RELEASE-NOTES-DRAFT.md @@ -0,0 +1,26 @@ +# Draft for the release notes of upcoming HydePHP versions + +## Changes to the configuration files + +The entire configuration system has been refactored. + +### Snake_case is used for all configuration keys + +All configuration keys are now in the snake_case_format. Published configuration files will need to be updated accordingly. This is pretty fast in a modern code editor like VS Code. + +### Documentation options have been moved to a new file + +The documentation page specific options have been moved to the `config/docs.php` file. +You may need to republish Blade views if you have done so before. + +This is also easy to do in a modern code editor. See this example of the search and replace I used +to update the codebase: + +`hyde.docs_sidebar_header_title` => `docs.header_title` + + +### Deprecations and removals + +The deprecated option named `hyde.docs_directory` has been removed. + +Use `docs.output_directory` instead. \ No newline at end of file diff --git a/.github/dev-docs/documentation-pages.md b/.github/dev-docs/documentation-pages.md index 8ab3b162..edd28537 100644 --- a/.github/dev-docs/documentation-pages.md +++ b/.github/dev-docs/documentation-pages.md @@ -111,7 +111,7 @@ The default priority is 999. You can override the priority using the following f priority: 5 ``` -You can also change the order in the Hyde configuration file. +You can also change the order in the Docs configuration file. See [the chapter in the customization page](customization.html#navigation-menu--sidebar) for more details.
    _I personally think the config route is easier as it gives an instant overview, however the first way is nice as well._ @@ -162,20 +162,20 @@ including the documentation pages. Here is a high level overview for quick refer ### Output directory If you want to store the compiled documentation pages in a different directory than the default 'docs' directory, -for example to specify a version like the Hyde docs does, you can specify the output directory in the Hyde configuration file. +for example to specify a version like the Hyde docs does, you can specify the output directory in the Docs configuration file. ```php -'docs_directory' => 'docs' // default -'docs_directory' => 'docs/master' // What the Hyde docs use +'output_directory' => 'docs' // default +'output_directory' => 'docs/master' // What the Hyde docs use ``` ### Sidebar header name By default, the site title shown in the sidebar header is generated from the configured site name suffixed with "docs". -You can change this in the Hyde configuration file. +You can change this in the Docs configuration file. ```php -'docs_sidebar_header_title' => 'API Documentation', +'title' => 'API Documentation', ``` ### Sidebar page order @@ -184,7 +184,7 @@ To quickly arrange the order of items in the sidebar, you can reorder the page s Link items without an entry here will have fall back to the default priority of 999, putting them last. ```php -'documentation_page_order' => [ +'sidebar_order' => [ 'readme', 'installation', 'getting-started', @@ -196,11 +196,12 @@ See [the chapter in the customization page](customization.html#navigation-menu-- ### Table of contents settings -In the Hyde config you can configure the behavior, content, and the look and feel of the sidebar table of contents. +In the `config/docs.php` file you can configure the behavior, content, +and the look and feel of the sidebar table of contents. You can also disable the feature completely. ```php -'documentation_page_table_of_contents' => [ +'table_of_contents' => [ 'enabled' => true, 'min_heading_level' => 2, 'max_heading_level' => 4, diff --git a/config/docs.php b/config/docs.php new file mode 100644 index 00000000..01e6207a --- /dev/null +++ b/config/docs.php @@ -0,0 +1,84 @@ + config('hyde.name', 'HydePHP').' Docs', + + + /* + |-------------------------------------------------------------------------- + | Documentation Site Output Directory + |-------------------------------------------------------------------------- + | + | If you want to store the compiled documentation pages in a different + | directory than the default 'docs' directory, for example to set the + | specified version, you can specify the directory here. + | + | Note that you need to take care as to not set it to something that + | may conflict with other parts, such as media or posts directories. + | + | The default value is 'docs'. For easy versioning you can do what + | HydePHP.com does, setting it to 'docs/master'. + | + */ + + 'output_directory' => 'docs', + + + /* + |-------------------------------------------------------------------------- + | Sidebar Page Order + |-------------------------------------------------------------------------- + | + | In the generated Documentation pages the navigation links in the sidebar + | are sorted alphabetically by default. As this rarely makes sense, you + | can reorder the page slugs in the list and the links will be sorted + | in that order. Link items without an entry here will have fall + | back to the default priority of 999, putting them last. + | + | You can also set explicit priorities in front matter. + | + */ + + 'sidebar_order' => [ + 'readme', + 'installation', + 'getting-started', + ], + + /* + |-------------------------------------------------------------------------- + | Table of Contents Settings + |-------------------------------------------------------------------------- + | + | The Hyde Documentation Module comes with a fancy Sidebar that, by default, + | has a Table of Contents included. Here, you can configure its behavior, + | content, look and feel. You can also disable the feature completely. + | + */ + + 'table_of_contents' => [ + 'enabled' => true, + 'min_heading_level' => 2, + 'max_heading_level' => 4, + ], +]; \ No newline at end of file diff --git a/config/hyde.php b/config/hyde.php index f9640f53..f300a9ce 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -182,38 +182,7 @@ '404', ], - /* - |-------------------------------------------------------------------------- - | Documentation Sidebar Header Name - |-------------------------------------------------------------------------- - | - | By default, the sidebar title shown in the documentation page layouts uses - | the app name suffixed with "docs". You can change it with this setting. - | - */ - - 'docs_sidebar_header_title' => $siteName.' Docs', - - /* - |-------------------------------------------------------------------------- - | Documentation Site Output Directory - |-------------------------------------------------------------------------- - | - | If you want to store the compiled documentation pages in a different - | directory than the default 'docs' directory, for example to set the - | specified version, you can specify the directory here. - | - | Note that you need to take care as to not set it to something that - | may conflict with other parts, such as media or posts directories. - | - | The default value is 'docs'. - | - */ - - /** - * @deprecated version 0.25.0, will be renamed to documentationOutputPath - */ - 'docs_directory' => 'docs', + /* |-------------------------------------------------------------------------- @@ -230,41 +199,6 @@ 'site_output_path' => Hyde\Framework\Hyde::path('_site'), - /* - |-------------------------------------------------------------------------- - | Documentation Sidebar Page Order - |-------------------------------------------------------------------------- - | - | In the generated Documentation pages the navigation links in the sidebar - | are sorted alphabetically by default. As this rarely makes sense, you - | can reorder the page slugs in the list and the links will be sorted - | in that order. Link items without an entry here will have fall - | back to the default priority of 999, putting them last. - | - */ - - 'documentation_page_order' => [ - 'readme', - 'installation', - 'getting-started', - ], - - /* - |-------------------------------------------------------------------------- - | Documentation Table of Contents Settings - |-------------------------------------------------------------------------- - | - | The Hyde Documentation Module comes with a fancy Sidebar that, by default, - | has a Table of Contents included. Here, you can configure its behavior, - | content, look and feel. You can also disable the feature completely. - | - */ - - 'documentation_page_table_of_contents' => [ - 'enabled' => true, - 'min_heading_level' => 2, - 'max_heading_level' => 4, - ], /* |-------------------------------------------------------------------------- diff --git a/resources/views/layouts/docs.blade.php b/resources/views/layouts/docs.blade.php index a6def2f7..30cad9ce 100644 --- a/resources/views/layouts/docs.blade.php +++ b/resources/views/layouts/docs.blade.php @@ -15,10 +15,10 @@ @if(Hyde::docsIndexPath() !== false) - {{ config('hyde.docs_sidebar_header_title', 'Documentation') }} + {{ config('docs.title', 'Documentation') }} @else - {{ config('hyde.docs_sidebar_header_title', 'Documentation') }} + {{ config('docs.title', 'Documentation') }} @endif @include('hyde::components.navigation.theme-toggle-button') @@ -35,10 +35,10 @@ @if(Hyde::docsIndexPath() !== false) - {{ config('hyde.docs_sidebar_header_title', 'Documentation') }} + {{ config('docs.title', 'Documentation') }} @else - {{ config('hyde.docs_sidebar_header_title', 'Documentation') }} + {{ config('docs.title', 'Documentation') }} @endif @include('hyde::components.navigation.theme-toggle-button') diff --git a/src/Actions/GeneratesTableOfContents.php b/src/Actions/GeneratesTableOfContents.php index ae939194..7b853902 100644 --- a/src/Actions/GeneratesTableOfContents.php +++ b/src/Actions/GeneratesTableOfContents.php @@ -30,8 +30,8 @@ public function execute(): string 'html_class' => 'table-of-contents', 'position' => 'top', 'style' => 'bullet', - 'min_heading_level' => config('hyde.documentation_page_table_of_contents.min_heading_level', 2), - 'max_heading_level' => config('hyde.documentation_page_table_of_contents.max_heading_level', 4), + 'min_heading_level' => config('docs.table_of_contents.min_heading_level', 2), + 'max_heading_level' => config('docs.table_of_contents.max_heading_level', 4), 'normalize' => 'relative', ], 'heading_permalink' => [ diff --git a/src/Concerns/HasTableOfContents.php b/src/Concerns/HasTableOfContents.php index 06c584d9..e38ffbe8 100644 --- a/src/Concerns/HasTableOfContents.php +++ b/src/Concerns/HasTableOfContents.php @@ -15,7 +15,7 @@ trait HasTableOfContents public function constructTableOfContents(): void { - if (config('hyde.documentation_page_table_of_contents.enabled', true)) { + if (config('docs.table_of_contents.enabled', true)) { $this->tableOfContents = (new GeneratesTableOfContents($this->body))->execute(); } } diff --git a/src/Concerns/Internal/FileHelpers.php b/src/Concerns/Internal/FileHelpers.php index 2ad85cac..b3eaf03a 100644 --- a/src/Concerns/Internal/FileHelpers.php +++ b/src/Concerns/Internal/FileHelpers.php @@ -17,7 +17,7 @@ trait FileHelpers * * @deprecated will be renamed to be more distinct from other path helpers. * Naming suggestion is `getDocumentationOutputPath()`. - * The configuration is deprecated as well and will be renamed. + * The configuration option has been renamed. * * @todo Test and if needed add support for storing documentation files in the site root * @@ -25,7 +25,7 @@ trait FileHelpers */ public static function docsDirectory(): string { - return trim(config('hyde.docs_directory', 'docs'), '/\\'); + return trim(config('docs.output_directory', 'docs'), '/\\'); } /** diff --git a/src/Concerns/Markdown/HasMarkdownFeatures.php b/src/Concerns/Markdown/HasMarkdownFeatures.php index 74d3f274..889cf29f 100644 --- a/src/Concerns/Markdown/HasMarkdownFeatures.php +++ b/src/Concerns/Markdown/HasMarkdownFeatures.php @@ -11,6 +11,6 @@ trait HasMarkdownFeatures { public static function hasTableOfContents(): bool { - return config('hyde.documentation_page_table_of_contents.enabled', true); + return config('docs.table_of_contents.enabled', true); } } diff --git a/src/Models/DocumentationSidebarItem.php b/src/Models/DocumentationSidebarItem.php index ecb662ea..53b4fb11 100644 --- a/src/Models/DocumentationSidebarItem.php +++ b/src/Models/DocumentationSidebarItem.php @@ -30,7 +30,7 @@ public function __construct(string $label, string $destination, ?int $priority = protected function findPriorityInConfig(string $slug): int { - $orderIndexArray = config('hyde.documentationPageOrder', []); + $orderIndexArray = config('docs.sidebar_order', []); if (! in_array($slug, $orderIndexArray)) { return 500; diff --git a/tests/Feature/Services/DocumentationSidebarServiceTest.php b/tests/Feature/Services/DocumentationSidebarServiceTest.php index f5fada57..1ae0ce9e 100644 --- a/tests/Feature/Services/DocumentationSidebarServiceTest.php +++ b/tests/Feature/Services/DocumentationSidebarServiceTest.php @@ -79,7 +79,7 @@ public function test_files_with_front_matter_hidden_set_to_true_are_removed_from public function test_sidebar_is_ordered_alphabetically_when_no_order_is_set_in_config() { - Config::set('hyde.documentationPageOrder', []); + Config::set('docs.sidebar_order', []); touch(Hyde::path('_docs/alpha.md')); touch(Hyde::path('_docs/bravo.md')); touch(Hyde::path('_docs/charlie.md')); @@ -93,7 +93,7 @@ public function test_sidebar_is_ordered_alphabetically_when_no_order_is_set_in_c public function test_sidebar_is_ordered_by_priority_when_priority_is_set_in_config() { - Config::set('hyde.documentationPageOrder', [ + Config::set('docs.sidebar_order', [ 'charlie', 'bravo', 'alpha', @@ -127,14 +127,14 @@ public function test_sidebar_item_priority_set_in_config_overrides_front_matter( (new ConvertsArrayToFrontMatter)->execute(['priority' => 25]) ); - Config::set('hyde.documentationPageOrder', ['foo']); + Config::set('docs.sidebar_order', ['foo']); $this->assertEquals(25, DocumentationSidebarService::get()->first()->priority); } public function test_sidebar_priorities_can_be_set_in_both_front_matter_and_config() { - Config::set('hyde.documentationPageOrder', [ + Config::set('docs.sidebar_order', [ 'first', 'third', 'second', diff --git a/tests/Feature/Services/HasConfigurableMarkdownFeaturesTest.php b/tests/Feature/Services/HasConfigurableMarkdownFeaturesTest.php index e8b1bdf4..5c1c1461 100644 --- a/tests/Feature/Services/HasConfigurableMarkdownFeaturesTest.php +++ b/tests/Feature/Services/HasConfigurableMarkdownFeaturesTest.php @@ -95,7 +95,7 @@ public function test_has_features_array_can_enable_permalinks() // Test that method canEnablePermalinks is automatically for DocumentationPages public function test_has_features_array_can_enable_permalinks_auto() { - Config::set('hyde.documentationPageTableOfContents.enabled', true); + Config::set('docs.table_of_contents.enabled', true); $this->sourceModel = DocumentationPage::class; $this->assertTrue($this->canEnablePermalinks()); diff --git a/tests/Feature/StaticPageBuilderTest.php b/tests/Feature/StaticPageBuilderTest.php index c90a856d..76f022e6 100644 --- a/tests/Feature/StaticPageBuilderTest.php +++ b/tests/Feature/StaticPageBuilderTest.php @@ -106,7 +106,7 @@ public function test_creates_custom_documentation_directory() { $page = new DocumentationPage([], '# Body', 'Title', 'foo'); - Config::set('hyde.docsDirectory', 'docs/foo'); + Config::set('docs.output_directory', 'docs/foo'); new StaticPageBuilder($page, true); diff --git a/tests/Unit/HasMarkdownFeaturesTest.php b/tests/Unit/HasMarkdownFeaturesTest.php index 9b14727f..28b63622 100644 --- a/tests/Unit/HasMarkdownFeaturesTest.php +++ b/tests/Unit/HasMarkdownFeaturesTest.php @@ -17,10 +17,10 @@ public function test_has_table_of_contents() { $this->assertIsBool(static::hasTableOfContents()); - Config::set('hyde.documentationPageTableOfContents.enabled', true); + Config::set('docs.table_of_contents.enabled', true); $this->assertTrue(static::hasTableOfContents()); - Config::set('hyde.documentationPageTableOfContents.enabled', false); + Config::set('docs.table_of_contents.enabled', false); $this->assertFalse(static::hasTableOfContents()); } } From f578855047113c3181c9869f1ec9d4d521c3bd62 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 May 2022 21:47:06 +0200 Subject: [PATCH 10/45] Use the snake_case config format --- src/Commands/HydeBuildStaticSiteCommand.php | 2 +- .../Feature/Concerns/HasPageMetadataTest.php | 4 +-- tests/Feature/Services/SitemapServiceTest.php | 4 +-- .../Unit/FileHelperPageLinkPrettyUrlTest.php | 26 +++++++++---------- tests/Unit/FileHelperRelativeLinkTest.php | 12 ++++----- tests/Unit/MarkdownPostHelpersTest.php | 2 +- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Commands/HydeBuildStaticSiteCommand.php b/src/Commands/HydeBuildStaticSiteCommand.php index a9e0fa83..9d78b9be 100644 --- a/src/Commands/HydeBuildStaticSiteCommand.php +++ b/src/Commands/HydeBuildStaticSiteCommand.php @@ -106,7 +106,7 @@ protected function runPreBuildActions(): void if ($this->option('pretty-urls')) { $this->info('Generating site with pretty URLs'); $this->newLine(); - Config::set(['hyde.prettyUrls' => true]); + Config::set(['hyde.pretty_urls' => true]); } } diff --git a/tests/Feature/Concerns/HasPageMetadataTest.php b/tests/Feature/Concerns/HasPageMetadataTest.php index d423e783..ffcf0cd1 100644 --- a/tests/Feature/Concerns/HasPageMetadataTest.php +++ b/tests/Feature/Concerns/HasPageMetadataTest.php @@ -20,7 +20,7 @@ protected function setUp(): void config(['hyde.meta' => []]); config(['hyde.site_url' => null]); - config(['hyde.prettyUrls' => false]); + config(['hyde.pretty_urls' => false]); config(['hyde.generateSitemap' => false]); } @@ -46,7 +46,7 @@ public function test_get_canonical_url_returns_pretty_url_for_top_level_page() public string $slug = 'foo'; }; config(['hyde.site_url' => 'https://example.com']); - config(['hyde.prettyUrls' => true]); + config(['hyde.pretty_urls' => true]); $this->assertEquals('https://example.com/foo', $page->getCanonicalUrl()); } diff --git a/tests/Feature/Services/SitemapServiceTest.php b/tests/Feature/Services/SitemapServiceTest.php index 98f700df..1eee71aa 100644 --- a/tests/Feature/Services/SitemapServiceTest.php +++ b/tests/Feature/Services/SitemapServiceTest.php @@ -112,7 +112,7 @@ public function test_can_generate_sitemap_helper_returns_false_if_sitemaps_are_d public function test_url_item_is_generated_correctly() { - config(['hyde.prettyUrls' => false]); + config(['hyde.pretty_urls' => false]); config(['hyde.site_url' => 'https://example.com']); touch(Hyde::path('_pages/0-test.blade.php')); @@ -129,7 +129,7 @@ public function test_url_item_is_generated_correctly() public function test_url_item_is_generated_with_pretty_ur_ls_if_enabled() { - config(['hyde.prettyUrls' => true]); + config(['hyde.pretty_urls' => true]); config(['hyde.site_url' => 'https://example.com']); touch(Hyde::path('_pages/0-test.blade.php')); diff --git a/tests/Unit/FileHelperPageLinkPrettyUrlTest.php b/tests/Unit/FileHelperPageLinkPrettyUrlTest.php index 6255ce4c..d4c1a6bb 100644 --- a/tests/Unit/FileHelperPageLinkPrettyUrlTest.php +++ b/tests/Unit/FileHelperPageLinkPrettyUrlTest.php @@ -14,82 +14,82 @@ class FileHelperPageLinkPrettyUrlTest extends TestCase { public function test_helper_returns_string_as_is_if_pretty_urls_is_not_true() { - config(['hyde.prettyUrls' => false]); + config(['hyde.pretty_urls' => false]); $this->assertEquals('foo/bar.html', Hyde::pageLink('foo/bar.html')); } public function test_helper_returns_pretty_url_if_pretty_urls_is_true() { - config(['hyde.prettyUrls' => true]); + config(['hyde.pretty_urls' => true]); $this->assertEquals('foo/bar', Hyde::pageLink('foo/bar.html')); } public function test_non_pretty_urls_is_default_value_when_config_is_not_set() { - config(['hyde.prettyUrls' => null]); + config(['hyde.pretty_urls' => null]); $this->assertEquals('foo/bar.html', Hyde::pageLink('foo/bar.html')); } public function test_helper_respects_absolute_urls() { - config(['hyde.prettyUrls' => false]); + config(['hyde.pretty_urls' => false]); $this->assertEquals('/foo/bar.html', Hyde::pageLink('/foo/bar.html')); } public function test_helper_respects_pretty_absolute_urls() { - config(['hyde.prettyUrls' => true]); + config(['hyde.pretty_urls' => true]); $this->assertEquals('/foo/bar', Hyde::pageLink('/foo/bar.html')); } public function test_helper_respects_relative_urls() { - config(['hyde.prettyUrls' => false]); + config(['hyde.pretty_urls' => false]); $this->assertEquals('../foo/bar.html', Hyde::pageLink('../foo/bar.html')); } public function test_helper_respects_pretty_relative_urls() { - config(['hyde.prettyUrls' => true]); + config(['hyde.pretty_urls' => true]); $this->assertEquals('../foo/bar', Hyde::pageLink('../foo/bar.html')); } public function test_non_html_links_are_not_modified() { - config(['hyde.prettyUrls' => true]); + config(['hyde.pretty_urls' => true]); $this->assertEquals('/foo/bar.jpg', Hyde::pageLink('/foo/bar.jpg')); } public function test_helper_respects_absolute_urls_with_pretty_urls_enabled() { - config(['hyde.prettyUrls' => true]); + config(['hyde.pretty_urls' => true]); $this->assertEquals('/foo/bar.jpg', Hyde::pageLink('/foo/bar.jpg')); } public function test_helper_rewrites_index_when_using_pretty_urls() { - config(['hyde.prettyUrls' => true]); + config(['hyde.pretty_urls' => true]); $this->assertEquals('/', Hyde::pageLink('index.html')); } public function test_helper_does_not_rewrite_index_when_not_using_pretty_urls() { - config(['hyde.prettyUrls' => false]); + config(['hyde.pretty_urls' => false]); $this->assertEquals('index.html', Hyde::pageLink('index.html')); } public function test_helper_rewrites_documentation_page_index_when_using_pretty_urls() { - config(['hyde.prettyUrls' => true]); + config(['hyde.pretty_urls' => true]); $this->assertEquals('docs/', Hyde::pageLink('docs/index.html')); } public function test_helper_does_not_rewrite_documentation_page_index_when_not_using_pretty_urls() { - config(['hyde.prettyUrls' => false]); + config(['hyde.pretty_urls' => false]); $this->assertEquals('docs/index.html', Hyde::pageLink('docs/index.html')); } } diff --git a/tests/Unit/FileHelperRelativeLinkTest.php b/tests/Unit/FileHelperRelativeLinkTest.php index acb93485..07b4a7e9 100644 --- a/tests/Unit/FileHelperRelativeLinkTest.php +++ b/tests/Unit/FileHelperRelativeLinkTest.php @@ -66,27 +66,27 @@ public function test_helper_handles_different_file_extensions() // Test helper returns pretty URL if enabled and destination is a HTML file public function test_helper_returns_pretty_url_if_enabled_and_destination_is_a_html_file() { - config(['hyde.prettyUrls' => true]); + config(['hyde.pretty_urls' => true]); $this->assertEquals('../foo', Hyde::relativeLink('foo.html', 'foo/bar.html')); } // Test helper method does not require current path to be HTML to use pretty URLs public function test_helper_method_does_not_require_current_path_to_be_html_to_use_pretty_urls() { - config(['hyde.prettyUrls' => true]); + config(['hyde.pretty_urls' => true]); $this->assertEquals('../foo', Hyde::relativeLink('foo.html', 'foo/bar')); } // Test helper returns does not return pretty URL if when enabled but and destination is not a HTML file public function test_helper_returns_does_not_return_pretty_url_if_when_enabled_but_and_destination_is_not_a_html_file() { - config(['hyde.prettyUrls' => true]); + config(['hyde.pretty_urls' => true]); $this->assertEquals('../foo.png', Hyde::relativeLink('foo.png', 'foo/bar.html')); } public function test_helper_rewrites_index_when_using_pretty_urls() { - config(['hyde.prettyUrls' => true]); + config(['hyde.pretty_urls' => true]); $this->assertEquals('/', Hyde::relativeLink('index.html', 'foo.html')); $this->assertEquals('../', Hyde::relativeLink('index.html', 'foo/bar.html')); $this->assertEquals('../../', Hyde::relativeLink('index.html', 'foo/bar/baz.html')); @@ -94,7 +94,7 @@ public function test_helper_rewrites_index_when_using_pretty_urls() public function test_helper_does_not_rewrite_index_when_not_using_pretty_urls() { - config(['hyde.prettyUrls' => false]); + config(['hyde.pretty_urls' => false]); $this->assertEquals('index.html', Hyde::relativeLink('index.html', 'foo.html')); $this->assertEquals('../index.html', Hyde::relativeLink('index.html', 'foo/bar.html')); $this->assertEquals('../../index.html', Hyde::relativeLink('index.html', 'foo/bar/baz.html')); @@ -102,7 +102,7 @@ public function test_helper_does_not_rewrite_index_when_not_using_pretty_urls() public function test_helper_rewrites_documentation_page_index_when_using_pretty_urls() { - config(['hyde.prettyUrls' => true]); + config(['hyde.pretty_urls' => true]); $this->assertEquals('docs/', Hyde::relativeLink('docs/index.html', 'foo.html')); $this->assertEquals('docs/', Hyde::relativeLink('docs/index.html', 'docs.html')); $this->assertEquals('../docs/', Hyde::relativeLink('docs/index.html', 'foo/bar.html')); diff --git a/tests/Unit/MarkdownPostHelpersTest.php b/tests/Unit/MarkdownPostHelpersTest.php index 24577721..f8de62b1 100644 --- a/tests/Unit/MarkdownPostHelpersTest.php +++ b/tests/Unit/MarkdownPostHelpersTest.php @@ -25,7 +25,7 @@ public function test_get_canonical_link_returns_canonical_uri_path_for_post_slug public function test_get_canonical_link_returns_pretty_url_when_enabled() { - config(['hyde.site_url' => 'https://example.com', 'hyde.prettyUrls' => true]); + config(['hyde.site_url' => 'https://example.com', 'hyde.pretty_urls' => true]); $post = new MarkdownPost([], '', '', 'foo-bar'); $this->assertEquals('https://example.com/posts/foo-bar', $post->getCanonicalLink()); } From 668c2be2ce8feeb865e04f2c4337fc4959156620 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 May 2022 21:47:54 +0200 Subject: [PATCH 11/45] Use the snake_case config format --- tests/Feature/Commands/BuildStaticSiteCommandTest.php | 4 ++-- tests/Feature/Commands/HydeBuildSitemapCommandTest.php | 4 ++-- tests/Feature/Concerns/HasPageMetadataTest.php | 6 +++--- tests/Feature/Services/SitemapServiceTest.php | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/Feature/Commands/BuildStaticSiteCommandTest.php b/tests/Feature/Commands/BuildStaticSiteCommandTest.php index bd60930c..66f15299 100644 --- a/tests/Feature/Commands/BuildStaticSiteCommandTest.php +++ b/tests/Feature/Commands/BuildStaticSiteCommandTest.php @@ -96,7 +96,7 @@ public function test_pretty_urls_option_output() public function test_sitemap_is_not_generated_when_conditions_are_not_met() { config(['hyde.site_url' => '']); - config(['hyde.generateSitemap' => false]); + config(['hyde.generate_sitemap' => false]); $this->artisan('build') ->doesntExpectOutput('Generating sitemap...') @@ -106,7 +106,7 @@ public function test_sitemap_is_not_generated_when_conditions_are_not_met() public function test_sitemap_is_generated_when_conditions_are_met() { config(['hyde.site_url' => 'https://example.com']); - config(['hyde.generateSitemap' => true]); + config(['hyde.generate_sitemap' => true]); $this->artisan('build') ->expectsOutput('Generating sitemap...') diff --git a/tests/Feature/Commands/HydeBuildSitemapCommandTest.php b/tests/Feature/Commands/HydeBuildSitemapCommandTest.php index f1f5fdda..be5df588 100644 --- a/tests/Feature/Commands/HydeBuildSitemapCommandTest.php +++ b/tests/Feature/Commands/HydeBuildSitemapCommandTest.php @@ -13,7 +13,7 @@ class HydeBuildSitemapCommandTest extends TestCase public function test_sitemap_is_not_generated_when_conditions_are_not_met() { config(['hyde.site_url' => '']); - config(['hyde.generateSitemap' => false]); + config(['hyde.generate_sitemap' => false]); unlinkIfExists(Hyde::path('_site/sitemap.xml')); $this->artisan('build:sitemap') @@ -26,7 +26,7 @@ public function test_sitemap_is_not_generated_when_conditions_are_not_met() public function test_sitemap_is_generated_when_conditions_are_met() { config(['hyde.site_url' => 'https://example.com']); - config(['hyde.generateSitemap' => true]); + config(['hyde.generate_sitemap' => true]); unlinkIfExists(Hyde::path('_site/sitemap.xml')); $this->artisan('build:sitemap') diff --git a/tests/Feature/Concerns/HasPageMetadataTest.php b/tests/Feature/Concerns/HasPageMetadataTest.php index ffcf0cd1..9e6980d1 100644 --- a/tests/Feature/Concerns/HasPageMetadataTest.php +++ b/tests/Feature/Concerns/HasPageMetadataTest.php @@ -21,7 +21,7 @@ protected function setUp(): void config(['hyde.meta' => []]); config(['hyde.site_url' => null]); config(['hyde.pretty_urls' => false]); - config(['hyde.generateSitemap' => false]); + config(['hyde.generate_sitemap' => false]); } public function test_get_canonical_url_returns_url_for_top_level_page() @@ -212,7 +212,7 @@ public function test_get_dynamic_metadata_adds_sitemap_link_when_conditions_are_ use HasPageMetadata; }; config(['hyde.site_url' => 'https://example.com']); - config(['hyde.generateSitemap' => true]); + config(['hyde.generate_sitemap' => true]); $this->assertEquals([''], $page->getDynamicMetadata() @@ -226,7 +226,7 @@ public function test_get_dynamic_metadata_does_not_add_sitemap_link_when_conditi use HasPageMetadata; }; config(['hyde.site_url' => 'https://example.com']); - config(['hyde.generateSitemap' => false]); + config(['hyde.generate_sitemap' => false]); $this->assertEquals([], $page->getDynamicMetadata() diff --git a/tests/Feature/Services/SitemapServiceTest.php b/tests/Feature/Services/SitemapServiceTest.php index 1eee71aa..7d96fd61 100644 --- a/tests/Feature/Services/SitemapServiceTest.php +++ b/tests/Feature/Services/SitemapServiceTest.php @@ -106,7 +106,7 @@ public function test_can_generate_sitemap_helper_returns_false_if_hyde_does_not_ public function test_can_generate_sitemap_helper_returns_false_if_sitemaps_are_disabled_in_config() { config(['hyde.site_url' => 'foo']); - config(['hyde.generateSitemap' => false]); + config(['hyde.generate_sitemap' => false]); $this->assertFalse(SitemapService::canGenerateSitemap()); } From 7531b44bdc509e05d54bfe20771b72875dc24996 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 May 2022 21:48:29 +0200 Subject: [PATCH 12/45] Use the snake_case config format --- tests/Feature/Commands/BuildStaticSiteCommandTest.php | 4 ++-- tests/Feature/Commands/HydeBuildRssFeedCommandTest.php | 6 +++--- tests/Feature/Services/RssFeedServiceTest.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Feature/Commands/BuildStaticSiteCommandTest.php b/tests/Feature/Commands/BuildStaticSiteCommandTest.php index 66f15299..41a0a8a5 100644 --- a/tests/Feature/Commands/BuildStaticSiteCommandTest.php +++ b/tests/Feature/Commands/BuildStaticSiteCommandTest.php @@ -117,7 +117,7 @@ public function test_sitemap_is_generated_when_conditions_are_met() public function test_rss_feed_is_not_generated_when_conditions_are_not_met() { config(['hyde.site_url' => '']); - config(['hyde.generateRssFeed' => false]); + config(['hyde.generate_rss_feed' => false]); $this->artisan('build') ->doesntExpectOutput('Generating RSS feed...') @@ -127,7 +127,7 @@ public function test_rss_feed_is_not_generated_when_conditions_are_not_met() public function test_rss_feed_is_generated_when_conditions_are_met() { config(['hyde.site_url' => 'https://example.com']); - config(['hyde.generateRssFeed' => true]); + config(['hyde.generate_rss_feed' => true]); $this->artisan('build') ->expectsOutput('Generating RSS feed...') diff --git a/tests/Feature/Commands/HydeBuildRssFeedCommandTest.php b/tests/Feature/Commands/HydeBuildRssFeedCommandTest.php index 22411c0c..44ff734a 100644 --- a/tests/Feature/Commands/HydeBuildRssFeedCommandTest.php +++ b/tests/Feature/Commands/HydeBuildRssFeedCommandTest.php @@ -13,7 +13,7 @@ class HydeBuildRssFeedCommandTest extends TestCase public function test_rss_feed_is_not_generated_when_conditions_are_not_met() { config(['hyde.site_url' => '']); - config(['hyde.generateRssFeed' => false]); + config(['hyde.generate_rss_feed' => false]); unlinkIfExists(Hyde::path('_site/feed.xml')); $this->artisan('build:rss') @@ -25,7 +25,7 @@ public function test_rss_feed_is_not_generated_when_conditions_are_not_met() public function test_rss_feed_is_generated_when_conditions_are_met() { config(['hyde.site_url' => 'https://example.com']); - config(['hyde.generateRssFeed' => true]); + config(['hyde.generate_rss_feed' => true]); unlinkIfExists(Hyde::path('_site/feed.xml')); $this->artisan('build:rss') @@ -39,7 +39,7 @@ public function test_rss_feed_is_generated_when_conditions_are_met() public function test_rss_filename_can_be_changed() { config(['hyde.site_url' => 'https://example.com']); - config(['hyde.generateRssFeed' => true]); + config(['hyde.generate_rss_feed' => true]); config(['hyde.rssFilename' => 'blog.xml']); unlinkIfExists(Hyde::path('_site/feed.xml')); diff --git a/tests/Feature/Services/RssFeedServiceTest.php b/tests/Feature/Services/RssFeedServiceTest.php index a6c1f984..eb81998e 100644 --- a/tests/Feature/Services/RssFeedServiceTest.php +++ b/tests/Feature/Services/RssFeedServiceTest.php @@ -150,7 +150,7 @@ public function test_can_generate_sitemap_helper_returns_false_if_hyde_does_not_ public function test_can_generate_sitemap_helper_returns_false_if_sitemaps_are_disabled_in_config() { config(['hyde.site_url' => 'foo']); - config(['hyde.generateRssFeed' => false]); + config(['hyde.generate_rss_feed' => false]); $this->assertFalse(RssFeedService::canGenerateFeed()); } } From 0105243c24669bff14799713408561b6e304afea Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 May 2022 22:00:11 +0200 Subject: [PATCH 13/45] Use the snake_case config format --- src/HydeServiceProvider.php | 2 +- tests/Feature/Commands/HydeBuildRssFeedCommandTest.php | 2 +- tests/Feature/GeneratesNavigationMenuTest.php | 2 +- tests/Feature/Services/RssFeedServiceTest.php | 2 +- tests/Unit/HasPageMetadataRssFeedLinkTest.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/HydeServiceProvider.php b/src/HydeServiceProvider.php index 440a8506..820e404b 100644 --- a/src/HydeServiceProvider.php +++ b/src/HydeServiceProvider.php @@ -59,7 +59,7 @@ function () { $this->discoverBladeViewsIn('_pages'); $this->storeCompiledSiteIn(config( - 'hyde.siteOutputPath', Hyde::path('_site') + 'hyde.site_output_path', Hyde::path('_site') )); $this->commands([ diff --git a/tests/Feature/Commands/HydeBuildRssFeedCommandTest.php b/tests/Feature/Commands/HydeBuildRssFeedCommandTest.php index 44ff734a..73b205c2 100644 --- a/tests/Feature/Commands/HydeBuildRssFeedCommandTest.php +++ b/tests/Feature/Commands/HydeBuildRssFeedCommandTest.php @@ -40,7 +40,7 @@ public function test_rss_filename_can_be_changed() { config(['hyde.site_url' => 'https://example.com']); config(['hyde.generate_rss_feed' => true]); - config(['hyde.rssFilename' => 'blog.xml']); + config(['hyde.rss_filename' => 'blog.xml']); unlinkIfExists(Hyde::path('_site/feed.xml')); unlinkIfExists(Hyde::path('_site/blog.xml')); diff --git a/tests/Feature/GeneratesNavigationMenuTest.php b/tests/Feature/GeneratesNavigationMenuTest.php index a40ef782..74dd1bae 100644 --- a/tests/Feature/GeneratesNavigationMenuTest.php +++ b/tests/Feature/GeneratesNavigationMenuTest.php @@ -30,7 +30,7 @@ public function test_get_links_from_config_method() { $generator = new GeneratesNavigationMenu(currentPage: 'foo/bar'); - Config::set('hyde.navigationMenuLinks', [ + Config::set('hyde.navigation_menu_links', [ [ 'title' => 'GNMTestExt', 'destination' => 'https://example.org/test', diff --git a/tests/Feature/Services/RssFeedServiceTest.php b/tests/Feature/Services/RssFeedServiceTest.php index eb81998e..ba3f39ab 100644 --- a/tests/Feature/Services/RssFeedServiceTest.php +++ b/tests/Feature/Services/RssFeedServiceTest.php @@ -70,7 +70,7 @@ public function test_xml_channel_data_can_be_customized() { config(['hyde.name' => 'Foo']); config(['hyde.site_url' => 'https://blog.foo.com/bar']); - config(['hyde.rssDescription' => 'Foo is a web log about stuff']); + config(['hyde.rss_description' => 'Foo is a web log about stuff']); $service = new RssFeedService(); $this->assertEquals('Foo', $service->feed->channel->title); diff --git a/tests/Unit/HasPageMetadataRssFeedLinkTest.php b/tests/Unit/HasPageMetadataRssFeedLinkTest.php index abbe5507..569ae12f 100644 --- a/tests/Unit/HasPageMetadataRssFeedLinkTest.php +++ b/tests/Unit/HasPageMetadataRssFeedLinkTest.php @@ -84,7 +84,7 @@ public function test_can_use_rss_feed_uses_configured_site_url() public function test_can_use_rss_feed_uses_configured_rss_file_name() { - config(['hyde.rssFilename' => 'posts.rss']); + config(['hyde.rss_filename' => 'posts.rss']); $page = new MarkdownPost([], ''); $this->assertStringContainsString( From acc274ab510a520f6874be9bd8a7685eec674e8c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 May 2022 22:02:11 +0200 Subject: [PATCH 14/45] Deprecate YAML file --- src/Services/AuthorService.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Services/AuthorService.php b/src/Services/AuthorService.php index aa5cdddf..c7d64060 100644 --- a/src/Services/AuthorService.php +++ b/src/Services/AuthorService.php @@ -10,10 +10,17 @@ /** * Contains service methods relating to blog post authors. + * + * The YAML service is deprecated, the data will be + * fetched from the main config instead. */ class AuthorService { public string $filepath; + + /** + * @deprecated version 0.28.0 + */ public array $yaml = []; public Collection $authors; @@ -37,10 +44,14 @@ public function __construct() * Returns the filepath of the Yaml file. * * If the file does not exist, it will be created. + * @deprecated version 0.28.0 */ public function publishFile(): void { file_put_contents($this->filepath, <<<'EOF' +# Note that this file is deprecated. You'll be able to +# define authors using the Author facade in the config + # In this file you can declare custom authors. # In the default example, `mr_hyde` is the username. @@ -58,6 +69,7 @@ public function publishFile(): void /** * Parse the Yaml file. * + * @deprecated version 0.28.0 * @return array */ public function getYaml(): array From 2cef183eecc627478221be8fcfb6d33b6f082a7e Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 22 May 2022 20:06:09 +0000 Subject: [PATCH 15/45] Apply fixes from StyleCI --- config/docs.php | 10 ++++------ config/hyde.php | 3 --- src/Services/AuthorService.php | 4 +++- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/config/docs.php b/config/docs.php index 01e6207a..6831c4b0 100644 --- a/config/docs.php +++ b/config/docs.php @@ -1,5 +1,5 @@ config('hyde.name', 'HydePHP').' Docs', - /* |-------------------------------------------------------------------------- | Documentation Site Output Directory @@ -37,13 +36,12 @@ | may conflict with other parts, such as media or posts directories. | | The default value is 'docs'. For easy versioning you can do what - | HydePHP.com does, setting it to 'docs/master'. + | HydePHP.com does, setting it to 'docs/master'. | */ 'output_directory' => 'docs', - /* |-------------------------------------------------------------------------- | Sidebar Page Order @@ -81,4 +79,4 @@ 'min_heading_level' => 2, 'max_heading_level' => 4, ], -]; \ No newline at end of file +]; diff --git a/config/hyde.php b/config/hyde.php index f300a9ce..3bbd8510 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -182,8 +182,6 @@ '404', ], - - /* |-------------------------------------------------------------------------- | Site Output Directory (Experimental 🧪) @@ -199,7 +197,6 @@ 'site_output_path' => Hyde\Framework\Hyde::path('_site'), - /* |-------------------------------------------------------------------------- | Warn about outdated config? diff --git a/src/Services/AuthorService.php b/src/Services/AuthorService.php index c7d64060..9efacf51 100644 --- a/src/Services/AuthorService.php +++ b/src/Services/AuthorService.php @@ -10,7 +10,7 @@ /** * Contains service methods relating to blog post authors. - * + * * The YAML service is deprecated, the data will be * fetched from the main config instead. */ @@ -44,6 +44,7 @@ public function __construct() * Returns the filepath of the Yaml file. * * If the file does not exist, it will be created. + * * @deprecated version 0.28.0 */ public function publishFile(): void @@ -70,6 +71,7 @@ public function publishFile(): void * Parse the Yaml file. * * @deprecated version 0.28.0 + * * @return array */ public function getYaml(): array From 5334c89268c5000b46f327c198e9fbda401862b7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 May 2022 22:07:19 +0200 Subject: [PATCH 16/45] Add deprecation notice --- .github/dev-docs/RELEASE-NOTES-DRAFT.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/dev-docs/RELEASE-NOTES-DRAFT.md b/.github/dev-docs/RELEASE-NOTES-DRAFT.md index 29403b4c..9292cf17 100644 --- a/.github/dev-docs/RELEASE-NOTES-DRAFT.md +++ b/.github/dev-docs/RELEASE-NOTES-DRAFT.md @@ -23,4 +23,6 @@ to update the codebase: The deprecated option named `hyde.docs_directory` has been removed. -Use `docs.output_directory` instead. \ No newline at end of file +Use `docs.output_directory` instead. + +The authors.yml has been deprecated, and will be refactored in an upcoming release. \ No newline at end of file From 7b0a958e68b116d86c86f41315762e2a41b58d68 Mon Sep 17 00:00:00 2001 From: caendesilva Date: Sun, 22 May 2022 20:14:55 +0000 Subject: [PATCH 17/45] Automatic Changelog Update --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 359f26c7..b4f3fb36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [v0.28.0-beta-pre](https://github.com/hydephp/framework/compare/v0.27.12-beta...v0.28.0-beta-pre) + +> 22 May 2022 + +- Refactor configuration to use snake_case for all options, and extract documentation settings to own file [`#444`](https://github.com/hydephp/framework/pull/444) +- Apply fixes from StyleCI [`#443`](https://github.com/hydephp/framework/pull/443) +- Update Changelog [`#441`](https://github.com/hydephp/framework/pull/441) +- Extract documentation configuration options to docs.php [`92b9ae5`](https://github.com/hydephp/framework/commit/92b9ae5fc4f2c7743206ebcfce48d81e4df7746d) +- Use the snake_case config format [`f578855`](https://github.com/hydephp/framework/commit/f578855047113c3181c9869f1ec9d4d521c3bd62) +- Remove "Asset Locations and Versions" config setting [`9507514`](https://github.com/hydephp/framework/commit/95075144e8d0dcceff56bae61b6ce51ef754e039) + #### [v0.27.12-beta](https://github.com/hydephp/framework/compare/v0.27.11-beta...v0.27.12-beta) > 22 May 2022 From 4272d039a96ac2779ece16b54db842a07b788f6a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 11:48:33 +0200 Subject: [PATCH 18/45] Sketch out the Author helper --- config/hyde.php | 25 +++++++++++++++++++++++++ src/Helpers/Author.php | 16 ++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/Helpers/Author.php diff --git a/config/hyde.php b/config/hyde.php index 3bbd8510..79ebd1c1 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -17,6 +17,7 @@ | */ +use Hyde\Framework\Helpers\Author; use Hyde\Framework\Helpers\Features; use Hyde\Framework\Helpers\Meta; @@ -123,6 +124,30 @@ Features::torchlight(), ], + /* + |-------------------------------------------------------------------------- + | Blog Post Authors + |-------------------------------------------------------------------------- + | + | Hyde has support for adding authors in front matter, for example to + | automatically add a link to your website or social media profiles. + | However, it's tedious to have to add those to each and every + | post you make, and keeping them updated is even harder. + | + | Here you can add predefined authors. When writing posts, + | just specify the username in the front matter, and the + | rest of the data will be pulled from a matching entry. + | + */ + + 'authors' => [ + Author::create( + 'mrhyde', // Required username + 'Mr. Hyde', // Optional display name + 'https://hydephp.com' // Optional website URL + ), + ], + /* |-------------------------------------------------------------------------- | Footer Text diff --git a/src/Helpers/Author.php b/src/Helpers/Author.php new file mode 100644 index 00000000..da3bf531 --- /dev/null +++ b/src/Helpers/Author.php @@ -0,0 +1,16 @@ + $displayName, + 'website '=> $website + ]); + } +} \ No newline at end of file From 76ef9c8f90ec10e20cd47aac4053e3b39dbe0952 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 11:50:50 +0200 Subject: [PATCH 19/45] Add name identifiers to Author arguments --- config/hyde.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/hyde.php b/config/hyde.php index 79ebd1c1..01b49eaa 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -142,9 +142,9 @@ 'authors' => [ Author::create( - 'mrhyde', // Required username - 'Mr. Hyde', // Optional display name - 'https://hydephp.com' // Optional website URL + username: 'mrhyde', // Required username + displayName: 'Mr. Hyde', // Optional display name + website: 'https://hydephp.com' // Optional website URL ), ], From 884828a2193ce82d4d1e21cf81eacf0ee4815573 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 11:51:03 +0200 Subject: [PATCH 20/45] Create Image.php --- src/Helpers/Image.php | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/Helpers/Image.php diff --git a/src/Helpers/Image.php b/src/Helpers/Image.php new file mode 100644 index 00000000..dc7c46a3 --- /dev/null +++ b/src/Helpers/Image.php @@ -0,0 +1,11 @@ + Date: Mon, 23 May 2022 11:53:28 +0200 Subject: [PATCH 21/45] Change $displayName to $display_name Breaking variable naming convention, following POLA as config keys are snake_case --- config/hyde.php | 2 +- src/Helpers/Author.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/hyde.php b/config/hyde.php index 01b49eaa..66c41424 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -143,7 +143,7 @@ 'authors' => [ Author::create( username: 'mrhyde', // Required username - displayName: 'Mr. Hyde', // Optional display name + display_name: 'Mr. Hyde', // Optional display name website: 'https://hydephp.com' // Optional website URL ), ], diff --git a/src/Helpers/Author.php b/src/Helpers/Author.php index da3bf531..4215f6a5 100644 --- a/src/Helpers/Author.php +++ b/src/Helpers/Author.php @@ -6,10 +6,10 @@ class Author { - static function create(string $username, ?string $displayName = null, ?string $website = null): AuthorModel + static function create(string $username, ?string $display_name = null, ?string $website = null): AuthorModel { return new AuthorModel($username, [ - 'name' => $displayName, + 'name' => $display_name, 'website '=> $website ]); } From dc43c836adecb978fddf0cfd0a964714fff17a15 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 12:06:02 +0200 Subject: [PATCH 22/45] Sketch out the test class --- src/Helpers/Author.php | 3 +++ tests/Feature/AuthorHelperTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/Feature/AuthorHelperTest.php diff --git a/src/Helpers/Author.php b/src/Helpers/Author.php index 4215f6a5..aa09960b 100644 --- a/src/Helpers/Author.php +++ b/src/Helpers/Author.php @@ -4,6 +4,9 @@ use Hyde\Framework\Models\Author as AuthorModel; +/** + * @see \Tests\Feature\AuthorHelperTest + */ class Author { static function create(string $username, ?string $display_name = null, ?string $website = null): AuthorModel diff --git a/tests/Feature/AuthorHelperTest.php b/tests/Feature/AuthorHelperTest.php new file mode 100644 index 00000000..b7ba4fa7 --- /dev/null +++ b/tests/Feature/AuthorHelperTest.php @@ -0,0 +1,25 @@ + Date: Mon, 23 May 2022 12:06:54 +0200 Subject: [PATCH 23/45] Import classes --- tests/Feature/AuthorHelperTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Feature/AuthorHelperTest.php b/tests/Feature/AuthorHelperTest.php index b7ba4fa7..7f0ae0df 100644 --- a/tests/Feature/AuthorHelperTest.php +++ b/tests/Feature/AuthorHelperTest.php @@ -3,6 +3,10 @@ namespace Tests\Feature; use Tests\TestCase; +use Hyde\Framework\Helpers\Author as AuthorHelper; +use Hyde\Framework\Models\Author as AuthorModel; +use Illuminate\Support\Facades\Config; +use Illuminate\Support\Collection; /** * Class AuthorHelperTest. From 6c5261fa3804dbe65ad4ed81e423465b5cfd9ae8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 12:10:09 +0200 Subject: [PATCH 24/45] Fix whitespace typo in array key --- src/Helpers/Author.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Helpers/Author.php b/src/Helpers/Author.php index aa09960b..e7fd8131 100644 --- a/src/Helpers/Author.php +++ b/src/Helpers/Author.php @@ -13,7 +13,7 @@ static function create(string $username, ?string $display_name = null, ?string $ { return new AuthorModel($username, [ 'name' => $display_name, - 'website '=> $website + 'website'=> $website ]); } } \ No newline at end of file From cd379f7cf5a413bbb7e36715131efc443917dc1b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 12:12:52 +0200 Subject: [PATCH 25/45] Test creation of Author model --- tests/Feature/AuthorHelperTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/Feature/AuthorHelperTest.php b/tests/Feature/AuthorHelperTest.php index 7f0ae0df..57de46f3 100644 --- a/tests/Feature/AuthorHelperTest.php +++ b/tests/Feature/AuthorHelperTest.php @@ -16,8 +16,22 @@ class AuthorHelperTest extends TestCase { // Test create method creates new Author model + public function test_create_method_creates_new_author_model() + { + $author = AuthorHelper::create('mr_hyde'); + + $this->assertInstanceOf(AuthorModel::class, $author); + } // Test create method accepts all parameters + public function test_create_method_accepts_all_parameters() + { + $author = AuthorHelper::create('mr_hyde', 'Mr Hyde', 'https://mrhyde.com'); + + $this->assertEquals('mr_hyde', $author->username); + $this->assertEquals('Mr Hyde', $author->name); + $this->assertEquals('https://mrhyde.com', $author->website); + } // Test all method returns empty Collection if no Authors are set in config From 6b976acc62f061029c6818553311c36cc07f0c38 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 11:48:33 +0200 Subject: [PATCH 26/45] Sketch out the Author helper From 19213d6b7d4bbbb46878324dd810d2ace91e3bf9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 12:28:01 +0200 Subject: [PATCH 27/45] Add Author collection methods --- src/Helpers/Author.php | 6 ++++++ tests/Feature/AuthorHelperTest.php | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Helpers/Author.php b/src/Helpers/Author.php index e7fd8131..0f1052a6 100644 --- a/src/Helpers/Author.php +++ b/src/Helpers/Author.php @@ -3,6 +3,7 @@ namespace Hyde\Framework\Helpers; use Hyde\Framework\Models\Author as AuthorModel; +use Illuminate\Support\Collection; /** * @see \Tests\Feature\AuthorHelperTest @@ -16,4 +17,9 @@ static function create(string $username, ?string $display_name = null, ?string $ 'website'=> $website ]); } + + static function all(): Collection + { + return new Collection(config('authors', [])); + } } \ No newline at end of file diff --git a/tests/Feature/AuthorHelperTest.php b/tests/Feature/AuthorHelperTest.php index 57de46f3..f92fb12f 100644 --- a/tests/Feature/AuthorHelperTest.php +++ b/tests/Feature/AuthorHelperTest.php @@ -34,8 +34,27 @@ public function test_create_method_accepts_all_parameters() } // Test all method returns empty Collection if no Authors are set in config + public function test_all_method_returns_empty_collection_if_no_authors_are_set_in_config() + { + Config::set('authors', []); + $authors = AuthorHelper::all(); + + $this->assertInstanceOf(Collection::class, $authors); + $this->assertCount(0, $authors); + } // Test all method returns Collection with all Authors defined in config + public function test_all_method_returns_collection_with_all_authors_defined_in_config() + { + Config::set('authors', [ + AuthorHelper::create('mr_hyde') + ]); + $authors = AuthorHelper::all(); + + $this->assertInstanceOf(Collection::class, $authors); + $this->assertCount(1, $authors); + $this->assertEquals(AuthorHelper::create('mr_hyde'), $authors->first()); + } // Test get method returns config defined Author by username From c1990f6268f17ae3ea62b9703229fbef503edd94 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 12:31:38 +0200 Subject: [PATCH 28/45] Add get method to find Author in config --- src/Helpers/Author.php | 6 ++++++ tests/Feature/AuthorHelperTest.php | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Helpers/Author.php b/src/Helpers/Author.php index 0f1052a6..d82486de 100644 --- a/src/Helpers/Author.php +++ b/src/Helpers/Author.php @@ -22,4 +22,10 @@ static function all(): Collection { return new Collection(config('authors', [])); } + + static function get(string $username): AuthorModel + { + return static::all()->firstWhere('username', $username) + ?? static::create($username); + } } \ No newline at end of file diff --git a/tests/Feature/AuthorHelperTest.php b/tests/Feature/AuthorHelperTest.php index f92fb12f..0bf58356 100644 --- a/tests/Feature/AuthorHelperTest.php +++ b/tests/Feature/AuthorHelperTest.php @@ -57,6 +57,25 @@ public function test_all_method_returns_collection_with_all_authors_defined_in_c } // Test get method returns config defined Author by username + public function test_get_method_returns_config_defined_author_by_username() + { + Config::set('authors', [ + AuthorHelper::create('foo', 'bar') + ]); + $author = AuthorHelper::get('foo'); + + $this->assertInstanceOf(AuthorModel::class, $author); + $this->assertEquals('foo', $author->username); + $this->assertEquals('bar', $author->name); + } // Test get method returns new Author if username not found in config + public function test_get_method_returns_new_author_if_username_not_found_in_config() + { + Config::set('authors', []); + $author = AuthorHelper::get('foo'); + + $this->assertInstanceOf(AuthorModel::class, $author); + $this->assertEquals('foo', $author->username); + } } From f9b74943e76e820479ffc21237556522f8747b00 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 12:32:04 +0200 Subject: [PATCH 29/45] Set method visibility to public --- src/Helpers/Author.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Helpers/Author.php b/src/Helpers/Author.php index d82486de..f852220f 100644 --- a/src/Helpers/Author.php +++ b/src/Helpers/Author.php @@ -10,7 +10,7 @@ */ class Author { - static function create(string $username, ?string $display_name = null, ?string $website = null): AuthorModel + public static function create(string $username, ?string $display_name = null, ?string $website = null): AuthorModel { return new AuthorModel($username, [ 'name' => $display_name, @@ -18,12 +18,12 @@ static function create(string $username, ?string $display_name = null, ?string $ ]); } - static function all(): Collection + public static function all(): Collection { return new Collection(config('authors', [])); } - static function get(string $username): AuthorModel + public static function get(string $username): AuthorModel { return static::all()->firstWhere('username', $username) ?? static::create($username); From 11726a424f324441583a3483c9889cee333999fc Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 12:32:33 +0200 Subject: [PATCH 30/45] Remove Copilot comments --- tests/Feature/AuthorHelperTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/Feature/AuthorHelperTest.php b/tests/Feature/AuthorHelperTest.php index 0bf58356..f6de0ed2 100644 --- a/tests/Feature/AuthorHelperTest.php +++ b/tests/Feature/AuthorHelperTest.php @@ -15,7 +15,6 @@ */ class AuthorHelperTest extends TestCase { - // Test create method creates new Author model public function test_create_method_creates_new_author_model() { $author = AuthorHelper::create('mr_hyde'); @@ -23,7 +22,6 @@ public function test_create_method_creates_new_author_model() $this->assertInstanceOf(AuthorModel::class, $author); } - // Test create method accepts all parameters public function test_create_method_accepts_all_parameters() { $author = AuthorHelper::create('mr_hyde', 'Mr Hyde', 'https://mrhyde.com'); @@ -33,7 +31,6 @@ public function test_create_method_accepts_all_parameters() $this->assertEquals('https://mrhyde.com', $author->website); } - // Test all method returns empty Collection if no Authors are set in config public function test_all_method_returns_empty_collection_if_no_authors_are_set_in_config() { Config::set('authors', []); @@ -43,7 +40,6 @@ public function test_all_method_returns_empty_collection_if_no_authors_are_set_i $this->assertCount(0, $authors); } - // Test all method returns Collection with all Authors defined in config public function test_all_method_returns_collection_with_all_authors_defined_in_config() { Config::set('authors', [ @@ -56,7 +52,6 @@ public function test_all_method_returns_collection_with_all_authors_defined_in_c $this->assertEquals(AuthorHelper::create('mr_hyde'), $authors->first()); } - // Test get method returns config defined Author by username public function test_get_method_returns_config_defined_author_by_username() { Config::set('authors', [ @@ -69,7 +64,6 @@ public function test_get_method_returns_config_defined_author_by_username() $this->assertEquals('bar', $author->name); } - // Test get method returns new Author if username not found in config public function test_get_method_returns_new_author_if_username_not_found_in_config() { Config::set('authors', []); From 99fbdab58601f3d8e2db74c0b8b7df08a8ed6e4b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 12:33:00 +0200 Subject: [PATCH 31/45] Clean up test code --- tests/Feature/AuthorHelperTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/Feature/AuthorHelperTest.php b/tests/Feature/AuthorHelperTest.php index f6de0ed2..3c66dacd 100644 --- a/tests/Feature/AuthorHelperTest.php +++ b/tests/Feature/AuthorHelperTest.php @@ -17,18 +17,18 @@ class AuthorHelperTest extends TestCase { public function test_create_method_creates_new_author_model() { - $author = AuthorHelper::create('mr_hyde'); + $author = AuthorHelper::create('foo'); $this->assertInstanceOf(AuthorModel::class, $author); } public function test_create_method_accepts_all_parameters() { - $author = AuthorHelper::create('mr_hyde', 'Mr Hyde', 'https://mrhyde.com'); + $author = AuthorHelper::create('foo', 'bar', 'https://example.com'); - $this->assertEquals('mr_hyde', $author->username); - $this->assertEquals('Mr Hyde', $author->name); - $this->assertEquals('https://mrhyde.com', $author->website); + $this->assertEquals('foo', $author->username); + $this->assertEquals('bar', $author->name); + $this->assertEquals('https://example.com', $author->website); } public function test_all_method_returns_empty_collection_if_no_authors_are_set_in_config() @@ -43,13 +43,13 @@ public function test_all_method_returns_empty_collection_if_no_authors_are_set_i public function test_all_method_returns_collection_with_all_authors_defined_in_config() { Config::set('authors', [ - AuthorHelper::create('mr_hyde') + AuthorHelper::create('foo') ]); $authors = AuthorHelper::all(); $this->assertInstanceOf(Collection::class, $authors); $this->assertCount(1, $authors); - $this->assertEquals(AuthorHelper::create('mr_hyde'), $authors->first()); + $this->assertEquals(AuthorHelper::create('foo'), $authors->first()); } public function test_get_method_returns_config_defined_author_by_username() From fa6c3bf49b4ae8da31ff47ec0b47f509c6175397 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 12:35:26 +0200 Subject: [PATCH 32/45] Update PHPDoc comments --- src/Models/Author.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Models/Author.php b/src/Models/Author.php index 621187ff..e7ee41d9 100644 --- a/src/Models/Author.php +++ b/src/Models/Author.php @@ -4,13 +4,12 @@ /** * The Post Author Object Model. - * - * The Author is parsed from the config/authors.yml file using the AuthorService class */ class Author { /** - * The username (slug) of the author. + * The username of the author. + * This is the key used to find authors in the config * * @var string */ @@ -49,7 +48,7 @@ public function __construct(string $username, ?array $data = []) } /** - * Get the author's name. + * Get the author's preferred name. * * @see \Tests\Unit\AuthorGetNameTest * From ab6cafc6fb69beca5061e4de4787eea954b1dac4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 12:38:13 +0200 Subject: [PATCH 33/45] Add information to PHPDoc as to why an array is used --- src/Models/Author.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Models/Author.php b/src/Models/Author.php index e7ee41d9..b2ed1d2e 100644 --- a/src/Models/Author.php +++ b/src/Models/Author.php @@ -33,6 +33,11 @@ class Author public ?string $website = null; /** + * Construct a new Author object. + * + * Parameters are supplied through an array to make it + * easy to load data from Markdown post front matter. + * * @param string $username * @param array|null $data */ From 5b56e9b0f89b38adb5aa4a64f7e9899da6e5df7d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 12:39:51 +0200 Subject: [PATCH 34/45] Deprecate AuthorService --- src/Services/AuthorService.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Services/AuthorService.php b/src/Services/AuthorService.php index 9efacf51..a5d0f88c 100644 --- a/src/Services/AuthorService.php +++ b/src/Services/AuthorService.php @@ -10,6 +10,9 @@ /** * Contains service methods relating to blog post authors. + * + * @deprecated version 0.28.0 as the new Author system + * is now simple enough as to not warrant a service class. * * The YAML service is deprecated, the data will be * fetched from the main config instead. From c4fdddb015a2df5da982246cb071235c4498799f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 12:42:18 +0200 Subject: [PATCH 35/45] Add inline documentation --- src/Concerns/HasAuthor.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Concerns/HasAuthor.php b/src/Concerns/HasAuthor.php index 13b2897a..c540cc76 100644 --- a/src/Concerns/HasAuthor.php +++ b/src/Concerns/HasAuthor.php @@ -19,9 +19,14 @@ public function constructAuthor(): void { if (isset($this->matter['author'])) { if (is_string($this->matter['author'])) { + // If the author is a string, we assume it's a username + // and we'll try to find the author in the config $this->author = $this->findAuthor($this->matter['author']); } if (is_array($this->matter['author'])) { + // If the author is an array, we'll assume it's a user + // with one-off custom data, so we create a new author. + // In the future we may want to merge config data with custom data $this->author = $this->createAuthor($this->matter['author']); } } From 2204832ee2ed965d89a540a3c7f28520ee6feea6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 12:44:20 +0200 Subject: [PATCH 36/45] Use the new helper in the findAuthor method --- src/Concerns/HasAuthor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Concerns/HasAuthor.php b/src/Concerns/HasAuthor.php index c540cc76..97966aa3 100644 --- a/src/Concerns/HasAuthor.php +++ b/src/Concerns/HasAuthor.php @@ -3,7 +3,7 @@ namespace Hyde\Framework\Concerns; use Hyde\Framework\Models\Author; -use Hyde\Framework\Services\AuthorService; +use Hyde\Framework\Helpers\Author as AuthorHelper; /** * Handle logic for Page models that have an Author. @@ -34,7 +34,7 @@ public function constructAuthor(): void protected function findAuthor(string $author): Author { - return AuthorService::find($author) ?: new Author($author); + return AuthorHelper::get($author); } protected function createAuthor(array $data): Author From ba4344d2a40944b078291cb5d5c25e370d25876e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 12:48:28 +0200 Subject: [PATCH 37/45] Add helper to remove dependency on AuthorService --- src/Concerns/GeneratesPageMetadata.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Concerns/GeneratesPageMetadata.php b/src/Concerns/GeneratesPageMetadata.php index 3f9ce252..07e37fd7 100644 --- a/src/Concerns/GeneratesPageMetadata.php +++ b/src/Concerns/GeneratesPageMetadata.php @@ -4,7 +4,6 @@ use Hyde\Framework\Hyde; use Hyde\Framework\Models\MarkdownPost; -use Hyde\Framework\Services\AuthorService; use Tests\TestCase; /** @@ -48,7 +47,7 @@ protected function parseFrontMatterMetadata(): void } if (isset($this->matter['author'])) { - $this->metadata['author'] = AuthorService::getAuthorName($this->matter['author']); + $this->metadata['author'] = $this->getAuthorName($this->matter['author']); } if (isset($this->matter['category'])) { @@ -87,4 +86,20 @@ protected function makeOpenGraphPropertiesForArticle(): void } } } + + + /** + * Parse the author name string from front matter with support for both flat and array notation. + * + * @param string|array $author + * @return string + */ + protected function getAuthorName(string|array $author): string + { + if (is_string($author)) { + return $author; + } + + return $author['name'] ?? $author['username'] ?? 'Guest'; + } } From 9f9d64dc4f232e6c0a695088cd43dc28f8535fc3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 12:57:43 +0200 Subject: [PATCH 38/45] Remove AuthorService --- src/Services/AuthorService.php | 142 ------------------- tests/Feature/AuthorPostsIntegrationTest.php | 60 ++------ tests/Feature/AuthorServiceTest.php | 141 ------------------ 3 files changed, 11 insertions(+), 332 deletions(-) delete mode 100644 src/Services/AuthorService.php delete mode 100644 tests/Feature/AuthorServiceTest.php diff --git a/src/Services/AuthorService.php b/src/Services/AuthorService.php deleted file mode 100644 index a5d0f88c..00000000 --- a/src/Services/AuthorService.php +++ /dev/null @@ -1,142 +0,0 @@ -filepath = Hyde::path('config/authors.yml'); - - if (file_exists($this->filepath)) { - $this->yaml = $this->getYaml(); - $this->authors = $this->getAuthors(); - } else { - $this->authors = new Collection(); - } - } - - /** - * Returns the filepath of the Yaml file. - * - * If the file does not exist, it will be created. - * - * @deprecated version 0.28.0 - */ - public function publishFile(): void - { - file_put_contents($this->filepath, <<<'EOF' -# Note that this file is deprecated. You'll be able to -# define authors using the Author facade in the config - -# In this file you can declare custom authors. - -# In the default example, `mr_hyde` is the username. -# When setting the author to mr_hyde in a blog post, -# the data in the array will automatically be added. - -authors: - mr_hyde: - name: Mr Hyde - website: https://github.com/hydephp/hyde -EOF - ); - } - - /** - * Parse the Yaml file. - * - * @deprecated version 0.28.0 - * - * @return array - */ - public function getYaml(): array - { - if (! file_exists($this->filepath)) { - return []; - } - $parsed = Yaml::parse(file_get_contents($this->filepath)); - if (! is_array($parsed)) { - return []; - } - - return $parsed; - } - - /** - * Use the Yaml array to parse and collect the Authors. - * - * @return Collection - */ - public function getAuthors(): Collection - { - $collection = new Collection(); - - if (isset($this->yaml['authors'])) { - foreach ($this->yaml['authors'] as $username => $data) { - $collection->push(new Author($username, $data)); - } - } - - return $collection; - } - - /** - * Find and retrieve an Author by their username. - * - * @param string $username of the Author to search for - * @param bool $forgiving should the search be fuzzy? - * @return Author|false - */ - public static function find(string $username, bool $forgiving = true): Author|false - { - $service = new self; - if ($forgiving) { - $username = Str::snake($username); - } - - return $service->authors->firstWhere('username', $username) ?? false; - } - - /** - * Parse the author name string from front matter with support for both flat and array notation. - * - * @param string|array $author - * @return string - */ - public static function getAuthorName(string|array $author): string - { - if (is_string($author)) { - return $author; - } - - return $author['name'] ?? $author['username'] ?? 'Guest'; - } -} diff --git a/tests/Feature/AuthorPostsIntegrationTest.php b/tests/Feature/AuthorPostsIntegrationTest.php index c59b7552..96eb4863 100644 --- a/tests/Feature/AuthorPostsIntegrationTest.php +++ b/tests/Feature/AuthorPostsIntegrationTest.php @@ -3,7 +3,9 @@ namespace Tests\Feature; use Hyde\Framework\Actions\CreatesNewMarkdownPostFile; +use Hyde\Framework\Helpers\Author; use Hyde\Framework\Hyde; +use Illuminate\Support\Facades\Config; use Tests\TestCase; /** @@ -15,22 +17,11 @@ */ class AuthorPostsIntegrationTest extends TestCase { - /** - * Set up the test environment. - * - * @return void - */ - public function test_setup_integration_test_environment() + protected function setUp(): void { - // If an authors.yml file exists, back it up. - if (file_exists(Hyde::path('config/authors.yml')) && ! file_exists(Hyde::path('config/authors.yml.bak'))) { - copy(Hyde::path('config/authors.yml'), Hyde::path('config/authors.yml.bak')); - } - - // Create a new authors.yml file. - file_put_contents(Hyde::path('config/authors.yml'), "authors:\n"); + parent::setUp(); - $this->assertTrue(true); + Config::set('authors', []); } /** @@ -86,13 +77,9 @@ public function test_create_post_with_defined_author_with_name() // Check that the post was created $this->assertFileExists(Hyde::path('_posts/test-2dcbb2c-post-with-defined-author-with-name.md')); - // Add the author to the authors.yml file - file_put_contents( - Hyde::path('config/authors.yml'), - 'authors: - test_named_author: - name: Test Author' - ); + Config::set('authors', [ + Author::create('test_named_author', 'Test Author') + ]); // Check that the post was created $this->assertFileExists(Hyde::path('_posts/test-2dcbb2c-post-with-defined-author-with-name.md')); @@ -128,15 +115,9 @@ public function test_create_post_with_defined_author_with_website() // Check that the post was created $this->assertFileExists(Hyde::path('_posts/test-2dcbb2c-post-with-defined-author-with-name.md')); - // Add the author to the authors.yml file - file_put_contents( - Hyde::path('config/authors.yml'), - 'authors: - test_author_with_website: - name: Test Author - website: https://example.org -' - ); + Config::set('authors', [ + Author::create('test_author_with_website', 'Test Author', 'https://example.org') + ]); // Check that the post was created $this->assertFileExists(Hyde::path('_posts/test-2dcbb2c-post-with-defined-author-with-name.md')); @@ -161,23 +142,4 @@ public function test_create_post_with_defined_author_with_website() unlink(Hyde::path('_posts/test-2dcbb2c-post-with-defined-author-with-name.md')); unlink(Hyde::path('_site/posts/test-2dcbb2c-post-with-defined-author-with-name.html')); } - - /** - * Tear down the test environment. - * - * @return void - */ - public function test_teardown_integration_test_environment() - { - // Remove the test authors.yml file. - unlink(Hyde::path('config/authors.yml')); - - // If an authors.yml backup exists, restore it. - if (file_exists(Hyde::path('config/authors.yml.bak'))) { - copy(Hyde::path('config/authors.yml.bak'), Hyde::path('config/authors.yml')); - unlink(Hyde::path('config/authors.yml.bak')); - } - - $this->assertTrue(true); - } } diff --git a/tests/Feature/AuthorServiceTest.php b/tests/Feature/AuthorServiceTest.php deleted file mode 100644 index 22642f56..00000000 --- a/tests/Feature/AuthorServiceTest.php +++ /dev/null @@ -1,141 +0,0 @@ -filepath; - - backup($path); - unlinkIfExists($path); - } - - protected function tearDown(): void - { - parent::tearDown(); - - // Clean up any test files - $service = new AuthorService(); - $path = $service->filepath; - unlinkIfExists($path); - - // Restore the original authors.yml file - - restore($path); - } - - public function test_publish_file_creates_file() - { - $service = new AuthorService(); - $path = $service->filepath; - - if (file_exists($path)) { - unlink($path); - } - - $service->publishFile(); - $this->assertFileExists($path); - } - - public function test_get_authors_returns_author_collection() - { - (new AuthorService)->publishFile(); - $service = new AuthorService(); - - $collection = $service->authors; - - $this->assertInstanceOf(Collection::class, $collection); - - $author = $collection->first(); - - $this->assertInstanceOf(Author::class, $author); - - $this->assertEquals('mr_hyde', $author->username); - $this->assertEquals('Mr Hyde', $author->name); - $this->assertEquals('https://github.com/hydephp/hyde', $author->website); - } - - public function test_can_find_author_by_username() - { - $service = new AuthorService(); - $service->publishFile(); - - $author = AuthorService::find('mr_hyde'); - - $this->assertInstanceOf(Author::class, $author); - - $this->assertEquals('mr_hyde', $author->username); - $this->assertEquals('Mr Hyde', $author->name); - $this->assertEquals('https://github.com/hydephp/hyde', $author->website); - } - - public function test_get_yaml_can_parse_file() - { - $service = new AuthorService(); - - $service->publishFile(); - - $array = $service->getYaml(); - - $this->assertIsArray($array); - - $this->assertEquals([ - 'authors' => [ - 'mr_hyde' => [ - 'name' => 'Mr Hyde', - 'website' => 'https://github.com/hydephp/hyde', - ], - ], - ], $array); - } - - public function test_find_method_returns_false_if_no_author_is_found() - { - $this->assertFalse(AuthorService::find('undefined_author')); - } - - public function test_get_yaml_method_returns_empty_array_if_file_does_not_exist() - { - $service = new AuthorService(); - $this->assertFileDoesNotExist($service->filepath); - $this->assertEquals([], $service->getYaml()); - } - - public function test_get_yaml_method_returns_empty_array_if_file_does_not_contain_valid_yaml() - { - $service = new AuthorService(); - file_put_contents($service->filepath, 'invalid yaml'); - - $this->assertEquals([], $service->getYaml()); - } - - public function test_get_author_name_helper_returns_string_for_string() - { - $this->assertEquals('foo', AuthorService::getAuthorName('foo')); - } - - public function test_get_author_name_helper_returns_string_for_array() - { - $this->assertEquals('foo', AuthorService::getAuthorName(['name' => 'foo'])); - } - - public function test_get_author_name_helper_returns_string_for_array_with_proper_fallback_priorities() - { - $this->assertEquals('foo', AuthorService::getAuthorName(['name' => 'foo', 'username' => 'bar'])); - $this->assertEquals('bar', AuthorService::getAuthorName(['username' => 'bar'])); - $this->assertEquals('Guest', AuthorService::getAuthorName([])); - } -} From 990dcfc5cd6531177e197fc83386d679e5ec561c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 13:08:37 +0200 Subject: [PATCH 39/45] Finalize removal of authors.yml --- .github/dev-docs/RELEASE-NOTES-DRAFT.md | 2 +- .github/dev-docs/blog-posts.md | 6 +++--- tests/Feature/AuthorPostsIntegrationTest.php | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/dev-docs/RELEASE-NOTES-DRAFT.md b/.github/dev-docs/RELEASE-NOTES-DRAFT.md index 9292cf17..c07343af 100644 --- a/.github/dev-docs/RELEASE-NOTES-DRAFT.md +++ b/.github/dev-docs/RELEASE-NOTES-DRAFT.md @@ -25,4 +25,4 @@ The deprecated option named `hyde.docs_directory` has been removed. Use `docs.output_directory` instead. -The authors.yml has been deprecated, and will be refactored in an upcoming release. \ No newline at end of file +The authors.yml and related services have been removed. Define authors in the main Hyde config instead. \ No newline at end of file diff --git a/.github/dev-docs/blog-posts.md b/.github/dev-docs/blog-posts.md index 88eba597..8846ab31 100644 --- a/.github/dev-docs/blog-posts.md +++ b/.github/dev-docs/blog-posts.md @@ -172,16 +172,16 @@ date: "2022-01-01" ```yaml author: "Mr. Hyde" # Arbitrary name displayed "as is" -author: mr_hyde # Username defined in `authors.yml` config +author: mr_hyde # Username defined in `authors` config author: # Array of author data name: "Mr. Hyde" username: mr_hyde - website: https://mrhyde.example.com + website: https://twitter.com/hyde_php ``` When specifying an array you don't need all the sub-properties. The example just shows all the supported values. Array values here -will override the values in the `authors.yml` config. +will override all the values in the `authors` config entry. ### Image diff --git a/tests/Feature/AuthorPostsIntegrationTest.php b/tests/Feature/AuthorPostsIntegrationTest.php index 96eb4863..16009d59 100644 --- a/tests/Feature/AuthorPostsIntegrationTest.php +++ b/tests/Feature/AuthorPostsIntegrationTest.php @@ -9,10 +9,9 @@ use Tests\TestCase; /** - * Test that the config/authors.yml feature works in + * Test that the Author feature works in * conjunction with the static Post generator. * - * @see AuthorServiceTest * @see StaticSiteBuilderPostModuleTest */ class AuthorPostsIntegrationTest extends TestCase From 1660ce351892fce5c5e92a8ff167aa4cdb186d04 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 23 May 2022 11:08:49 +0000 Subject: [PATCH 40/45] Apply fixes from StyleCI --- config/hyde.php | 4 +-- src/Concerns/GeneratesPageMetadata.php | 1 - src/Concerns/HasAuthor.php | 2 +- src/Helpers/Author.php | 34 ++++++++++---------- src/Helpers/Image.php | 10 +++--- src/Models/Author.php | 4 +-- tests/Feature/AuthorHelperTest.php | 10 +++--- tests/Feature/AuthorPostsIntegrationTest.php | 4 +-- 8 files changed, 34 insertions(+), 35 deletions(-) diff --git a/config/hyde.php b/config/hyde.php index 66c41424..1ec705c9 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -132,12 +132,12 @@ | Hyde has support for adding authors in front matter, for example to | automatically add a link to your website or social media profiles. | However, it's tedious to have to add those to each and every - | post you make, and keeping them updated is even harder. + | post you make, and keeping them updated is even harder. | | Here you can add predefined authors. When writing posts, | just specify the username in the front matter, and the | rest of the data will be pulled from a matching entry. - | + | */ 'authors' => [ diff --git a/src/Concerns/GeneratesPageMetadata.php b/src/Concerns/GeneratesPageMetadata.php index 07e37fd7..628d9b21 100644 --- a/src/Concerns/GeneratesPageMetadata.php +++ b/src/Concerns/GeneratesPageMetadata.php @@ -87,7 +87,6 @@ protected function makeOpenGraphPropertiesForArticle(): void } } - /** * Parse the author name string from front matter with support for both flat and array notation. * diff --git a/src/Concerns/HasAuthor.php b/src/Concerns/HasAuthor.php index 97966aa3..9de225ac 100644 --- a/src/Concerns/HasAuthor.php +++ b/src/Concerns/HasAuthor.php @@ -2,8 +2,8 @@ namespace Hyde\Framework\Concerns; -use Hyde\Framework\Models\Author; use Hyde\Framework\Helpers\Author as AuthorHelper; +use Hyde\Framework\Models\Author; /** * Handle logic for Page models that have an Author. diff --git a/src/Helpers/Author.php b/src/Helpers/Author.php index f852220f..36d0dcc6 100644 --- a/src/Helpers/Author.php +++ b/src/Helpers/Author.php @@ -10,22 +10,22 @@ */ class Author { - public static function create(string $username, ?string $display_name = null, ?string $website = null): AuthorModel - { - return new AuthorModel($username, [ - 'name' => $display_name, - 'website'=> $website - ]); - } + public static function create(string $username, ?string $display_name = null, ?string $website = null): AuthorModel + { + return new AuthorModel($username, [ + 'name' => $display_name, + 'website'=> $website, + ]); + } - public static function all(): Collection - { - return new Collection(config('authors', [])); - } + public static function all(): Collection + { + return new Collection(config('authors', [])); + } - public static function get(string $username): AuthorModel - { - return static::all()->firstWhere('username', $username) - ?? static::create($username); - } -} \ No newline at end of file + public static function get(string $username): AuthorModel + { + return static::all()->firstWhere('username', $username) + ?? static::create($username); + } +} diff --git a/src/Helpers/Image.php b/src/Helpers/Image.php index dc7c46a3..51832a11 100644 --- a/src/Helpers/Image.php +++ b/src/Helpers/Image.php @@ -4,8 +4,8 @@ class Image { - public static function get(string $path): string - { - return $path; - } -} \ No newline at end of file + public static function get(string $path): string + { + return $path; + } +} diff --git a/src/Models/Author.php b/src/Models/Author.php index b2ed1d2e..85c150ed 100644 --- a/src/Models/Author.php +++ b/src/Models/Author.php @@ -9,7 +9,7 @@ class Author { /** * The username of the author. - * This is the key used to find authors in the config + * This is the key used to find authors in the config. * * @var string */ @@ -34,7 +34,7 @@ class Author /** * Construct a new Author object. - * + * * Parameters are supplied through an array to make it * easy to load data from Markdown post front matter. * diff --git a/tests/Feature/AuthorHelperTest.php b/tests/Feature/AuthorHelperTest.php index 3c66dacd..e9252f55 100644 --- a/tests/Feature/AuthorHelperTest.php +++ b/tests/Feature/AuthorHelperTest.php @@ -2,11 +2,11 @@ namespace Tests\Feature; -use Tests\TestCase; use Hyde\Framework\Helpers\Author as AuthorHelper; use Hyde\Framework\Models\Author as AuthorModel; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Config; +use Tests\TestCase; /** * Class AuthorHelperTest. @@ -30,7 +30,7 @@ public function test_create_method_accepts_all_parameters() $this->assertEquals('bar', $author->name); $this->assertEquals('https://example.com', $author->website); } - + public function test_all_method_returns_empty_collection_if_no_authors_are_set_in_config() { Config::set('authors', []); @@ -43,7 +43,7 @@ public function test_all_method_returns_empty_collection_if_no_authors_are_set_i public function test_all_method_returns_collection_with_all_authors_defined_in_config() { Config::set('authors', [ - AuthorHelper::create('foo') + AuthorHelper::create('foo'), ]); $authors = AuthorHelper::all(); @@ -55,7 +55,7 @@ public function test_all_method_returns_collection_with_all_authors_defined_in_c public function test_get_method_returns_config_defined_author_by_username() { Config::set('authors', [ - AuthorHelper::create('foo', 'bar') + AuthorHelper::create('foo', 'bar'), ]); $author = AuthorHelper::get('foo'); diff --git a/tests/Feature/AuthorPostsIntegrationTest.php b/tests/Feature/AuthorPostsIntegrationTest.php index 16009d59..8e8ba730 100644 --- a/tests/Feature/AuthorPostsIntegrationTest.php +++ b/tests/Feature/AuthorPostsIntegrationTest.php @@ -77,7 +77,7 @@ public function test_create_post_with_defined_author_with_name() $this->assertFileExists(Hyde::path('_posts/test-2dcbb2c-post-with-defined-author-with-name.md')); Config::set('authors', [ - Author::create('test_named_author', 'Test Author') + Author::create('test_named_author', 'Test Author'), ]); // Check that the post was created @@ -115,7 +115,7 @@ public function test_create_post_with_defined_author_with_website() $this->assertFileExists(Hyde::path('_posts/test-2dcbb2c-post-with-defined-author-with-name.md')); Config::set('authors', [ - Author::create('test_author_with_website', 'Test Author', 'https://example.org') + Author::create('test_author_with_website', 'Test Author', 'https://example.org'), ]); // Check that the post was created From b6dcd63064c8ff13c1723dc1c64bb0f5d1d117ec Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 13:12:06 +0200 Subject: [PATCH 41/45] Add underscore to sample name --- config/hyde.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/hyde.php b/config/hyde.php index 66c41424..d3d57f8c 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -142,7 +142,7 @@ 'authors' => [ Author::create( - username: 'mrhyde', // Required username + username: 'mr_hyde', // Required username display_name: 'Mr. Hyde', // Optional display name website: 'https://hydephp.com' // Optional website URL ), From 359fd07162e27f193ec5bd4c7bc7bed11946c5e3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 13:14:10 +0200 Subject: [PATCH 42/45] Add exxtra test case for multiple authors --- tests/Feature/AuthorHelperTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/Feature/AuthorHelperTest.php b/tests/Feature/AuthorHelperTest.php index 3c66dacd..957e41cb 100644 --- a/tests/Feature/AuthorHelperTest.php +++ b/tests/Feature/AuthorHelperTest.php @@ -52,6 +52,20 @@ public function test_all_method_returns_collection_with_all_authors_defined_in_c $this->assertEquals(AuthorHelper::create('foo'), $authors->first()); } + public function test_multiple_authors_can_be_defined_in_config() + { + Config::set('authors', [ + AuthorHelper::create('foo'), + AuthorHelper::create('bar'), + ]); + $authors = AuthorHelper::all(); + + $this->assertInstanceOf(Collection::class, $authors); + $this->assertCount(2, $authors); + $this->assertEquals(AuthorHelper::create('foo'), $authors->first()); + $this->assertEquals(AuthorHelper::create('bar'), $authors->last()); + } + public function test_get_method_returns_config_defined_author_by_username() { Config::set('authors', [ From ba7c2ccdb2898383ac1e23c8b2c09ab4290fda7c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 13:18:20 +0200 Subject: [PATCH 43/45] Change display_name to name to match front matter --- config/hyde.php | 2 +- src/Helpers/Author.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/hyde.php b/config/hyde.php index 4329c6ce..3e522d77 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -143,7 +143,7 @@ 'authors' => [ Author::create( username: 'mr_hyde', // Required username - display_name: 'Mr. Hyde', // Optional display name + name: 'Mr. Hyde', // Optional display name website: 'https://hydephp.com' // Optional website URL ), ], diff --git a/src/Helpers/Author.php b/src/Helpers/Author.php index 36d0dcc6..e4a647a1 100644 --- a/src/Helpers/Author.php +++ b/src/Helpers/Author.php @@ -10,10 +10,10 @@ */ class Author { - public static function create(string $username, ?string $display_name = null, ?string $website = null): AuthorModel + public static function create(string $username, ?string $name = null, ?string $website = null): AuthorModel { return new AuthorModel($username, [ - 'name' => $display_name, + 'name' => $name, 'website'=> $website, ]); } From a58408fb436f2b3ec31902173f1f40a5ae63aaa4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 13:21:50 +0200 Subject: [PATCH 44/45] Update Author config documentation --- .github/dev-docs/customization.md | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/.github/dev-docs/customization.md b/.github/dev-docs/customization.md index 975167f4..fb5a3d7a 100644 --- a/.github/dev-docs/customization.md +++ b/.github/dev-docs/customization.md @@ -31,6 +31,41 @@ With a concept directly inspired by [Laravel Jetstream](https://jetstream.larave ], ``` +### Authors +Hyde has support for adding authors in front matter, for example to +automatically add a link to your website or social media profiles. +However, it's tedious to have to add those to each and every +post you make, and keeping them updated is even harder. + +You can predefine authors in the Hyde config. +When writing posts, just specify the username in the front matter, +and the rest of the data will be pulled from a matching entry. + +#### Example +// torchlight! {"lineNumbers": false} +```php +'authors' => [ + Author::create( + username: 'mr_hyde', // Required username + name: 'Mr. Hyde', // Optional display name + website: 'https://hydephp.com' // Optional website URL + ), +], +``` + +This is equivalent to the following front matter: +```yaml +author: + username: mr_hyde + name: Mr. Hyde + website: https://hydephp.com +``` + +But you only have to specify the username: +```yaml +author: mr_hyde +``` + ### Footer The footer can be customized using Markdown, and even disabled completely. From 65c15360ece2f9258538a56c1ccd79a715845c1d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 23 May 2022 13:29:37 +0200 Subject: [PATCH 45/45] Update RELEASE-NOTES-DRAFT.md --- .github/dev-docs/RELEASE-NOTES-DRAFT.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/dev-docs/RELEASE-NOTES-DRAFT.md b/.github/dev-docs/RELEASE-NOTES-DRAFT.md index c07343af..185e7750 100644 --- a/.github/dev-docs/RELEASE-NOTES-DRAFT.md +++ b/.github/dev-docs/RELEASE-NOTES-DRAFT.md @@ -1,5 +1,9 @@ # Draft for the release notes of upcoming HydePHP versions +--- + +# v0.28.0-beta - Refactor configuration files + ## Changes to the configuration files The entire configuration system has been refactored. @@ -18,6 +22,9 @@ to update the codebase: `hyde.docs_sidebar_header_title` => `docs.header_title` +### Authors.yml has been removed + +The authors.yml and related services have been removed. Define authors in the main Hyde config instead. ### Deprecations and removals @@ -25,4 +32,9 @@ The deprecated option named `hyde.docs_directory` has been removed. Use `docs.output_directory` instead. -The authors.yml and related services have been removed. Define authors in the main Hyde config instead. \ No newline at end of file +## What's Changed +* Refactor configuration to use snake_case for all options, and extract documentation settings to own file by @caendesilva in https://github.com/hydephp/framework/pull/444 +* Refactor author configuration system by @caendesilva in https://github.com/hydephp/framework/pull/449 + + +**Full Changelog**: https://github.com/hydephp/framework/compare/v0.27.12-beta...v0.28.0-beta \ No newline at end of file