Skip to content

Commit cca9662

Browse files
authored
Merge pull request #487 from hydephp/breaking-page-refactors
Merge getCurrentPagePath method into getRouteKey
2 parents c6d817e + d6e1ca7 commit cca9662

File tree

11 files changed

+22
-29
lines changed

11 files changed

+22
-29
lines changed

RELEASE_NOTES.md

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ In general, these changes should only affect those who have written custom code
2323
- Moved class NavItem into Navigation namespace
2424
- Moved class FindsContentLengthForImageObject into Constructors namespace
2525
- Merged interface RouteFacadeContract into existing interface RouteContract
26+
- Merged `getCurrentPagePath()` method into existing `getRouteKey()` method in PageContract and AbstractPage
2627
- Renamed HydeBuildStaticSiteCommand to HydeBuildSiteCommand
2728
- Renamed legacy FileCacheService to ViewDiffService
2829
- Renamed method `Hyde::getSiteOutputPath()` to `Hyde::sitePath()`
@@ -41,6 +42,8 @@ In general, these changes should only affect those who have written custom code
4142
- Removed deprecated and unused abstract class ActionCommand
4243
- Removed unused function `array_map_unique`
4344
- Removed interface RouteFacadeContract (merged into existing RouteContract)
45+
- Removed method `PageContract::getCurrentPagePath()` (merged into `getRouteKey()` in the same class)
46+
- Removed method `AbstractPage::getCurrentPagePath()` (merged into `getRouteKey()` in the same class)
4447
- Using absolute paths for site output directories is no longer supported (use build tasks to move files around after build if needed)
4548

4649
### Fixed

packages/framework/resources/views/pages/documentation-search.blade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@php
22
// Emulate a page object
33
$page = Hyde\Framework\Models\Pages\DocumentationPage::make('search', ['title' => 'Search']);
4-
$currentPage = $page->getCurrentPagePath();
4+
$currentPage = $page->getRouteKey();
55
$currentRoute = $page->getRoute();
66
$markdown = '';
77
@endphp

