Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor publication list page to extend virtual page #813

Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,25 @@
namespace Hyde\Framework\Features\Publications\Models;

use Hyde\Framework\Actions\PublicationPageCompiler;
use Hyde\Pages\BladePage;
use Hyde\Pages\Contracts\DynamicPage;
use Hyde\Pages\VirtualPage;

/**
* @see \Hyde\Pages\PublicationPage
* @see \Hyde\Framework\Testing\Feature\PublicationListPageTest
*/
class PublicationListPage extends BladePage implements DynamicPage
class PublicationListPage extends VirtualPage
{
public static string $sourceDirectory = '__publications';
public static string $outputDirectory = '';
public static string $fileExtension = 'json';

public PublicationType $type;

public function __construct(PublicationType $type)
{
$this->type = $type;

parent::__construct("{$type->getDirectory()}/index");
parent::__construct("{$type->getDirectory()}/index", view: $type->listTemplate);
}

public function compile(): string
{
return PublicationPageCompiler::call($this);
}

public function getSourcePath(): string
{
return $this->type->getDirectory().'/schema.json';
}
}
2 changes: 1 addition & 1 deletion packages/framework/tests/Feature/PageCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function test_listing_pages_for_publications_are_discovered()

$this->assertInstanceOf(
PublicationListPage::class,
PageCollection::boot(Hyde::getInstance())->getPage('publication/schema.json')
PageCollection::boot(Hyde::getInstance())->getPage('publication/index')
);

File::deleteDirectory(Hyde::path('publication'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function test_source_path_mappings()
$this->assertSame('test-publication/index', $page->getIdentifier());
$this->assertSame('test-publication/index', $page->getRouteKey());
$this->assertSame('test-publication/index.html', $page->getOutputPath());
$this->assertSame('test-publication/schema.json', $page->getSourcePath());
$this->assertSame('test-publication/index', $page->getSourcePath());

File::deleteDirectory(Hyde::path('test-publication'));
}
Expand Down