packages/framework/src/Actions/StaticPageBuilder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(protected AbstractPage|PageContract $page, bool $sel
4040
public function __invoke(): string
4141
{
4242
view()->share('page', $this->page);
43-
view()->share('currentPage', $this->page->getCurrentPagePath());
43+
view()->share('currentPage', $this->page->getRouteKey());
4444
view()->share('currentRoute', $this->page->getRoute());
4545

4646
$this->needsDirectory(Hyde::sitePath());

packages/framework/src/Concerns/AbstractPage.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ abstract class AbstractPage implements PageContract, CompilableContract, PageSch
5151
public function __construct(string $identifier = '', FrontMatter|array $matter = [])
5252
{
5353
$this->identifier = $identifier;
54-
$this->routeKey = $this->getCurrentPagePath();
54+
$this->routeKey = trim(static::getOutputDirectory().'/'.$this->identifier, '/');
5555

5656
$this->matter = $matter instanceof FrontMatter ? $matter : new FrontMatter($matter);
5757
$this->constructPageSchemas();
@@ -151,13 +151,7 @@ public function getSourcePath(): string
151151
/** @inheritDoc */
152152
public function getOutputPath(): string
153153
{
154-
return $this->getCurrentPagePath().'.html';
155-
}
156-
157-
/** @inheritDoc */
158-
public function getCurrentPagePath(): string
159-
{
160-
return trim(static::getOutputDirectory().'/'.$this->identifier, '/');
154+
return $this->getRouteKey().'.html';
161155
}
162156

163157
/** @inheritDoc */

packages/framework/src/Contracts/PageContract.php

+6-10
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,15 @@ public function getSourcePath(): string;
120120
public function getOutputPath(): string;
121121

122122
/**
123-
* Get the URI path relative to the site root.
123+
* Get the route key for the page.
124124
*
125-
* @example if the compiled page will be saved to _site/docs/index.html,
126-
* then this method will return 'docs/index'
125+
* The route key is the URI path relative to the site root.
127126
*
128-
* @return string URI path relative to the site root.
129-
*/
130-
public function getCurrentPagePath(): string;
131-
132-
/**
133-
* Get the route key for the page.
127+
* For example, if the compiled page will be saved to _site/docs/index.html,
128+
* then this method will return 'docs/index'. Route keys are used to
129+
* identify pages, similar to how named routes work in Laravel.
134130
*
135-
* @return string
131+
* @return string URI path relative to the site root.
136132
*/
137133
public function getRouteKey(): string;
138134

packages/framework/src/Models/Pages/DocumentationPage.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(string $identifier = '', ?FrontMatter $matter = null
3535
}
3636

3737
/** @inheritDoc */
38-
public function getCurrentPagePath(): string
38+
public function getRouteKey(): string
3939
{
4040
return trim(static::getOutputDirectory().'/'.basename($this->identifier), '/');
4141
}

packages/framework/tests/Feature/AbstractPageTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -156,21 +156,21 @@ public function test_get_output_location_trims_trailing_slashes_from_basename()
156156
public function test_get_current_page_path_returns_output_directory_and_basename()
157157
{
158158
$page = new MarkdownPage('foo');
159-
$this->assertEquals('foo', $page->getCurrentPagePath());
159+
$this->assertEquals('foo', $page->getRouteKey());
160160
}
161161

162162
public function test_get_current_page_path_returns_output_directory_and_basename_for_configured_directory()
163163
{
164164
MarkdownPage::$outputDirectory = 'foo';
165165
$page = new MarkdownPage('bar');
166-
$this->assertEquals('foo/bar', $page->getCurrentPagePath());
166+
$this->assertEquals('foo/bar', $page->getRouteKey());
167167
}
168168

169169
public function test_get_current_page_path_trims_trailing_slashes_from_directory_setting()
170170
{
171171
MarkdownPage::$outputDirectory = '/foo/\\';
172172
$page = new MarkdownPage('bar');
173-
$this->assertEquals('foo/bar', $page->getCurrentPagePath());
173+
$this->assertEquals('foo/bar', $page->getRouteKey());
174174
}
175175

176176
public function test_get_output_path_returns_current_page_path_with_html_extension_appended()

packages/framework/tests/Feature/RouteTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function test_get_route_key_returns_page_path()
4848
$page = new MarkdownPage();
4949
$route = new Route($page);
5050

51-
$this->assertEquals($page->getCurrentPagePath(), $route->getRouteKey());
51+
$this->assertEquals($page->getRouteKey(), $route->getRouteKey());
5252
}
5353

5454
public function test_get_source_file_path_returns_page_source_path()

packages/framework/tests/Unit/DocumentationPageTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ public function test_can_generate_table_of_contents()
2525
public function test_can_get_current_page_path()
2626
{
2727
$page = DocumentationPage::make('foo');
28-
$this->assertEquals('docs/foo', $page->getCurrentPagePath());
28+
$this->assertEquals('docs/foo', $page->getRouteKey());
2929

3030
config(['docs.output_directory' => 'documentation/latest/']);
3131
(new HydeServiceProvider($this->app))->register();
32-
$this->assertEquals('documentation/latest/foo', $page->getCurrentPagePath());
32+
$this->assertEquals('documentation/latest/foo', $page->getRouteKey());
3333
}
3434

3535
public function test_can_get_online_source_path()

packages/framework/tests/Unit/MarkdownPostHelpersTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class MarkdownPostHelpersTest extends TestCase
1313
public function test_get_current_page_path_returns_local_uri_path_for_post_slug()
1414
{
1515
$post = new MarkdownPost('foo-bar');
16-
$this->assertEquals('posts/foo-bar', $post->getCurrentPagePath());
16+
$this->assertEquals('posts/foo-bar', $post->getRouteKey());
1717
}
1818

1919
public function test_get_canonical_link_returns_canonical_uri_path_for_post_slug()

projects/shelf/admin/src/AdminPage.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct(string $view)
2323
$this->route = $this->request()?->get('route', 'dashboard') ?? 'dashboard';
2424
}
2525

26-
public function getCurrentPagePath(): string
26+
public function getRouteKey(): string
2727
{
2828
return 'admin';
2929
}

0 commit comments

Comments
 (0)