From 1462755c42c4316c272b0a556dd558d54784d9d2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 20:37:12 +0100 Subject: [PATCH 001/129] Create PublicationPage.php --- packages/framework/src/Pages/PublicationPage.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 packages/framework/src/Pages/PublicationPage.php diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php new file mode 100644 index 00000000000..ac17d825b60 --- /dev/null +++ b/packages/framework/src/Pages/PublicationPage.php @@ -0,0 +1,13 @@ + Date: Fri, 18 Nov 2022 19:47:07 +0000 Subject: [PATCH 002/129] Apply fixes from StyleCI --- .../Commands/BuildPublicationsCommand.php | 14 ++-- .../Interfaces/CommandHandleInterface.php | 2 +- .../Commands/MakePublicationCommand.php | 34 ++++----- .../Commands/MakePublicationTypeCommand.php | 43 ++++++------ .../Actions/CreatesNewPublicationFile.php | 21 +++--- .../CreatesNewPublicationTypeSchema.php | 24 +++---- .../Interfaces/CreateActionInterface.php | 2 +- packages/framework/src/HydeHelper.php | 69 ++++++++++--------- rector.php | 11 ++- 9 files changed, 108 insertions(+), 112 deletions(-) diff --git a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php index 82c8142963f..aada335110d 100644 --- a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php +++ b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php @@ -60,7 +60,7 @@ public function handle(): int $this->printFinishMessage($time_start); - $this->output->writeln('Max memory used: ' . memory_get_peak_usage() / 1024 / 1024 . ' MB'); + $this->output->writeln('Max memory used: '.memory_get_peak_usage() / 1024 / 1024 .' MB'); return Command::SUCCESS; } @@ -89,7 +89,7 @@ protected function buildDetailPages(string $targetDirectory, Collection $pubType view()->share('currentPage', $template); view()->share('currentRoute', $page->getRoute()); - $detailTemplate = "hyde::pubtypes." . $template; + $detailTemplate = 'hyde::pubtypes.'.$template; foreach ($publications as $publication) { $slug = $publication->matter->__slug; $this->info(" Building [$slug] ..."); @@ -100,8 +100,8 @@ protected function buildDetailPages(string $targetDirectory, Collection $pubType protected function buildListPage(string $targetDirectory, Collection $pubType, Collection $publications): void { - $template = "hyde::pubtypes." . $pubType->listTemplate; - $this->info(" Building list page ..."); + $template = 'hyde::pubtypes.'.$pubType->listTemplate; + $this->info(' Building list page ...'); $html = view($template)->with('publications', $publications)->render(); file_put_contents("$targetDirectory/index.html", $html); } @@ -129,7 +129,7 @@ public function runPostBuildActions(): void if ($this->option('run-prettier')) { $this->runNodeCommand( - 'npx prettier ' . Hyde::pathToRelative(Hyde::sitePath()) . '/**/*.html --write --bracket-same-line', + 'npx prettier '.Hyde::pathToRelative(Hyde::sitePath()).'/**/*.html --write --bracket-same-line', 'Prettifying code!', 'prettify code' ); @@ -163,14 +163,14 @@ protected function printFinishMessage(float $time_start): void $this->info('Congratulations! 🎉 Your static site has been built!'); $this->line( - 'Your new homepage is stored here -> ' . + 'Your new homepage is stored here -> '. DiscoveryService::createClickableFilepath(Hyde::sitePath('index.html')) ); } protected function runNodeCommand(string $command, string $message, ?string $actionMessage = null): void { - $this->info($message . ' This may take a second.'); + $this->info($message.' This may take a second.'); $output = shell_exec( sprintf( diff --git a/packages/framework/src/Console/Commands/Interfaces/CommandHandleInterface.php b/packages/framework/src/Console/Commands/Interfaces/CommandHandleInterface.php index 3673cbd785c..7557d850818 100644 --- a/packages/framework/src/Console/Commands/Interfaces/CommandHandleInterface.php +++ b/packages/framework/src/Console/Commands/Interfaces/CommandHandleInterface.php @@ -5,4 +5,4 @@ interface CommandHandleInterface { public function handle(): int; -} \ No newline at end of file +} diff --git a/packages/framework/src/Console/Commands/MakePublicationCommand.php b/packages/framework/src/Console/Commands/MakePublicationCommand.php index 777420a2432..55d60f35dab 100644 --- a/packages/framework/src/Console/Commands/MakePublicationCommand.php +++ b/packages/framework/src/Console/Commands/MakePublicationCommand.php @@ -12,7 +12,7 @@ use Rgasch\Collection\Collection; /** - * Hyde Command to create a new publication for a given publication type + * Hyde Command to create a new publication for a given publication type. * * @see \Hyde\Framework\Testing\Feature\Commands\MakePageCommandTest */ @@ -25,31 +25,31 @@ class MakePublicationCommand extends Command implements CommandHandleInterface /** @var string */ protected $description = 'Create a new publication item'; - public function handle(): int { $this->title('Creating a new Publication Item!'); $pubTypes = HydeHelper::getPublicationTypes(); if ($pubTypes->isEmpty()) { - $this->output->error("Unable to locate any publication-types ... did you create any?"); + $this->output->error('Unable to locate any publication-types ... did you create any?'); + return Command::FAILURE; } $pubType = $this->argument('publicationType'); - if (!$pubType) { + if (! $pubType) { $this->output->writeln('Now please choose the Publication Type to create an item for:'); $offset = 0; foreach ($pubTypes as $pubType) { $offset++; $this->line(" $offset: $pubType->name"); } - $selected = (int)HydeHelper::askWithValidation($this, 'selected', "Publication type (1-$offset)", ['required', 'integer', "between:1,$offset"]); - $pubType = $pubTypes->{$pubTypes->keys()[$selected - 1]}; + $selected = (int) HydeHelper::askWithValidation($this, 'selected', "Publication type (1-$offset)", ['required', 'integer', "between:1,$offset"]); + $pubType = $pubTypes->{$pubTypes->keys()[$selected - 1]}; } $mediaFiles = HydeHelper::getMediaForPubType($pubType); - $fieldData = Collection::create(); + $fieldData = Collection::create(); $this->output->writeln('Now please enter the field data:'); foreach ($pubType->fields as $field) { $fieldData->{$field->name} = $this->captureFieldInput($field, $mediaFiles); @@ -67,7 +67,7 @@ public function handle(): int $this, 'overwrite', 'Do you wish to overwrite the existing file (y/n)', - ['required', 'string', "in:y,n"], + ['required', 'string', 'in:y,n'], 'n' ); if (strtolower($overwrite) == 'y') { @@ -77,21 +77,21 @@ public function handle(): int $this->output->writeln('Existing without overwriting existing publication file!'); } } catch (\Exception $e) { - $this->error("Error: " . $e->getMessage() . " at " . $e->getFile() . ':' . $e->getLine()); + $this->error('Error: '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine()); + return Command::FAILURE; } return Command::SUCCESS; } - private function captureFieldInput(Collection $field, Collection $mediaFiles): string|array { $rulesPerType = $this->getValidationRulesPerType(); if ($field->type === 'text') { $lines = []; - $this->output->writeln($field->name . " (end with a line containing only '<<<')"); + $this->output->writeln($field->name." (end with a line containing only '<<<')"); do { $line = Str::replace("\n", '', fgets(STDIN)); if ($line === '<<<') { @@ -105,7 +105,7 @@ private function captureFieldInput(Collection $field, Collection $mediaFiles): s if ($field->type === 'array') { $lines = []; - $this->output->writeln($field->name . " (end with an empty line)"); + $this->output->writeln($field->name.' (end with an empty line)'); do { $line = Str::replace("\n", '', fgets(STDIN)); if ($line === '') { @@ -118,14 +118,15 @@ private function captureFieldInput(Collection $field, Collection $mediaFiles): s } if ($field->type === 'image') { - $this->output->writeln($field->name . " (end with an empty line)"); + $this->output->writeln($field->name.' (end with an empty line)'); foreach ($mediaFiles as $k => $file) { $offset = $k + 1; $this->output->writeln(" $offset: $file"); } $selected = HydeHelper::askWithValidation($this, $field->name, $field->name, ['required', 'integer', "between:1,$offset"]); - $file = $mediaFiles->{$selected - 1}; - return '_media/' . Str::of($file)->after('media/')->toString(); + $file = $mediaFiles->{$selected - 1}; + + return '_media/'.Str::of($file)->after('media/')->toString(); } // Fields which are not of type array, text or image @@ -150,11 +151,10 @@ private function captureFieldInput(Collection $field, Collection $mediaFiles): s return HydeHelper::askWithValidation($this, $field->name, $field->name, $fieldRules); } - private function getValidationRulesPerType(): Collection { static $rulesPerType = null; - if (!$rulesPerType) { + if (! $rulesPerType) { $rulesPerType = Collection::create( [ 'string' => ['required', 'string', 'between'], diff --git a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php index 34bdd4bff06..0984f849398 100644 --- a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php +++ b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php @@ -11,7 +11,7 @@ use Rgasch\Collection\Collection; /** - * Hyde Command to create a new publication type + * Hyde Command to create a new publication type. * * @see \Hyde\Framework\Testing\Feature\Commands\MakePageCommandTest */ @@ -24,14 +24,13 @@ class MakePublicationTypeCommand extends Command implements CommandHandleInterfa /** @var string */ protected $description = 'Create a new publication type definition'; - public function handle(): int { $this->title('Creating a new Publication Type!'); $title = $this->argument('title'); - if (!$title) { - $title = trim(HydeHelper::askWithValidation($this, 'nanme', 'Publication type name', ['required', 'string'])); + if (! $title) { + $title = trim(HydeHelper::askWithValidation($this, 'nanme', 'Publication type name', ['required', 'string'])); $dirname = HydeHelper::formatNameForStorage($title); if (file_exists($dirname)) { throw new \InvalidArgumentException("Storage path [$dirname] already exists"); @@ -41,35 +40,35 @@ public function handle(): int $fields = $this->captureFieldsDefinitions(); $this->output->writeln('Choose the default field you wish to sort by:'); - $this->line(" 0: dateCreated (meta field)"); + $this->line(' 0: dateCreated (meta field)'); foreach ($fields as $k => $v) { $offset = $k + 1; $this->line(" $offset: $v[name]"); } - $selected = (int)HydeHelper::askWithValidation($this, 'selected', "Sort field (0-$offset)", ['required', 'integer', "between:0,$offset"], 0); + $selected = (int) HydeHelper::askWithValidation($this, 'selected', "Sort field (0-$offset)", ['required', 'integer', "between:0,$offset"], 0); $sortField = $selected ? $fields[$selected - 1]['name'] : '__createdAt'; $this->output->writeln('Choose the default sort direction:'); $this->line(' 1 - Ascending (oldest items first if sorting by dateCreated)'); $this->line(' 2 - Descending (newest items first if sorting by dateCreated)'); - $selected = (int)HydeHelper::askWithValidation($this, 'selected', "Sort field (1-2)", ['required', 'integer', "between:1,2"], 2); + $selected = (int) HydeHelper::askWithValidation($this, 'selected', 'Sort field (1-2)', ['required', 'integer', 'between:1,2'], 2); $sortDirection = match ($selected) { 1 => 'ASC', 2 => 'DESC', }; - $pagesize = (int)HydeHelper::askWithValidation( + $pagesize = (int) HydeHelper::askWithValidation( $this, 'pagesize', - "Enter the pagesize (0 for no limit)", + 'Enter the pagesize (0 for no limit)', ['required', 'integer', 'between:0,100'], 25 ); - $prevNextLinks = (bool)HydeHelper::askWithValidation( + $prevNextLinks = (bool) HydeHelper::askWithValidation( $this, 'prevNextLinks', 'Generate previous/next links in detail view (y/n)', - ['required', 'string', "in:y,n"], + ['required', 'string', 'in:y,n'], 'y' ); @@ -80,31 +79,31 @@ public function handle(): int $this->line(" $offset: $v->name"); } } - $selected = (int)HydeHelper::askWithValidation($this, 'selected', "Canonical field (1-$offset)", ['required', 'integer', "between:1,$offset"], 1); + $selected = (int) HydeHelper::askWithValidation($this, 'selected', "Canonical field (1-$offset)", ['required', 'integer', "between:1,$offset"], 1); $canonicalField = $fields[$selected - 1]['name']; try { $creator = new CreatesNewPublicationTypeSchema($title, $fields, $canonicalField, $sortField, $sortDirection, $pagesize, $prevNextLinks); $creator->create(); } catch (\Exception $e) { - $this->error("Error: " . $e->getMessage() . " at " . $e->getFile() . ':' . $e->getLine()); + $this->error('Error: '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine()); + return Command::FAILURE; } return Command::SUCCESS; } - private function captureFieldsDefinitions(): Collection { $this->output->writeln('You now need to define the fields in your publication type:'); - $count = 1; + $count = 1; $fields = Collection::create(); do { $this->line(''); $this->output->writeln("Field #$count:"); - $field = Collection::create(); + $field = Collection::create(); $field->name = HydeHelper::askWithValidation($this, 'name', 'Field name', ['required']); $this->line('Field type:'); $this->line(' 1 - String'); @@ -116,17 +115,17 @@ private function captureFieldsDefinitions(): Collection $this->line(' 7 - Array'); $this->line(' 8 - Text'); $this->line(' 9 - Local Image'); - $type = (int)HydeHelper::askWithValidation($this, 'type', 'Field type (1-7)', ['required', 'integer', 'between:1,9'], 1); + $type = (int) HydeHelper::askWithValidation($this, 'type', 'Field type (1-7)', ['required', 'integer', 'between:1,9'], 1); do { - $field->min = HydeHelper::askWithValidation($this, 'min', 'Min value (for strings, this refers to string length)', ['required', 'string'], 0); - $field->max = HydeHelper::askWithValidation($this, 'max', 'Max value (for strings, this refers to string length)', ['required', 'string'], 0); + $field->min = HydeHelper::askWithValidation($this, 'min', 'Min value (for strings, this refers to string length)', ['required', 'string'], 0); + $field->max = HydeHelper::askWithValidation($this, 'max', 'Max value (for strings, this refers to string length)', ['required', 'string'], 0); $lengthsValid = true; if ($field->max < $field->min) { $lengthsValid = false; - $this->output->warning("Field length [max] must be [>=] than [min]"); + $this->output->warning('Field length [max] must be [>=] than [min]'); } - } while (!$lengthsValid); - $addAnother = HydeHelper::askWithValidation($this, 'addAnother', 'Add another field (y/n)', ['required', 'string', "in:y,n"], 'y'); + } while (! $lengthsValid); + $addAnother = HydeHelper::askWithValidation($this, 'addAnother', 'Add another field (y/n)', ['required', 'string', 'in:y,n'], 'y'); // map field choice to actual field type $field->type = match ($type) { diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php index 6fc4206c359..08b573dd5f0 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php @@ -9,7 +9,6 @@ use Hyde\HydeHelper; use Illuminate\Support\Str; use Rgasch\Collection\Collection; - use function Safe\date; use function Safe\file_put_contents; @@ -33,19 +32,19 @@ public function __construct( public function create(): void { - $dir = dirname($this->pubType->schemaFile); + $dir = dirname($this->pubType->schemaFile); $canonicalFieldName = $this->pubType->canonicalField; - $canonicalFieldDef = $this->pubType->fields->filter(fn($f) => $f->name === $canonicalFieldName)->first(); - $canonicalValue = $canonicalFieldDef->type != 'array' ? $this->fieldData->{$canonicalFieldName} : $this->fieldData->{$canonicalFieldName}[0]; - $canonicalStr = Str::of($canonicalValue)->substr(0, 64); - $slug = $canonicalStr->slug()->toString(); - $fileName = HydeHelper::formatNameForStorage($slug); - $outFile = "$dir/$fileName.md"; - if (file_exists($outFile) && !$this->force) { + $canonicalFieldDef = $this->pubType->fields->filter(fn ($f) => $f->name === $canonicalFieldName)->first(); + $canonicalValue = $canonicalFieldDef->type != 'array' ? $this->fieldData->{$canonicalFieldName} : $this->fieldData->{$canonicalFieldName}[0]; + $canonicalStr = Str::of($canonicalValue)->substr(0, 64); + $slug = $canonicalStr->slug()->toString(); + $fileName = HydeHelper::formatNameForStorage($slug); + $outFile = "$dir/$fileName.md"; + if (file_exists($outFile) && ! $this->force) { throw new \InvalidArgumentException("File [$outFile] already exists"); } - $now = date('Y-m-d H:i:s'); + $now = date('Y-m-d H:i:s'); $output = "---\n"; $output .= "__createdAt: {$now}\n"; foreach ($this->fieldData as $k => $v) { @@ -73,7 +72,7 @@ public function create(): void $output .= "Raw MD text ...\n"; $this->result = $output; - print "Saving publication data to [$outFile]\n"; + echo "Saving publication data to [$outFile]\n"; file_put_contents($outFile, $output); } diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php index 9d6ff4bdc3f..9567145a847 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php @@ -8,7 +8,6 @@ use Hyde\Framework\Concerns\InteractsWithDirectories; use Hyde\HydeHelper; use Rgasch\Collection\Collection; - use function Safe\file_put_contents; use function Safe\json_encode; use function Safe\mkdir; @@ -35,27 +34,26 @@ public function __construct( ) { } - public function create(): void { $dirName = HydeHelper::formatNameForStorage($this->name); $outFile = "$dirName/schema.json"; mkdir($dirName); - $data = []; - $data['name'] = $this->name; + $data = []; + $data['name'] = $this->name; $data['canonicalField'] = $this->canonicalField; - $data['sortField'] = $this->sortField; - $data['sortDirection'] = $this->sortDirection; - $data['pagesize'] = $this->pagesize; - $data['prevNextLinks'] = $this->prevNextLinks; + $data['sortField'] = $this->sortField; + $data['sortDirection'] = $this->sortDirection; + $data['pagesize'] = $this->pagesize; + $data['prevNextLinks'] = $this->prevNextLinks; $data['detailTemplate'] = "{$dirName}_detail"; - $data['listTemplate'] = "{$dirName}_list"; - $data['fields'] = $this->fields; - $json = json_encode($data, JSON_PRETTY_PRINT); - $this->result = $json; + $data['listTemplate'] = "{$dirName}_list"; + $data['fields'] = $this->fields; + $json = json_encode($data, JSON_PRETTY_PRINT); + $this->result = $json; - print "Saving publicationType data to [$outFile]\n"; + echo "Saving publicationType data to [$outFile]\n"; file_put_contents($outFile, $json); } diff --git a/packages/framework/src/Framework/Actions/Interfaces/CreateActionInterface.php b/packages/framework/src/Framework/Actions/Interfaces/CreateActionInterface.php index 1ff4f524e93..ce11adb9efe 100644 --- a/packages/framework/src/Framework/Actions/Interfaces/CreateActionInterface.php +++ b/packages/framework/src/Framework/Actions/Interfaces/CreateActionInterface.php @@ -5,4 +5,4 @@ interface CreateActionInterface { public function create(): void; -} \ No newline at end of file +} diff --git a/packages/framework/src/HydeHelper.php b/packages/framework/src/HydeHelper.php index 22c8c070835..273481a6fa8 100644 --- a/packages/framework/src/HydeHelper.php +++ b/packages/framework/src/HydeHelper.php @@ -10,20 +10,19 @@ use Illuminate\Support\Str; use LaravelZero\Framework\Commands\Command; use Rgasch\Collection\Collection; -use Spatie\YamlFrontMatter\YamlFrontMatter; - use function Safe\file_get_contents; +use Spatie\YamlFrontMatter\YamlFrontMatter; class HydeHelper { /** - * Ask for a CLI input value until we pass validation rules + * Ask for a CLI input value until we pass validation rules. * - * @param Command $command - * @param string $name - * @param string $message - * @param array $rules - * @param array $rules + * @param Command $command + * @param string $name + * @param string $message + * @param array $rules + * @param array $rules * @return mixed $default */ public static function askWithValidation(Command $command, string $name, string $message, Collection|array $rules = [], mixed $default = null) @@ -32,8 +31,8 @@ public static function askWithValidation(Command $command, string $name, string $rules = $rules->toArray(); } - $answer = $command->ask($message, $default); - $factory = app(ValidationFactory::class); + $answer = $command->ask($message, $default); + $factory = app(ValidationFactory::class); $validator = $factory->make([$name => $answer], [$name => $rules]); if ($validator->passes()) { @@ -58,9 +57,9 @@ public static function getKernel(): HydeKernel } /** - * Format the publication type name to a suitable representation for file storage + * Format the publication type name to a suitable representation for file storage. * - * @param string $pubTypeNameRaw + * @param string $pubTypeNameRaw * @return string */ public static function formatNameForStorage(string $pubTypeNameRaw) @@ -72,23 +71,24 @@ public static function formatNameForStorage(string $pubTypeNameRaw) * Return a collection of all defined publication types, indexed by the directory name. * * @return Collection + * * @throws \Exception */ public static function getPublicationTypes(): Collection { - $root = base_path(); + $root = base_path(); $schemaFiles = glob("$root/*/schema.json", GLOB_BRACE); $pubTypes = Collection::create(); foreach ($schemaFiles as $schemaFile) { $fileData = file_get_contents($schemaFile); - if (!$fileData) { + if (! $fileData) { throw new \Exception("No data read from [$schemaFile]"); } - $dirName = Collection::create(explode('/', dirname($schemaFile)))->last(); - $schema = Collection::create(json_decode($fileData, true)); - $schema->directory = $dirName; - $schema->schemaFile = $schemaFile; + $dirName = Collection::create(explode('/', dirname($schemaFile)))->last(); + $schema = Collection::create(json_decode($fileData, true)); + $schema->directory = $dirName; + $schema->schemaFile = $schemaFile; $pubTypes->{$schema->directory} = $schema; } @@ -98,13 +98,14 @@ public static function getPublicationTypes(): Collection /** * Return all publications for a given pub type, optionally sorted by the publication's sortField. * - * @param Collection $pubType + * @param Collection $pubType * @return Collection + * * @throws \Safe\Exceptions\FilesystemException */ public static function getPublicationsForPubType(Collection $pubType, $sort = true): Collection { - $root = base_path(); + $root = base_path(); $files = glob("$root/{$pubType->directory}/*.md"); $publications = Collection::create(); @@ -121,17 +122,17 @@ public static function getPublicationsForPubType(Collection $pubType, $sort = tr return $publications; } - /** - * Return all media items for a given publication type + * Return all media items for a given publication type. * - * @param Collection $pubType + * @param Collection $pubType * @return Collection + * * @throws \Safe\Exceptions\FilesystemException */ public static function getMediaForPubType(Collection $pubType, $sort = true): Collection { - $root = base_path(); + $root = base_path(); $files = glob("$root/_media/{$pubType->directory}/*.{jpg,jpeg,png,gif,pdf}", GLOB_BRACE); $media = Collection::create(); @@ -146,24 +147,23 @@ public static function getMediaForPubType(Collection $pubType, $sort = true): Co return $media; } - /** * Read an MD file and return the parsed data. * - * @param string $fileData + * @param string $fileData * @return Collection */ public static function getPublicationData(string $mdFileName): Collection { $fileData = file_get_contents($mdFileName); - if (!$fileData) { + if (! $fileData) { throw new \Exception("No data read from [$mdFileName]"); } - $parsedFileData = YamlFrontMatter::markdownCompatibleParse($fileData); - $matter = $parsedFileData->matter(); - $markdown = $parsedFileData->body(); - $matter['__slug'] = basename($mdFileName, '.md'); + $parsedFileData = YamlFrontMatter::markdownCompatibleParse($fileData); + $matter = $parsedFileData->matter(); + $markdown = $parsedFileData->body(); + $matter['__slug'] = basename($mdFileName, '.md'); $matter['__createdDatetime'] = Carbon::createFromTimestamp($matter['__createdAt']); return Collection::create(['matter' => $matter, 'markdown' => $markdown]); @@ -172,9 +172,10 @@ public static function getPublicationData(string $mdFileName): Collection /** * Check whether a given publication type exists. * - * @param string $pubTypeName - * @param bool $isRaw + * @param string $pubTypeName + * @param bool $isRaw * @return bool + * * @throws \Exception */ public static function publicationTypeExists(string $pubTypeName, bool $isRaw = true): bool @@ -189,7 +190,7 @@ public static function publicationTypeExists(string $pubTypeName, bool $isRaw = /** * Remove trailing slashes from the start and end of a string. * - * @param string $string + * @param string $string * @return string */ public static function unslash(string $string): string diff --git a/rector.php b/rector.php index 535dfab3613..5ca2375a2ef 100644 --- a/rector.php +++ b/rector.php @@ -6,12 +6,11 @@ use Rector\Laravel\Set\LaravelSetList; return static function (RectorConfig $rectorConfig): void { - $rectorConfig->paths([__DIR__ . '/packages']); + $rectorConfig->paths([__DIR__.'/packages']); $rectorConfig->sets([ - LaravelSetList::LARAVEL_90, - \Rector\Set\ValueObject\SetList::PHP_80, - \Rector\Set\ValueObject\SetList::PHP_81, - ]); + LaravelSetList::LARAVEL_90, + \Rector\Set\ValueObject\SetList::PHP_80, + \Rector\Set\ValueObject\SetList::PHP_81, + ]); $rectorConfig->rule(Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector::class); }; - From 58c52296e618cf575107bd7d2c3e4beb4c12b2c3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 20:49:39 +0100 Subject: [PATCH 003/129] Add class PHPDoc --- packages/framework/src/Pages/PublicationPage.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index ac17d825b60..54af6cea343 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -4,6 +4,10 @@ namespace Hyde\Pages; +/** + * Publication pages adds an easy way to create custom no-code page types, + * with support using a custom front matter schema and Blade templates. + */ class PublicationPage extends Concerns\HydePage { public function compile(): string From 71a0b0a62d73a8b77674462b760422a55f0afd2a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 20:52:27 +0100 Subject: [PATCH 004/129] Add PublicationPage feature --- config/hyde.php | 1 + packages/framework/config/hyde.php | 1 + packages/framework/src/Facades/Features.php | 11 +++++++++++ 3 files changed, 13 insertions(+) diff --git a/config/hyde.php b/config/hyde.php index 08ffd8f946a..84a132beb1f 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -85,6 +85,7 @@ Features::bladePages(), Features::markdownPages(), Features::documentationPages(), + Features::publicationPages(), // Features::dataCollections(), // Frontend Features diff --git a/packages/framework/config/hyde.php b/packages/framework/config/hyde.php index 08ffd8f946a..84a132beb1f 100644 --- a/packages/framework/config/hyde.php +++ b/packages/framework/config/hyde.php @@ -85,6 +85,7 @@ Features::bladePages(), Features::markdownPages(), Features::documentationPages(), + Features::publicationPages(), // Features::dataCollections(), // Frontend Features diff --git a/packages/framework/src/Facades/Features.php b/packages/framework/src/Facades/Features.php index 8fe9e154419..d0c64a770ba 100644 --- a/packages/framework/src/Facades/Features.php +++ b/packages/framework/src/Facades/Features.php @@ -41,6 +41,7 @@ public static function enabled(string $feature): bool static::bladePages(), static::markdownPages(), static::documentationPages(), + static::publicationPages(), // static::dataCollections(), // Frontend Features @@ -81,6 +82,11 @@ public static function hasDocumentationPages(): bool return static::enabled(static::documentationPages()); } + public static function hasPublicationPages(): bool + { + return static::enabled(static::publicationPages()); + } + public static function hasDataCollections(): bool { return static::enabled(static::dataCollections()); @@ -138,6 +144,11 @@ public static function documentationPages(): string return 'documentation-pages'; } + public static function publicationPages(): string + { + return 'publication-pages'; + } + public static function documentationSearch(): string { return 'documentation-search'; From 6fe5c86eafd5272a803334353a94d8e70d4a33a3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 20:53:00 +0100 Subject: [PATCH 005/129] Update ConfigurableFeaturesTest.php --- packages/framework/tests/Feature/ConfigurableFeaturesTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/ConfigurableFeaturesTest.php b/packages/framework/tests/Feature/ConfigurableFeaturesTest.php index f644a8941d7..0c69851231c 100644 --- a/packages/framework/tests/Feature/ConfigurableFeaturesTest.php +++ b/packages/framework/tests/Feature/ConfigurableFeaturesTest.php @@ -81,11 +81,12 @@ public function test_to_array_method_contains_all_settings() $this->assertArrayHasKey('blade-pages', $array); $this->assertArrayHasKey('markdown-pages', $array); $this->assertArrayHasKey('documentation-pages', $array); + $this->assertArrayHasKey('publication-pages', $array); $this->assertArrayHasKey('darkmode', $array); $this->assertArrayHasKey('documentation-search', $array); $this->assertArrayHasKey('torchlight', $array); - $this->assertCount(9, $array); + $this->assertCount(10, $array); } public function test_features_can_be_mocked() From f1fa0c539f7eb5e45ab06ebd834f08b57a9fcbe0 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 21:25:23 +0100 Subject: [PATCH 006/129] Test HtmlPages --- packages/framework/tests/Feature/PageCollectionTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PageCollectionTest.php b/packages/framework/tests/Feature/PageCollectionTest.php index e218b206bb1..8cf08c84695 100644 --- a/packages/framework/tests/Feature/PageCollectionTest.php +++ b/packages/framework/tests/Feature/PageCollectionTest.php @@ -8,6 +8,7 @@ use Hyde\Hyde; use Hyde\Pages\BladePage; use Hyde\Pages\DocumentationPage; +use Hyde\Pages\HtmlPage; use Hyde\Pages\MarkdownPage; use Hyde\Pages\MarkdownPost; use Hyde\Testing\TestCase; @@ -103,13 +104,15 @@ public function test_get_pages_returns_all_pages_when_not_supplied_with_class_st $this->withoutDefaultPages(); $this->file('_pages/foo.blade.php'); + $this->file('_pages/foo.html'); $this->file('_pages/foo.md'); $this->file('_posts/foo.md'); $this->file('_docs/foo.md'); $collection = PageCollection::boot(Hyde::getInstance())->getPages(); - $this->assertCount(4, $collection); + $this->assertCount(5, $collection); $this->assertEquals(new BladePage('foo'), $collection->get('_pages/foo.blade.php')); + $this->assertEquals(new HtmlPage('foo'), $collection->get('_pages/foo.html')); $this->assertEquals(new MarkdownPage('foo'), $collection->get('_pages/foo.md')); $this->assertEquals(new MarkdownPost('foo'), $collection->get('_posts/foo.md')); $this->assertEquals(new DocumentationPage('foo'), $collection->get('_docs/foo.md')); From 01e513b793b30973d6849558904a259833831565 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 21:27:06 +0100 Subject: [PATCH 007/129] Update PageCollectionTest.php --- .../framework/tests/Feature/PageCollectionTest.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/framework/tests/Feature/PageCollectionTest.php b/packages/framework/tests/Feature/PageCollectionTest.php index 8cf08c84695..798ce06abd8 100644 --- a/packages/framework/tests/Feature/PageCollectionTest.php +++ b/packages/framework/tests/Feature/PageCollectionTest.php @@ -83,18 +83,22 @@ public function test_get_pages_returns_collection_of_pages_of_given_class() $this->file('_pages/foo.md'); $this->file('_posts/foo.md'); $this->file('_docs/foo.md'); + $this->file('_pages/foo.html'); + $collection = PageCollection::boot(Hyde::getInstance()); - $this->assertCount(4, $collection); + $this->assertCount(5, $collection); $this->assertContainsOnlyInstancesOf(BladePage::class, $collection->getPages(BladePage::class)); $this->assertContainsOnlyInstancesOf(MarkdownPage::class, $collection->getPages(MarkdownPage::class)); $this->assertContainsOnlyInstancesOf(MarkdownPost::class, $collection->getPages(MarkdownPost::class)); $this->assertContainsOnlyInstancesOf(DocumentationPage::class, $collection->getPages(DocumentationPage::class)); + $this->assertContainsOnlyInstancesOf(HtmlPage::class, $collection->getPages(HtmlPage::class)); $this->assertEquals(new BladePage('foo'), $collection->getPages(BladePage::class)->first()); $this->assertEquals(new MarkdownPage('foo'), $collection->getPages(MarkdownPage::class)->first()); $this->assertEquals(new MarkdownPost('foo'), $collection->getPages(MarkdownPost::class)->first()); $this->assertEquals(new DocumentationPage('foo'), $collection->getPages(DocumentationPage::class)->first()); + $this->assertEquals(new HtmlPage('foo'), $collection->getPages(HtmlPage::class)->first()); $this->restoreDefaultPages(); } @@ -104,18 +108,19 @@ public function test_get_pages_returns_all_pages_when_not_supplied_with_class_st $this->withoutDefaultPages(); $this->file('_pages/foo.blade.php'); - $this->file('_pages/foo.html'); $this->file('_pages/foo.md'); $this->file('_posts/foo.md'); $this->file('_docs/foo.md'); + $this->file('_pages/foo.html'); + $collection = PageCollection::boot(Hyde::getInstance())->getPages(); $this->assertCount(5, $collection); $this->assertEquals(new BladePage('foo'), $collection->get('_pages/foo.blade.php')); - $this->assertEquals(new HtmlPage('foo'), $collection->get('_pages/foo.html')); $this->assertEquals(new MarkdownPage('foo'), $collection->get('_pages/foo.md')); $this->assertEquals(new MarkdownPost('foo'), $collection->get('_posts/foo.md')); $this->assertEquals(new DocumentationPage('foo'), $collection->get('_docs/foo.md')); + $this->assertEquals(new HtmlPage('foo'), $collection->get('_pages/foo.html')); $this->restoreDefaultPages(); } From 90e3fbe269ae58b64908f852e1f678e974aee9fb Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 21:52:02 +0100 Subject: [PATCH 008/129] Add hook for publication page discovery --- packages/framework/src/Foundation/PageCollection.php | 5 +++++ packages/framework/tests/Feature/PageCollectionTest.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/packages/framework/src/Foundation/PageCollection.php b/packages/framework/src/Foundation/PageCollection.php index b3101dc1077..0220642e55a 100644 --- a/packages/framework/src/Foundation/PageCollection.php +++ b/packages/framework/src/Foundation/PageCollection.php @@ -13,6 +13,7 @@ use Hyde\Pages\HtmlPage; use Hyde\Pages\MarkdownPage; use Hyde\Pages\MarkdownPost; +use Hyde\Pages\PublicationPage; use Illuminate\Support\Collection; /** @@ -60,6 +61,10 @@ protected function runDiscovery(): self $this->discoverPagesFor(DocumentationPage::class); } + if (Features::hasPublicationPages()) { + $this->discoverPagesFor(PublicationPage::class); + } + return $this; } diff --git a/packages/framework/tests/Feature/PageCollectionTest.php b/packages/framework/tests/Feature/PageCollectionTest.php index 798ce06abd8..f2ab12cbbd5 100644 --- a/packages/framework/tests/Feature/PageCollectionTest.php +++ b/packages/framework/tests/Feature/PageCollectionTest.php @@ -177,4 +177,9 @@ public function test_pages_with_custom_source_directories_are_discovered_properl File::deleteDirectory(Hyde::path('.source')); } + + public function test_publication_pages_are_discovered() + { + // TODO: Implement test_publication_pages_are_discovered() method. + } } From 407fdfac35aebcaabb09000addb5945f9a935437 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 21:55:02 +0100 Subject: [PATCH 009/129] Rename HydeHelper to PublicationHelper --- .../Commands/BuildPublicationsCommand.php | 6 ++--- .../Commands/MakePublicationCommand.php | 14 +++++----- .../Commands/MakePublicationTypeCommand.php | 26 +++++++++---------- .../Actions/CreatesNewPublicationFile.php | 4 +-- .../CreatesNewPublicationTypeSchema.php | 4 +-- .../{HydeHelper.php => PublicationHelper.php} | 2 +- 6 files changed, 28 insertions(+), 28 deletions(-) rename packages/framework/src/{HydeHelper.php => PublicationHelper.php} (99%) diff --git a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php index aada335110d..5ff6f07ba09 100644 --- a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php +++ b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php @@ -13,7 +13,7 @@ use Hyde\Framework\Services\BuildTaskService; use Hyde\Framework\Services\DiscoveryService; use Hyde\Hyde; -use Hyde\HydeHelper; +use Hyde\PublicationHelper; use Hyde\Pages\MarkdownPage; use Illuminate\Support\Facades\Config; use LaravelZero\Framework\Commands\Command; @@ -68,11 +68,11 @@ public function handle(): int // Warning: This is extremely hacky ... protected function build(): void { - $pubTypes = HydeHelper::getPublicationTypes(); + $pubTypes = PublicationHelper::getPublicationTypes(); foreach ($pubTypes as $dir => $pubType) { $targetDirectory = "_site/$dir"; @mkdir($targetDirectory); - $publications = HydeHelper::getPublicationsForPubType($pubType); + $publications = PublicationHelper::getPublicationsForPubType($pubType); $this->info("Building [$pubType->name] into [$targetDirectory] ..."); $this->buildDetailPages($targetDirectory, $pubType, $publications); $this->buildListPage($targetDirectory, $pubType, $publications); diff --git a/packages/framework/src/Console/Commands/MakePublicationCommand.php b/packages/framework/src/Console/Commands/MakePublicationCommand.php index 55d60f35dab..44f5d1b13bc 100644 --- a/packages/framework/src/Console/Commands/MakePublicationCommand.php +++ b/packages/framework/src/Console/Commands/MakePublicationCommand.php @@ -6,7 +6,7 @@ use Hyde\Console\Commands\Interfaces\CommandHandleInterface; use Hyde\Framework\Actions\CreatesNewPublicationFile; -use Hyde\HydeHelper; +use Hyde\PublicationHelper; use Illuminate\Support\Str; use LaravelZero\Framework\Commands\Command; use Rgasch\Collection\Collection; @@ -29,7 +29,7 @@ public function handle(): int { $this->title('Creating a new Publication Item!'); - $pubTypes = HydeHelper::getPublicationTypes(); + $pubTypes = PublicationHelper::getPublicationTypes(); if ($pubTypes->isEmpty()) { $this->output->error('Unable to locate any publication-types ... did you create any?'); @@ -44,11 +44,11 @@ public function handle(): int $offset++; $this->line(" $offset: $pubType->name"); } - $selected = (int) HydeHelper::askWithValidation($this, 'selected', "Publication type (1-$offset)", ['required', 'integer', "between:1,$offset"]); + $selected = (int) PublicationHelper::askWithValidation($this, 'selected', "Publication type (1-$offset)", ['required', 'integer', "between:1,$offset"]); $pubType = $pubTypes->{$pubTypes->keys()[$selected - 1]}; } - $mediaFiles = HydeHelper::getMediaForPubType($pubType); + $mediaFiles = PublicationHelper::getMediaForPubType($pubType); $fieldData = Collection::create(); $this->output->writeln('Now please enter the field data:'); foreach ($pubType->fields as $field) { @@ -63,7 +63,7 @@ public function handle(): int // Useful for debugging //$this->output->writeln("xxx " . $e->getTraceAsString()); $this->output->writeln("$msg"); - $overwrite = HydeHelper::askWithValidation( + $overwrite = PublicationHelper::askWithValidation( $this, 'overwrite', 'Do you wish to overwrite the existing file (y/n)', @@ -123,7 +123,7 @@ private function captureFieldInput(Collection $field, Collection $mediaFiles): s $offset = $k + 1; $this->output->writeln(" $offset: $file"); } - $selected = HydeHelper::askWithValidation($this, $field->name, $field->name, ['required', 'integer', "between:1,$offset"]); + $selected = PublicationHelper::askWithValidation($this, $field->name, $field->name, ['required', 'integer', "between:1,$offset"]); $file = $mediaFiles->{$selected - 1}; return '_media/'.Str::of($file)->after('media/')->toString(); @@ -148,7 +148,7 @@ private function captureFieldInput(Collection $field, Collection $mediaFiles): s } } - return HydeHelper::askWithValidation($this, $field->name, $field->name, $fieldRules); + return PublicationHelper::askWithValidation($this, $field->name, $field->name, $fieldRules); } private function getValidationRulesPerType(): Collection diff --git a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php index 0984f849398..92ca2dcb0ce 100644 --- a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php +++ b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php @@ -6,7 +6,7 @@ use Hyde\Console\Commands\Interfaces\CommandHandleInterface; use Hyde\Framework\Actions\CreatesNewPublicationTypeSchema; -use Hyde\HydeHelper; +use Hyde\PublicationHelper; use LaravelZero\Framework\Commands\Command; use Rgasch\Collection\Collection; @@ -30,8 +30,8 @@ public function handle(): int $title = $this->argument('title'); if (! $title) { - $title = trim(HydeHelper::askWithValidation($this, 'nanme', 'Publication type name', ['required', 'string'])); - $dirname = HydeHelper::formatNameForStorage($title); + $title = trim(PublicationHelper::askWithValidation($this, 'nanme', 'Publication type name', ['required', 'string'])); + $dirname = PublicationHelper::formatNameForStorage($title); if (file_exists($dirname)) { throw new \InvalidArgumentException("Storage path [$dirname] already exists"); } @@ -45,26 +45,26 @@ public function handle(): int $offset = $k + 1; $this->line(" $offset: $v[name]"); } - $selected = (int) HydeHelper::askWithValidation($this, 'selected', "Sort field (0-$offset)", ['required', 'integer', "between:0,$offset"], 0); + $selected = (int) PublicationHelper::askWithValidation($this, 'selected', "Sort field (0-$offset)", ['required', 'integer', "between:0,$offset"], 0); $sortField = $selected ? $fields[$selected - 1]['name'] : '__createdAt'; $this->output->writeln('Choose the default sort direction:'); $this->line(' 1 - Ascending (oldest items first if sorting by dateCreated)'); $this->line(' 2 - Descending (newest items first if sorting by dateCreated)'); - $selected = (int) HydeHelper::askWithValidation($this, 'selected', 'Sort field (1-2)', ['required', 'integer', 'between:1,2'], 2); + $selected = (int) PublicationHelper::askWithValidation($this, 'selected', 'Sort field (1-2)', ['required', 'integer', 'between:1,2'], 2); $sortDirection = match ($selected) { 1 => 'ASC', 2 => 'DESC', }; - $pagesize = (int) HydeHelper::askWithValidation( + $pagesize = (int) PublicationHelper::askWithValidation( $this, 'pagesize', 'Enter the pagesize (0 for no limit)', ['required', 'integer', 'between:0,100'], 25 ); - $prevNextLinks = (bool) HydeHelper::askWithValidation( + $prevNextLinks = (bool) PublicationHelper::askWithValidation( $this, 'prevNextLinks', 'Generate previous/next links in detail view (y/n)', @@ -79,7 +79,7 @@ public function handle(): int $this->line(" $offset: $v->name"); } } - $selected = (int) HydeHelper::askWithValidation($this, 'selected', "Canonical field (1-$offset)", ['required', 'integer', "between:1,$offset"], 1); + $selected = (int) PublicationHelper::askWithValidation($this, 'selected', "Canonical field (1-$offset)", ['required', 'integer', "between:1,$offset"], 1); $canonicalField = $fields[$selected - 1]['name']; try { @@ -104,7 +104,7 @@ private function captureFieldsDefinitions(): Collection $this->output->writeln("Field #$count:"); $field = Collection::create(); - $field->name = HydeHelper::askWithValidation($this, 'name', 'Field name', ['required']); + $field->name = PublicationHelper::askWithValidation($this, 'name', 'Field name', ['required']); $this->line('Field type:'); $this->line(' 1 - String'); $this->line(' 2 - Boolean '); @@ -115,17 +115,17 @@ private function captureFieldsDefinitions(): Collection $this->line(' 7 - Array'); $this->line(' 8 - Text'); $this->line(' 9 - Local Image'); - $type = (int) HydeHelper::askWithValidation($this, 'type', 'Field type (1-7)', ['required', 'integer', 'between:1,9'], 1); + $type = (int) PublicationHelper::askWithValidation($this, 'type', 'Field type (1-7)', ['required', 'integer', 'between:1,9'], 1); do { - $field->min = HydeHelper::askWithValidation($this, 'min', 'Min value (for strings, this refers to string length)', ['required', 'string'], 0); - $field->max = HydeHelper::askWithValidation($this, 'max', 'Max value (for strings, this refers to string length)', ['required', 'string'], 0); + $field->min = PublicationHelper::askWithValidation($this, 'min', 'Min value (for strings, this refers to string length)', ['required', 'string'], 0); + $field->max = PublicationHelper::askWithValidation($this, 'max', 'Max value (for strings, this refers to string length)', ['required', 'string'], 0); $lengthsValid = true; if ($field->max < $field->min) { $lengthsValid = false; $this->output->warning('Field length [max] must be [>=] than [min]'); } } while (! $lengthsValid); - $addAnother = HydeHelper::askWithValidation($this, 'addAnother', 'Add another field (y/n)', ['required', 'string', 'in:y,n'], 'y'); + $addAnother = PublicationHelper::askWithValidation($this, 'addAnother', 'Add another field (y/n)', ['required', 'string', 'in:y,n'], 'y'); // map field choice to actual field type $field->type = match ($type) { diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php index 08b573dd5f0..e88de1523ae 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php @@ -6,7 +6,7 @@ use Hyde\Framework\Actions\Interfaces\CreateActionInterface; use Hyde\Framework\Concerns\InteractsWithDirectories; -use Hyde\HydeHelper; +use Hyde\PublicationHelper; use Illuminate\Support\Str; use Rgasch\Collection\Collection; use function Safe\date; @@ -38,7 +38,7 @@ public function create(): void $canonicalValue = $canonicalFieldDef->type != 'array' ? $this->fieldData->{$canonicalFieldName} : $this->fieldData->{$canonicalFieldName}[0]; $canonicalStr = Str::of($canonicalValue)->substr(0, 64); $slug = $canonicalStr->slug()->toString(); - $fileName = HydeHelper::formatNameForStorage($slug); + $fileName = PublicationHelper::formatNameForStorage($slug); $outFile = "$dir/$fileName.md"; if (file_exists($outFile) && ! $this->force) { throw new \InvalidArgumentException("File [$outFile] already exists"); diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php index 9567145a847..4d1f0cebfa7 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php @@ -6,7 +6,7 @@ use Hyde\Framework\Actions\Interfaces\CreateActionInterface; use Hyde\Framework\Concerns\InteractsWithDirectories; -use Hyde\HydeHelper; +use Hyde\PublicationHelper; use Rgasch\Collection\Collection; use function Safe\file_put_contents; use function Safe\json_encode; @@ -36,7 +36,7 @@ public function __construct( public function create(): void { - $dirName = HydeHelper::formatNameForStorage($this->name); + $dirName = PublicationHelper::formatNameForStorage($this->name); $outFile = "$dirName/schema.json"; mkdir($dirName); diff --git a/packages/framework/src/HydeHelper.php b/packages/framework/src/PublicationHelper.php similarity index 99% rename from packages/framework/src/HydeHelper.php rename to packages/framework/src/PublicationHelper.php index 273481a6fa8..8cb76147f39 100644 --- a/packages/framework/src/HydeHelper.php +++ b/packages/framework/src/PublicationHelper.php @@ -13,7 +13,7 @@ use function Safe\file_get_contents; use Spatie\YamlFrontMatter\YamlFrontMatter; -class HydeHelper +class PublicationHelper { /** * Ask for a CLI input value until we pass validation rules. From ef7027c78738156ddccd924f2093a03ce1d60eee Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 21:56:28 +0100 Subject: [PATCH 010/129] Create PublicationType.php --- .../Features/Publications/Models/PublicationType.php | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 packages/framework/src/Framework/Features/Publications/Models/PublicationType.php diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php new file mode 100644 index 00000000000..3cc7d3e606d --- /dev/null +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -0,0 +1,10 @@ + Date: Fri, 18 Nov 2022 22:04:29 +0100 Subject: [PATCH 011/129] Create base PublicationType object --- .../Publications/Models/PublicationType.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 3cc7d3e606d..0492c45a30a 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -6,5 +6,19 @@ class PublicationType { - // TODO: Refactor to utilize this class + protected string $schemaFile; + protected string $directory; + protected array $schema; + + public function __construct(string $schemaFile) + { + $this->schemaFile = $schemaFile; + $this->directory = dirname($schemaFile); + $this->schema = static::parseSchema($schemaFile); + } + + protected static function parseSchema(string $schemaFile): array + { + return json_decode(file_get_contents($schemaFile), true, 512, JSON_THROW_ON_ERROR); + } } From ed515e826787a82fc39fe46927a35da6459682d7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 22:05:01 +0100 Subject: [PATCH 012/129] Add magic __get method --- .../Features/Publications/Models/PublicationType.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 0492c45a30a..ff18dccfeea 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -17,6 +17,11 @@ public function __construct(string $schemaFile) $this->schema = static::parseSchema($schemaFile); } + public function __get(string $name): mixed + { + return $this->schema[$name] ?? null; + } + protected static function parseSchema(string $schemaFile): array { return json_decode(file_get_contents($schemaFile), true, 512, JSON_THROW_ON_ERROR); From b30e7ff93131525f5c526f11cd97e0aa2c6e996c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 22:07:39 +0100 Subject: [PATCH 013/129] Update magic method to first search for actual class properties --- .../Framework/Features/Publications/Models/PublicationType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index ff18dccfeea..dd3e824c89b 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -19,7 +19,7 @@ public function __construct(string $schemaFile) public function __get(string $name): mixed { - return $this->schema[$name] ?? null; + return $this->$name ?? $this->schema[$name] ?? null; } protected static function parseSchema(string $schemaFile): array From c2c4996b68095c2fa2be75e81b74b7e6278a951a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 22:08:42 +0100 Subject: [PATCH 014/129] Force relative path --- .../Features/Publications/Models/PublicationType.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index dd3e824c89b..232320bff1c 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -4,6 +4,8 @@ namespace Hyde\Framework\Features\Publications\Models; +use Hyde\Hyde; + class PublicationType { protected string $schemaFile; @@ -13,7 +15,7 @@ class PublicationType public function __construct(string $schemaFile) { $this->schemaFile = $schemaFile; - $this->directory = dirname($schemaFile); + $this->directory = Hyde::pathToRelative(dirname($schemaFile)); $this->schema = static::parseSchema($schemaFile); } From 87449c78e851a07010d62c462709d5faff9d62d1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 22:10:34 +0100 Subject: [PATCH 015/129] Refactor to use the PublicationType class --- packages/framework/src/PublicationHelper.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/packages/framework/src/PublicationHelper.php b/packages/framework/src/PublicationHelper.php index 8cb76147f39..402fdd96bbd 100644 --- a/packages/framework/src/PublicationHelper.php +++ b/packages/framework/src/PublicationHelper.php @@ -6,6 +6,7 @@ use Carbon\Carbon; use Hyde\Foundation\HydeKernel; +use Hyde\Framework\Features\Publications\Models\PublicationType; use Illuminate\Contracts\Validation\Factory as ValidationFactory; use Illuminate\Support\Str; use LaravelZero\Framework\Commands\Command; @@ -81,15 +82,8 @@ public static function getPublicationTypes(): Collection $pubTypes = Collection::create(); foreach ($schemaFiles as $schemaFile) { - $fileData = file_get_contents($schemaFile); - if (! $fileData) { - throw new \Exception("No data read from [$schemaFile]"); - } - $dirName = Collection::create(explode('/', dirname($schemaFile)))->last(); - $schema = Collection::create(json_decode($fileData, true)); - $schema->directory = $dirName; - $schema->schemaFile = $schemaFile; - $pubTypes->{$schema->directory} = $schema; + $publicationType = new PublicationType($schemaFile); + $pubTypes->{$publicationType->directory} = $publicationType; } return $pubTypes; From ac48f8cfd76432ccbb4f2e5646c07bcacd029367 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 22:10:49 +0100 Subject: [PATCH 016/129] Update return tag --- packages/framework/src/PublicationHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/PublicationHelper.php b/packages/framework/src/PublicationHelper.php index 402fdd96bbd..e8864374e32 100644 --- a/packages/framework/src/PublicationHelper.php +++ b/packages/framework/src/PublicationHelper.php @@ -71,7 +71,7 @@ public static function formatNameForStorage(string $pubTypeNameRaw) /** * Return a collection of all defined publication types, indexed by the directory name. * - * @return Collection + * @return Collection * * @throws \Exception */ From 3b4f12a448529424d692b5ff1e6064a3e5490ed0 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 22:11:03 +0100 Subject: [PATCH 017/129] Use Hyde::path() instead of base_path() --- packages/framework/src/PublicationHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/PublicationHelper.php b/packages/framework/src/PublicationHelper.php index e8864374e32..4cf8b7bb65b 100644 --- a/packages/framework/src/PublicationHelper.php +++ b/packages/framework/src/PublicationHelper.php @@ -77,7 +77,7 @@ public static function formatNameForStorage(string $pubTypeNameRaw) */ public static function getPublicationTypes(): Collection { - $root = base_path(); + $root = Hyde::path(); $schemaFiles = glob("$root/*/schema.json", GLOB_BRACE); $pubTypes = Collection::create(); From d421668a142c3ec1f0d637c8f5e1da2953bfa3bb Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 22:12:22 +0100 Subject: [PATCH 018/129] Add publication type property to publication pages --- packages/framework/src/Pages/PublicationPage.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index 54af6cea343..8f386167783 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -4,12 +4,16 @@ namespace Hyde\Pages; +use Hyde\Framework\Features\Publications\Models\PublicationType; + /** * Publication pages adds an easy way to create custom no-code page types, * with support using a custom front matter schema and Blade templates. */ class PublicationPage extends Concerns\HydePage { + protected PublicationType $type; + public function compile(): string { // TODO: Implement compile() method. From 6c77bb65622efdaddac34a8df863c3d371ea82b5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 22:12:39 +0100 Subject: [PATCH 019/129] Make property public to match parent class properties --- packages/framework/src/Pages/PublicationPage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index 8f386167783..cbba31342ba 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -12,7 +12,7 @@ */ class PublicationPage extends Concerns\HydePage { - protected PublicationType $type; + public PublicationType $type; public function compile(): string { From 0316554045b587e7bc6a3e3942478304d93d29da Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 22:13:45 +0100 Subject: [PATCH 020/129] Add publication type to constructor --- packages/framework/src/Pages/PublicationPage.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index cbba31342ba..d6c88200792 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -5,6 +5,7 @@ namespace Hyde\Pages; use Hyde\Framework\Features\Publications\Models\PublicationType; +use Hyde\Markdown\Models\FrontMatter; /** * Publication pages adds an easy way to create custom no-code page types, @@ -14,6 +15,13 @@ class PublicationPage extends Concerns\HydePage { public PublicationType $type; + public function __construct(PublicationType $type, string $identifier = '', FrontMatter|array $matter = []) + { + $this->type = $type; + + parent::__construct($identifier, $matter); + } + public function compile(): string { // TODO: Implement compile() method. From a1119f21d38031f3928ef01c06104845e1ec3911 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 22:14:57 +0100 Subject: [PATCH 021/129] Add todo --- packages/framework/src/PublicationHelper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/src/PublicationHelper.php b/packages/framework/src/PublicationHelper.php index 4cf8b7bb65b..0c7d91c17e2 100644 --- a/packages/framework/src/PublicationHelper.php +++ b/packages/framework/src/PublicationHelper.php @@ -71,6 +71,8 @@ public static function formatNameForStorage(string $pubTypeNameRaw) /** * Return a collection of all defined publication types, indexed by the directory name. * + * @todo We might want to refactor to cache this in the Kernel, maybe under $publications? + * * @return Collection * * @throws \Exception From d85996532c46e853f17e351593f094aa03d11f98 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 22:15:44 +0100 Subject: [PATCH 022/129] Add getters --- .../Publications/Models/PublicationType.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 232320bff1c..1485941a2ca 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -24,6 +24,21 @@ public function __get(string $name): mixed return $this->$name ?? $this->schema[$name] ?? null; } + public function getSchemaFile(): string + { + return $this->schemaFile; + } + + public function getDirectory(): string + { + return $this->directory; + } + + public function getSchema(): array + { + return $this->schema; + } + protected static function parseSchema(string $schemaFile): array { return json_decode(file_get_contents($schemaFile), true, 512, JSON_THROW_ON_ERROR); From 501876399408ff91af69de4e4b016724163085bb Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 22:15:55 +0100 Subject: [PATCH 023/129] Use added getter --- packages/framework/src/PublicationHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/PublicationHelper.php b/packages/framework/src/PublicationHelper.php index 0c7d91c17e2..bc261b476df 100644 --- a/packages/framework/src/PublicationHelper.php +++ b/packages/framework/src/PublicationHelper.php @@ -85,7 +85,7 @@ public static function getPublicationTypes(): Collection $pubTypes = Collection::create(); foreach ($schemaFiles as $schemaFile) { $publicationType = new PublicationType($schemaFile); - $pubTypes->{$publicationType->directory} = $publicationType; + $pubTypes->{$publicationType->getDirectory()} = $publicationType; } return $pubTypes; From 6198b19c758cbc51696ab18250b3351ccefcbd77 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 22:18:31 +0100 Subject: [PATCH 024/129] Type hint the PublicationType class instead of Collection --- .../src/Console/Commands/BuildPublicationsCommand.php | 5 +++-- packages/framework/src/PublicationHelper.php | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php index 5ff6f07ba09..16783bc11d0 100644 --- a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php +++ b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php @@ -9,6 +9,7 @@ use Hyde\Framework\Features\BuildTasks\PostBuildTasks\GenerateRssFeed; use Hyde\Framework\Features\BuildTasks\PostBuildTasks\GenerateSearch; use Hyde\Framework\Features\BuildTasks\PostBuildTasks\GenerateSitemap; +use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Framework\Services\BuildService; use Hyde\Framework\Services\BuildTaskService; use Hyde\Framework\Services\DiscoveryService; @@ -79,7 +80,7 @@ protected function build(): void } } - protected function buildDetailPages(string $targetDirectory, Collection $pubType, Collection $publications): void + protected function buildDetailPages(string $targetDirectory, PublicationType $pubType, Collection $publications): void { $template = $pubType->detailTemplate; @@ -98,7 +99,7 @@ protected function buildDetailPages(string $targetDirectory, Collection $pubType } } - protected function buildListPage(string $targetDirectory, Collection $pubType, Collection $publications): void + protected function buildListPage(string $targetDirectory, PublicationType $pubType, Collection $publications): void { $template = 'hyde::pubtypes.'.$pubType->listTemplate; $this->info(' Building list page ...'); diff --git a/packages/framework/src/PublicationHelper.php b/packages/framework/src/PublicationHelper.php index bc261b476df..41e72af2616 100644 --- a/packages/framework/src/PublicationHelper.php +++ b/packages/framework/src/PublicationHelper.php @@ -94,12 +94,12 @@ public static function getPublicationTypes(): Collection /** * Return all publications for a given pub type, optionally sorted by the publication's sortField. * - * @param Collection $pubType + * @param PublicationType $pubType * @return Collection * * @throws \Safe\Exceptions\FilesystemException */ - public static function getPublicationsForPubType(Collection $pubType, $sort = true): Collection + public static function getPublicationsForPubType(PublicationType $pubType, $sort = true): Collection { $root = base_path(); $files = glob("$root/{$pubType->directory}/*.md"); @@ -121,12 +121,12 @@ public static function getPublicationsForPubType(Collection $pubType, $sort = tr /** * Return all media items for a given publication type. * - * @param Collection $pubType + * @param PublicationType $pubType * @return Collection * * @throws \Safe\Exceptions\FilesystemException */ - public static function getMediaForPubType(Collection $pubType, $sort = true): Collection + public static function getMediaForPubType(PublicationType $pubType, $sort = true): Collection { $root = base_path(); $files = glob("$root/_media/{$pubType->directory}/*.{jpg,jpeg,png,gif,pdf}", GLOB_BRACE); From 8b859adf4e6938e606868e35dbc6ff11d9952cd4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 22:34:43 +0100 Subject: [PATCH 025/129] Change PublicationPage to extend BaseMarkdownPage --- packages/framework/src/Pages/PublicationPage.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index d6c88200792..2cec19796cf 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -6,20 +6,21 @@ use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Markdown\Models\FrontMatter; +use Hyde\Markdown\Models\Markdown; /** * Publication pages adds an easy way to create custom no-code page types, * with support using a custom front matter schema and Blade templates. */ -class PublicationPage extends Concerns\HydePage +class PublicationPage extends Concerns\BaseMarkdownPage { public PublicationType $type; - public function __construct(PublicationType $type, string $identifier = '', FrontMatter|array $matter = []) + public function __construct(PublicationType $type, string $identifier = '', FrontMatter|array $matter = [], Markdown|string $markdown = '') { $this->type = $type; - parent::__construct($identifier, $matter); + parent::__construct($identifier, $matter, $markdown); } public function compile(): string From 4447a6cfc71787b5738c3f9a690df4a1574d1ee6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 22:35:04 +0100 Subject: [PATCH 026/129] Add static get method to PublicationType class --- .../Features/Publications/Models/PublicationType.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 1485941a2ca..e1b5fa3bbe4 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -12,6 +12,11 @@ class PublicationType protected string $directory; protected array $schema; + public static function get(string $name): self + { + return new self(Hyde::path("$name/schema.json")); + } + public function __construct(string $schemaFile) { $this->schemaFile = $schemaFile; From e63f1f98ffdb51de04c991b9d1b0354a8046e273 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 22:39:38 +0100 Subject: [PATCH 027/129] Refactor to return PublicationPage instead of Collection --- packages/framework/src/PublicationHelper.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/PublicationHelper.php b/packages/framework/src/PublicationHelper.php index 41e72af2616..439acd56f74 100644 --- a/packages/framework/src/PublicationHelper.php +++ b/packages/framework/src/PublicationHelper.php @@ -7,6 +7,7 @@ use Carbon\Carbon; use Hyde\Foundation\HydeKernel; use Hyde\Framework\Features\Publications\Models\PublicationType; +use Hyde\Pages\PublicationPage; use Illuminate\Contracts\Validation\Factory as ValidationFactory; use Illuminate\Support\Str; use LaravelZero\Framework\Commands\Command; @@ -149,7 +150,7 @@ public static function getMediaForPubType(PublicationType $pubType, $sort = true * @param string $fileData * @return Collection */ - public static function getPublicationData(string $mdFileName): Collection + public static function getPublicationData(string $mdFileName): PublicationPage { $fileData = file_get_contents($mdFileName); if (! $fileData) { @@ -162,7 +163,10 @@ public static function getPublicationData(string $mdFileName): Collection $matter['__slug'] = basename($mdFileName, '.md'); $matter['__createdDatetime'] = Carbon::createFromTimestamp($matter['__createdAt']); - return Collection::create(['matter' => $matter, 'markdown' => $markdown]); + $type = PublicationType::get(basename(dirname($mdFileName))); + + $identifier = basename($mdFileName, '.md'); + return new PublicationPage($type, $identifier, $matter, $markdown); } /** From 740c2507e8bc3a6e4b60b66f147e7618e1e19e3a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 22:46:20 +0100 Subject: [PATCH 028/129] Add path mapping placeholders --- packages/framework/src/Pages/PublicationPage.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index 2cec19796cf..c7e9dc50a6b 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -16,6 +16,10 @@ class PublicationPage extends Concerns\BaseMarkdownPage { public PublicationType $type; + public static string $sourceDirectory = '__publications'; + public static string $outputDirectory = '__publications'; + public static string $template = '__dynamic'; + public function __construct(PublicationType $type, string $identifier = '', FrontMatter|array $matter = [], Markdown|string $markdown = '') { $this->type = $type; From 1ef357b07cac91d97bab6f22a0f3dfcd2de2c64d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 18 Nov 2022 22:46:50 +0100 Subject: [PATCH 029/129] Implement publication discovery --- .../src/Foundation/PageCollection.php | 18 +++++++++++++++++- .../tests/Feature/PageCollectionTest.php | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Foundation/PageCollection.php b/packages/framework/src/Foundation/PageCollection.php index 0220642e55a..458e4599b57 100644 --- a/packages/framework/src/Foundation/PageCollection.php +++ b/packages/framework/src/Foundation/PageCollection.php @@ -7,6 +7,7 @@ use Hyde\Facades\Features; use Hyde\Foundation\Concerns\BaseFoundationCollection; use Hyde\Framework\Exceptions\FileNotFoundException; +use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Pages\BladePage; use Hyde\Pages\Concerns\HydePage; use Hyde\Pages\DocumentationPage; @@ -14,6 +15,7 @@ use Hyde\Pages\MarkdownPage; use Hyde\Pages\MarkdownPost; use Hyde\Pages\PublicationPage; +use Hyde\PublicationHelper; use Illuminate\Support\Collection; /** @@ -62,7 +64,7 @@ protected function runDiscovery(): self } if (Features::hasPublicationPages()) { - $this->discoverPagesFor(PublicationPage::class); + $this->discoverPublicationPages(); } return $this; @@ -98,4 +100,18 @@ protected function discover(HydePage $page): self return $this; } + + protected function discoverPublicationPages(): void + { + PublicationHelper::getPublicationTypes()->each(function (PublicationType $type) { + $this->discoverPublicationPagesForType($type); + }); + } + + protected function discoverPublicationPagesForType(PublicationType $type): void + { + PublicationHelper::getPublicationsForPubType($type)->each(function ($publication) { + $this->discover($publication); + }); + } } diff --git a/packages/framework/tests/Feature/PageCollectionTest.php b/packages/framework/tests/Feature/PageCollectionTest.php index f2ab12cbbd5..0a33505988c 100644 --- a/packages/framework/tests/Feature/PageCollectionTest.php +++ b/packages/framework/tests/Feature/PageCollectionTest.php @@ -11,6 +11,7 @@ use Hyde\Pages\HtmlPage; use Hyde\Pages\MarkdownPage; use Hyde\Pages\MarkdownPost; +use Hyde\Pages\PublicationPage; use Hyde\Testing\TestCase; use Illuminate\Support\Collection; use Illuminate\Support\Facades\File; @@ -180,6 +181,21 @@ public function test_pages_with_custom_source_directories_are_discovered_properl public function test_publication_pages_are_discovered() { - // TODO: Implement test_publication_pages_are_discovered() method. + @mkdir(Hyde::path('publication')); + file_put_contents(Hyde::path('publication/schema.json'), json_encode(['foo' => 'bar'])); + file_put_contents(Hyde::path('publication/foo.md'), '--- +__canonical: canonical +__createdAt: 2022-11-16 11:32:52 +foo: bar +--- + +Hello World! +'); + + $collection = PageCollection::boot(Hyde::getInstance())->getPages(); + // $this->assertCount(1, $collection); + $this->assertInstanceOf(PublicationPage::class, $collection->get('__publications/foo.md')); + + File::deleteDirectory(Hyde::path('publication')); } } From 8d7b536789f62a9cf38d7af30932c289d7da0099 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 18 Nov 2022 21:47:04 +0000 Subject: [PATCH 030/129] Apply fixes from StyleCI --- .../framework/src/Console/Commands/BuildPublicationsCommand.php | 2 +- packages/framework/src/Foundation/PageCollection.php | 1 - packages/framework/src/PublicationHelper.php | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php index 16783bc11d0..3a9cead9ed8 100644 --- a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php +++ b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php @@ -14,8 +14,8 @@ use Hyde\Framework\Services\BuildTaskService; use Hyde\Framework\Services\DiscoveryService; use Hyde\Hyde; -use Hyde\PublicationHelper; use Hyde\Pages\MarkdownPage; +use Hyde\PublicationHelper; use Illuminate\Support\Facades\Config; use LaravelZero\Framework\Commands\Command; use Rgasch\Collection\Collection; diff --git a/packages/framework/src/Foundation/PageCollection.php b/packages/framework/src/Foundation/PageCollection.php index 458e4599b57..3c607b7f152 100644 --- a/packages/framework/src/Foundation/PageCollection.php +++ b/packages/framework/src/Foundation/PageCollection.php @@ -14,7 +14,6 @@ use Hyde\Pages\HtmlPage; use Hyde\Pages\MarkdownPage; use Hyde\Pages\MarkdownPost; -use Hyde\Pages\PublicationPage; use Hyde\PublicationHelper; use Illuminate\Support\Collection; diff --git a/packages/framework/src/PublicationHelper.php b/packages/framework/src/PublicationHelper.php index 439acd56f74..82f824f63c6 100644 --- a/packages/framework/src/PublicationHelper.php +++ b/packages/framework/src/PublicationHelper.php @@ -166,6 +166,7 @@ public static function getPublicationData(string $mdFileName): PublicationPage $type = PublicationType::get(basename(dirname($mdFileName))); $identifier = basename($mdFileName, '.md'); + return new PublicationPage($type, $identifier, $matter, $markdown); } From f7ba1a26b8a83ef6c746c25fbe9769d6ad84b294 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 12:57:01 +0100 Subject: [PATCH 031/129] Add todo --- packages/framework/tests/Feature/PageCollectionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PageCollectionTest.php b/packages/framework/tests/Feature/PageCollectionTest.php index 0a33505988c..dcc3524fbfa 100644 --- a/packages/framework/tests/Feature/PageCollectionTest.php +++ b/packages/framework/tests/Feature/PageCollectionTest.php @@ -193,7 +193,7 @@ public function test_publication_pages_are_discovered() '); $collection = PageCollection::boot(Hyde::getInstance())->getPages(); - // $this->assertCount(1, $collection); + // $this->assertCount(1, $collection); // TODO: Fix this $this->assertInstanceOf(PublicationPage::class, $collection->get('__publications/foo.md')); File::deleteDirectory(Hyde::path('publication')); From a3b7e8898874097a89991761e6b8c4dafd871aa3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 12:57:15 +0100 Subject: [PATCH 032/129] Remove error suppression in test --- packages/framework/tests/Feature/PageCollectionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PageCollectionTest.php b/packages/framework/tests/Feature/PageCollectionTest.php index dcc3524fbfa..d6df8b7f0b7 100644 --- a/packages/framework/tests/Feature/PageCollectionTest.php +++ b/packages/framework/tests/Feature/PageCollectionTest.php @@ -181,7 +181,7 @@ public function test_pages_with_custom_source_directories_are_discovered_properl public function test_publication_pages_are_discovered() { - @mkdir(Hyde::path('publication')); + mkdir(Hyde::path('publication')); file_put_contents(Hyde::path('publication/schema.json'), json_encode(['foo' => 'bar'])); file_put_contents(Hyde::path('publication/foo.md'), '--- __canonical: canonical From e7f4ef11031c110a5e72054116bf4bcc87a28d5f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 12:57:50 +0100 Subject: [PATCH 033/129] Add todo --- packages/framework/src/Pages/PublicationPage.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index c7e9dc50a6b..e52269d1723 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -27,6 +27,8 @@ public function __construct(PublicationType $type, string $identifier = '', Fron parent::__construct($identifier, $matter, $markdown); } + // TODO: override method to get output directory from publication type etc + public function compile(): string { // TODO: Implement compile() method. From 9eb27ada43e60957ec63da6a37fd94a32e9e57d2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 14:21:32 +0100 Subject: [PATCH 034/129] Create PublicationPageTest.php --- .../tests/Feature/PublicationPageTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 packages/framework/tests/Feature/PublicationPageTest.php diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php new file mode 100644 index 00000000000..761edd4ee89 --- /dev/null +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -0,0 +1,15 @@ + Date: Sat, 19 Nov 2022 14:25:37 +0100 Subject: [PATCH 035/129] Test publication pages are routable --- .../tests/Feature/PublicationPageTest.php | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index 761edd4ee89..cbe88af5d09 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -4,12 +4,43 @@ namespace Hyde\Framework\Testing\Feature; +use Hyde\Framework\Features\Publications\Models\PublicationType; +use Hyde\Hyde; +use Hyde\Pages\PublicationPage; +use Hyde\Support\Models\Route; use Hyde\Testing\TestCase; +use function deleteDirectory; +use function file_put_contents; +use function json_encode; +use function mkdir; + /** * @covers \Hyde\Pages\PublicationPage */ class PublicationPageTest extends TestCase { - // + public function test_publication_pages_are_routable() + { + mkdir(Hyde::path('publication')); + file_put_contents(Hyde::path('publication/schema.json'), json_encode(['foo' => 'bar'])); + file_put_contents(Hyde::path('publication/foo.md'), '--- +__canonical: canonical +__createdAt: 2022-11-16 11:32:52 +foo: bar +--- + +Hello World! +'); + + $page = new PublicationPage(new PublicationType('publication/schema.json'), 'foo'); + + $this->assertInstanceOf(Route::class, $page->getRoute()); + $this->assertEquals(new Route($page), $page->getRoute()); + $this->assertSame($page->getRoute()->getLink(), $page->getLink()); + $this->assertArrayHasKey($page->getSourcePath(), Hyde::pages()); + $this->assertArrayHasKey($page->getRouteKey(), Hyde::routes()); + + deleteDirectory(Hyde::path('publication')); + } } From faa25da528abcbd11f07c3480004e18b7a92960c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 14:28:40 +0100 Subject: [PATCH 036/129] Test publication pages are discoverable and parsable --- .../tests/Feature/PublicationPageTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index cbe88af5d09..3b19d5ce651 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -43,4 +43,23 @@ public function test_publication_pages_are_routable() deleteDirectory(Hyde::path('publication')); } + + public function test_publication_pages_are_discoverable() + { + mkdir(Hyde::path('publication')); + file_put_contents(Hyde::path('publication/schema.json'), json_encode(['foo' => 'bar'])); + file_put_contents(Hyde::path('publication/foo.md'), '--- +__canonical: canonical +__createdAt: 2022-11-16 11:32:52 +foo: bar +--- + +Hello World! +'); + + $collection = Hyde::pages()->getPages(); + $this->assertInstanceOf(PublicationPage::class, $collection->get('__publications/foo.md')); + + deleteDirectory(Hyde::path('publication')); + } } From 8b76a3e6eed904c99acf5e46877c800f68b6bc7c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 14:29:29 +0100 Subject: [PATCH 037/129] Test publication pages are discoverable and compilable --- .../tests/Feature/PublicationPageTest.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index 3b19d5ce651..6c585da1add 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -62,4 +62,24 @@ public function test_publication_pages_are_discoverable() deleteDirectory(Hyde::path('publication')); } + + public function test_publication_pages_are_compilable() + { + mkdir(Hyde::path('publication')); + file_put_contents(Hyde::path('publication/schema.json'), json_encode(['foo' => 'bar'])); + file_put_contents(Hyde::path('publication/foo.md'), '--- +__canonical: canonical +__createdAt: 2022-11-16 11:32:52 +foo: bar +--- + +Hello World! +'); + + $page = new PublicationPage(new PublicationType('publication/schema.json'), 'foo'); + + $this->assertStringContainsString('Hello World!', $page->compile()); + + deleteDirectory(Hyde::path('publication')); + } } From b0aea50db55ebd4bc8e19a546c348638f0d7903e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 14:29:55 +0100 Subject: [PATCH 038/129] Extract method --- .../tests/Feature/PublicationPageTest.php | 46 ++++++++----------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index 6c585da1add..fec5dc883fc 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -23,15 +23,7 @@ class PublicationPageTest extends TestCase public function test_publication_pages_are_routable() { mkdir(Hyde::path('publication')); - file_put_contents(Hyde::path('publication/schema.json'), json_encode(['foo' => 'bar'])); - file_put_contents(Hyde::path('publication/foo.md'), '--- -__canonical: canonical -__createdAt: 2022-11-16 11:32:52 -foo: bar ---- - -Hello World! -'); + $this->createPublicationFiles(); $page = new PublicationPage(new PublicationType('publication/schema.json'), 'foo'); @@ -47,17 +39,9 @@ public function test_publication_pages_are_routable() public function test_publication_pages_are_discoverable() { mkdir(Hyde::path('publication')); - file_put_contents(Hyde::path('publication/schema.json'), json_encode(['foo' => 'bar'])); - file_put_contents(Hyde::path('publication/foo.md'), '--- -__canonical: canonical -__createdAt: 2022-11-16 11:32:52 -foo: bar ---- + $this->createPublicationFiles(); -Hello World! -'); - - $collection = Hyde::pages()->getPages(); + $collection = Hyde::pages()->getPages(); $this->assertInstanceOf(PublicationPage::class, $collection->get('__publications/foo.md')); deleteDirectory(Hyde::path('publication')); @@ -66,20 +50,28 @@ public function test_publication_pages_are_discoverable() public function test_publication_pages_are_compilable() { mkdir(Hyde::path('publication')); + $this->createPublicationFiles(); + + $page = new PublicationPage(new PublicationType('publication/schema.json'), 'foo'); + + $this->assertStringContainsString('Hello World!', $page->compile()); + + deleteDirectory(Hyde::path('publication')); + } + + protected function createPublicationFiles(): void + { file_put_contents(Hyde::path('publication/schema.json'), json_encode(['foo' => 'bar'])); - file_put_contents(Hyde::path('publication/foo.md'), '--- + file_put_contents( + Hyde::path('publication/foo.md'), + '--- __canonical: canonical __createdAt: 2022-11-16 11:32:52 foo: bar --- Hello World! -'); - - $page = new PublicationPage(new PublicationType('publication/schema.json'), 'foo'); - - $this->assertStringContainsString('Hello World!', $page->compile()); - - deleteDirectory(Hyde::path('publication')); +' + ); } } From d524de8cfc82e53de58e74572ef625d35a5d7950 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 14:31:01 +0100 Subject: [PATCH 039/129] Update test directory name --- .../tests/Feature/PublicationPageTest.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index fec5dc883fc..b95595c7c6c 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -22,10 +22,10 @@ class PublicationPageTest extends TestCase { public function test_publication_pages_are_routable() { - mkdir(Hyde::path('publication')); + mkdir(Hyde::path('test-publication')); $this->createPublicationFiles(); - $page = new PublicationPage(new PublicationType('publication/schema.json'), 'foo'); + $page = new PublicationPage(new PublicationType('test-publication/schema.json'), 'foo'); $this->assertInstanceOf(Route::class, $page->getRoute()); $this->assertEquals(new Route($page), $page->getRoute()); @@ -33,37 +33,37 @@ public function test_publication_pages_are_routable() $this->assertArrayHasKey($page->getSourcePath(), Hyde::pages()); $this->assertArrayHasKey($page->getRouteKey(), Hyde::routes()); - deleteDirectory(Hyde::path('publication')); + deleteDirectory(Hyde::path('test-publication')); } public function test_publication_pages_are_discoverable() { - mkdir(Hyde::path('publication')); + mkdir(Hyde::path('test-publication')); $this->createPublicationFiles(); $collection = Hyde::pages()->getPages(); $this->assertInstanceOf(PublicationPage::class, $collection->get('__publications/foo.md')); - deleteDirectory(Hyde::path('publication')); + deleteDirectory(Hyde::path('test-publication')); } public function test_publication_pages_are_compilable() { - mkdir(Hyde::path('publication')); + mkdir(Hyde::path('test-publication')); $this->createPublicationFiles(); - $page = new PublicationPage(new PublicationType('publication/schema.json'), 'foo'); + $page = new PublicationPage(new PublicationType('test-publication/schema.json'), 'foo'); $this->assertStringContainsString('Hello World!', $page->compile()); - deleteDirectory(Hyde::path('publication')); + deleteDirectory(Hyde::path('test-publication')); } protected function createPublicationFiles(): void { - file_put_contents(Hyde::path('publication/schema.json'), json_encode(['foo' => 'bar'])); + file_put_contents(Hyde::path('test-publication/schema.json'), json_encode(['foo' => 'bar'])); file_put_contents( - Hyde::path('publication/foo.md'), + Hyde::path('test-publication/foo.md'), '--- __canonical: canonical __createdAt: 2022-11-16 11:32:52 From 3e2daca97302116c1255c3f04d436817685283ab Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 14:51:09 +0100 Subject: [PATCH 040/129] Add TODOs --- .../framework/src/Console/Commands/BuildPublicationsCommand.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php index 3a9cead9ed8..f3ea7e38ad2 100644 --- a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php +++ b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php @@ -80,6 +80,7 @@ protected function build(): void } } + // TODO: Is detail page the right name? protected function buildDetailPages(string $targetDirectory, PublicationType $pubType, Collection $publications): void { $template = $pubType->detailTemplate; @@ -90,6 +91,7 @@ protected function buildDetailPages(string $targetDirectory, PublicationType $pu view()->share('currentPage', $template); view()->share('currentRoute', $page->getRoute()); + // TODO this should not be in the hyde namespace as user is expected to implement this right? $detailTemplate = 'hyde::pubtypes.'.$template; foreach ($publications as $publication) { $slug = $publication->matter->__slug; From da463ad1ba3c24defbe5aaddb2c7dae14e379476 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:04:03 +0100 Subject: [PATCH 041/129] Implement compile() method --- packages/framework/src/Pages/PublicationPage.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index e52269d1723..39ea74ee243 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -8,6 +8,10 @@ use Hyde\Markdown\Models\FrontMatter; use Hyde\Markdown\Models\Markdown; +use Illuminate\Support\Str; + +use function view; + /** * Publication pages adds an easy way to create custom no-code page types, * with support using a custom front matter schema and Blade templates. @@ -31,6 +35,9 @@ public function __construct(PublicationType $type, string $identifier = '', Fron public function compile(): string { - // TODO: Implement compile() method. + $detailTemplate = $this->type->getSchema()['detailTemplate']; + $component = Str::before("pubtypes.$detailTemplate", '.blade.php'); + + return view('hyde::layouts.pubtype')->with(['component' => $component, 'publication' => $this])->render(); } } From aacf86afb3e30e48515590c9835fec0eeb75477f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:05:03 +0100 Subject: [PATCH 042/129] Test with real files --- .../tests/Feature/PublicationPageTest.php | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index b95595c7c6c..8561ec2f984 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -14,6 +14,7 @@ use function file_put_contents; use function json_encode; use function mkdir; +use function resource_path; /** * @covers \Hyde\Pages\PublicationPage @@ -50,15 +51,54 @@ public function test_publication_pages_are_discoverable() public function test_publication_pages_are_compilable() { mkdir(Hyde::path('test-publication')); - $this->createPublicationFiles(); + $this->createRealPublicationFiles(); $page = new PublicationPage(new PublicationType('test-publication/schema.json'), 'foo'); + Hyde::shareViewData($page); $this->assertStringContainsString('Hello World!', $page->compile()); deleteDirectory(Hyde::path('test-publication')); } + protected function createRealPublicationFiles(): void + { + file_put_contents(Hyde::path('test-publication/schema.json'), '{ + "name": "test", + "canonicalField": "slug", + "sortField": "__createdAt", + "sortDirection": "DESC", + "pagesize": 0, + "prevNextLinks": true, + "detailTemplate": "test_detail.blade.php", + "listTemplate": "test_list.blade.php", + "fields": [ + { + "name": "slug", + "min": "4", + "max": "32", + "type": "string" + } + ] +}'); + file_put_contents( + Hyde::path('test-publication/foo.md'), + '--- +__canonical: canonical +__createdAt: 2022-11-16 11:32:52 +foo: bar +--- + +Hello World! +' + ); + + // Temporary until we settle on where to store templates + @mkdir(resource_path('views/pubtypes')); + $this->file('resources/views/pubtypes/test_list.blade.php'); + $this->file('resources/views/pubtypes/test_detail.blade.php', '{{ ($publication->markdown()) }}'); + } + protected function createPublicationFiles(): void { file_put_contents(Hyde::path('test-publication/schema.json'), json_encode(['foo' => 'bar'])); From ca90658d26b7ccbfbe2e17a2730f3a25dc9228e3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:05:15 +0100 Subject: [PATCH 043/129] Add todo --- .../Framework/Features/Publications/Models/PublicationType.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index e1b5fa3bbe4..5221a4013b6 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -48,4 +48,6 @@ protected static function parseSchema(string $schemaFile): array { return json_decode(file_get_contents($schemaFile), true, 512, JSON_THROW_ON_ERROR); } + + // TODO build list pages and detail pages for each publication type } From c7f12958e15e78b3a26904380d4cc0e27ef66602 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:10:09 +0100 Subject: [PATCH 044/129] Test publication pages are properly parsed --- .../tests/Feature/PublicationPageTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index 8561ec2f984..3e31bd4c5ba 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -48,6 +48,22 @@ public function test_publication_pages_are_discoverable() deleteDirectory(Hyde::path('test-publication')); } + + public function test_publication_pages_are_properly_parsed() + { + mkdir(Hyde::path('test-publication')); + $this->createPublicationFiles(); + + $page = Hyde::pages()->getPages()->get('__publications/foo.md'); + $this->assertInstanceOf(PublicationPage::class, $page); + $this->assertEquals('foo', $page->getIdentifier()); + $this->assertEquals('bar', $page->matter('foo')); + $this->assertEquals('canonical', $page->matter('__canonical')); + $this->assertEquals("Hello World!\n", $page->markdown()->body()); + + deleteDirectory(Hyde::path('test-publication')); + } + public function test_publication_pages_are_compilable() { mkdir(Hyde::path('test-publication')); From 0440ddcea3d57868bae545ecb722e4952a4e71fc Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:10:22 +0100 Subject: [PATCH 045/129] Update PublicationPageTest.php --- packages/framework/tests/Feature/PublicationPageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index 3e31bd4c5ba..c3f1a0805d1 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -112,7 +112,7 @@ protected function createRealPublicationFiles(): void // Temporary until we settle on where to store templates @mkdir(resource_path('views/pubtypes')); $this->file('resources/views/pubtypes/test_list.blade.php'); - $this->file('resources/views/pubtypes/test_detail.blade.php', '{{ ($publication->markdown()) }}'); + $this->file('resources/views/pubtypes/test_detail.blade.php', '{{ ($publication->markdown()->body()) }}'); } protected function createPublicationFiles(): void From f0f2c6d94cbbeb327090e078e0c8c5e040dad01e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:14:30 +0100 Subject: [PATCH 046/129] Update PublicationPageTest.php --- packages/framework/tests/Feature/PublicationPageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index c3f1a0805d1..143fc9b3e28 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -69,7 +69,7 @@ public function test_publication_pages_are_compilable() mkdir(Hyde::path('test-publication')); $this->createRealPublicationFiles(); - $page = new PublicationPage(new PublicationType('test-publication/schema.json'), 'foo'); + $page = Hyde::pages()->getPages()->get('__publications/foo.md'); Hyde::shareViewData($page); $this->assertStringContainsString('Hello World!', $page->compile()); From e3921932cb6c78811689b0d40bdbe30e8668e601 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sat, 19 Nov 2022 14:14:47 +0000 Subject: [PATCH 047/129] Apply fixes from StyleCI --- packages/framework/src/Pages/PublicationPage.php | 2 -- .../framework/tests/Feature/PublicationPageTest.php | 10 ++++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index 39ea74ee243..c6de2824424 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -7,9 +7,7 @@ use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Markdown\Models\FrontMatter; use Hyde\Markdown\Models\Markdown; - use Illuminate\Support\Str; - use function view; /** diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index 143fc9b3e28..3e3ebd67efb 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -4,14 +4,13 @@ namespace Hyde\Framework\Testing\Feature; +use function deleteDirectory; +use function file_put_contents; use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Hyde; use Hyde\Pages\PublicationPage; use Hyde\Support\Models\Route; use Hyde\Testing\TestCase; - -use function deleteDirectory; -use function file_put_contents; use function json_encode; use function mkdir; use function resource_path; @@ -43,12 +42,11 @@ public function test_publication_pages_are_discoverable() $this->createPublicationFiles(); $collection = Hyde::pages()->getPages(); - $this->assertInstanceOf(PublicationPage::class, $collection->get('__publications/foo.md')); + $this->assertInstanceOf(PublicationPage::class, $collection->get('__publications/foo.md')); - deleteDirectory(Hyde::path('test-publication')); + deleteDirectory(Hyde::path('test-publication')); } - public function test_publication_pages_are_properly_parsed() { mkdir(Hyde::path('test-publication')); From d91c61d8f26ef1f525ad909df66606942cc2f376 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:17:07 +0100 Subject: [PATCH 048/129] Refactor to use setup/teardown methods --- .../tests/Feature/PublicationPageTest.php | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index 3e3ebd67efb..59b8fc0cb9f 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -20,9 +20,22 @@ */ class PublicationPageTest extends TestCase { - public function test_publication_pages_are_routable() + protected function setUp(): void { + parent::setUp(); + mkdir(Hyde::path('test-publication')); + } + + protected function tearDown(): void + { + deleteDirectory(Hyde::path('test-publication')); + + parent::tearDown(); + } + + public function test_publication_pages_are_routable() + { $this->createPublicationFiles(); $page = new PublicationPage(new PublicationType('test-publication/schema.json'), 'foo'); @@ -32,24 +45,18 @@ public function test_publication_pages_are_routable() $this->assertSame($page->getRoute()->getLink(), $page->getLink()); $this->assertArrayHasKey($page->getSourcePath(), Hyde::pages()); $this->assertArrayHasKey($page->getRouteKey(), Hyde::routes()); - - deleteDirectory(Hyde::path('test-publication')); } public function test_publication_pages_are_discoverable() { - mkdir(Hyde::path('test-publication')); $this->createPublicationFiles(); $collection = Hyde::pages()->getPages(); $this->assertInstanceOf(PublicationPage::class, $collection->get('__publications/foo.md')); - - deleteDirectory(Hyde::path('test-publication')); } public function test_publication_pages_are_properly_parsed() { - mkdir(Hyde::path('test-publication')); $this->createPublicationFiles(); $page = Hyde::pages()->getPages()->get('__publications/foo.md'); @@ -58,21 +65,16 @@ public function test_publication_pages_are_properly_parsed() $this->assertEquals('bar', $page->matter('foo')); $this->assertEquals('canonical', $page->matter('__canonical')); $this->assertEquals("Hello World!\n", $page->markdown()->body()); - - deleteDirectory(Hyde::path('test-publication')); } public function test_publication_pages_are_compilable() { - mkdir(Hyde::path('test-publication')); $this->createRealPublicationFiles(); $page = Hyde::pages()->getPages()->get('__publications/foo.md'); Hyde::shareViewData($page); $this->assertStringContainsString('Hello World!', $page->compile()); - - deleteDirectory(Hyde::path('test-publication')); } protected function createRealPublicationFiles(): void From 9fa38bf4c5762a38a17b037d806df2cbf7257d34 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:23:06 +0100 Subject: [PATCH 049/129] Add todo --- .../framework/src/Console/Commands/BuildPublicationsCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php index f3ea7e38ad2..8267649d4ad 100644 --- a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php +++ b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php @@ -101,6 +101,7 @@ protected function buildDetailPages(string $targetDirectory, PublicationType $pu } } + // TODO: Move to post build task? protected function buildListPage(string $targetDirectory, PublicationType $pubType, Collection $publications): void { $template = 'hyde::pubtypes.'.$pubType->listTemplate; From 3e7c85c8d82265823d7b5fee74c96ec357ac169c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:24:35 +0100 Subject: [PATCH 050/129] Display memory usage after build is finished --- packages/framework/src/Console/Commands/BuildSiteCommand.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/framework/src/Console/Commands/BuildSiteCommand.php b/packages/framework/src/Console/Commands/BuildSiteCommand.php index e8a7485497e..11a13fe4183 100644 --- a/packages/framework/src/Console/Commands/BuildSiteCommand.php +++ b/packages/framework/src/Console/Commands/BuildSiteCommand.php @@ -15,6 +15,8 @@ use Illuminate\Support\Facades\Config; use LaravelZero\Framework\Commands\Command; +use function memory_get_peak_usage; + /** * Hyde Command to run the Build Process. * @@ -55,6 +57,8 @@ public function handle(): int $this->printFinishMessage($time_start); + $this->output->writeln('Max memory used: '.memory_get_peak_usage() / 1024 / 1024 .' MB'); + return Command::SUCCESS; } From 759886e7480f039eff6a8674ee89628fb98c586c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:28:00 +0100 Subject: [PATCH 051/129] Refactor BuildPublications command to only build publications so it can be used in the main build command --- .../Commands/BuildPublicationsCommand.php | 125 +----------------- 1 file changed, 2 insertions(+), 123 deletions(-) diff --git a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php index 8267649d4ad..6d4af2cffbe 100644 --- a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php +++ b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php @@ -28,41 +28,17 @@ class BuildPublicationsCommand extends Command implements CommandHandleInterface { /** @var string */ - protected $signature = 'build:publications - {--run-dev : Run the NPM dev script after build} - {--run-prod : Run the NPM prod script after build} - {--run-prettier : Format the output using NPM Prettier} - {--pretty-urls : Should links in output use pretty URLs?} - {--no-api : Disable API calls, for example, Torchlight}'; + protected $signature = 'build:publications'; /** @var string */ - protected $description = 'Build the PubType site'; + protected $description = 'Build the site publications'; protected BuildService $service; public function handle(): int { - $time_start = microtime(true); - - $this->title('Building your static site!'); - - $this->service = new BuildService($this->output); - - $this->runPreBuildActions(); - - $this->service->cleanOutputDirectory(); - - $this->service->transferMediaAssets(); - - // FIXME: refactor $this->build(); - $this->runPostBuildActions(); - - $this->printFinishMessage($time_start); - - $this->output->writeln('Max memory used: '.memory_get_peak_usage() / 1024 / 1024 .' MB'); - return Command::SUCCESS; } @@ -109,101 +85,4 @@ protected function buildListPage(string $targetDirectory, PublicationType $pubTy $html = view($template)->with('publications', $publications)->render(); file_put_contents("$targetDirectory/index.html", $html); } - - protected function runPreBuildActions(): void - { - if ($this->option('no-api')) { - $this->info('Disabling external API calls'); - $this->newLine(); - $config = config('hyde.features'); - unset($config[array_search('torchlight', $config)]); - Config::set(['hyde.features' => $config]); - } - - if ($this->option('pretty-urls')) { - $this->info('Generating site with pretty URLs'); - $this->newLine(); - Config::set(['site.pretty_urls' => true]); - } - } - - public function runPostBuildActions(): void - { - $service = new BuildTaskService($this->output); - - if ($this->option('run-prettier')) { - $this->runNodeCommand( - 'npx prettier '.Hyde::pathToRelative(Hyde::sitePath()).'/**/*.html --write --bracket-same-line', - 'Prettifying code!', - 'prettify code' - ); - } - - if ($this->option('run-dev')) { - $this->runNodeCommand('npm run dev', 'Building frontend assets for development!'); - } - - if ($this->option('run-prod')) { - $this->runNodeCommand('npm run prod', 'Building frontend assets for production!'); - } - - $service->runIf(GenerateSitemap::class, $this->canGenerateSitemap()); - $service->runIf(GenerateRssFeed::class, $this->canGenerateFeed()); - $service->runIf(GenerateSearch::class, $this->canGenerateSearch()); - - $service->runPostBuildTasks(); - } - - protected function printFinishMessage(float $time_start): void - { - $execution_time = (microtime(true) - $time_start); - $this->info( - sprintf( - 'All done! Finished in %s seconds. (%sms)', - number_format($execution_time, 2), - number_format($execution_time * 1000, 2) - ) - ); - - $this->info('Congratulations! 🎉 Your static site has been built!'); - $this->line( - 'Your new homepage is stored here -> '. - DiscoveryService::createClickableFilepath(Hyde::sitePath('index.html')) - ); - } - - protected function runNodeCommand(string $command, string $message, ?string $actionMessage = null): void - { - $this->info($message.' This may take a second.'); - - $output = shell_exec( - sprintf( - '%s%s', - app()->environment() === 'testing' ? 'echo ' : '', - $command - ) - ); - - $this->line( - $output ?? sprintf( - 'Could not %s! Is NPM installed?', - $actionMessage ?? 'run script' - ) - ); - } - - protected function canGenerateSitemap(): bool - { - return Features::sitemap(); - } - - protected function canGenerateFeed(): bool - { - return Features::rss(); - } - - protected function canGenerateSearch(): bool - { - return Features::hasDocumentationSearch(); - } } From d3f0f7480613335c36bfc408f6cfcf63d8b8a2aa Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:29:13 +0100 Subject: [PATCH 052/129] Move demo files from vendor to project --- .../resources => resources}/views/pubtypes/blah_detail.blade.php | 0 .../resources => resources}/views/pubtypes/blah_list.blade.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {packages/framework/resources => resources}/views/pubtypes/blah_detail.blade.php (100%) rename {packages/framework/resources => resources}/views/pubtypes/blah_list.blade.php (100%) diff --git a/packages/framework/resources/views/pubtypes/blah_detail.blade.php b/resources/views/pubtypes/blah_detail.blade.php similarity index 100% rename from packages/framework/resources/views/pubtypes/blah_detail.blade.php rename to resources/views/pubtypes/blah_detail.blade.php diff --git a/packages/framework/resources/views/pubtypes/blah_list.blade.php b/resources/views/pubtypes/blah_list.blade.php similarity index 100% rename from packages/framework/resources/views/pubtypes/blah_list.blade.php rename to resources/views/pubtypes/blah_list.blade.php From b711aecfc9b838e7e6449fdac36a9df14c632969 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sat, 19 Nov 2022 14:30:31 +0000 Subject: [PATCH 053/129] Apply fixes from StyleCI --- .../src/Console/Commands/BuildPublicationsCommand.php | 7 ------- .../framework/src/Console/Commands/BuildSiteCommand.php | 1 - 2 files changed, 8 deletions(-) diff --git a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php index 6d4af2cffbe..c4a15c73a65 100644 --- a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php +++ b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php @@ -5,18 +5,11 @@ namespace Hyde\Console\Commands; use Hyde\Console\Commands\Interfaces\CommandHandleInterface; -use Hyde\Facades\Features; -use Hyde\Framework\Features\BuildTasks\PostBuildTasks\GenerateRssFeed; -use Hyde\Framework\Features\BuildTasks\PostBuildTasks\GenerateSearch; -use Hyde\Framework\Features\BuildTasks\PostBuildTasks\GenerateSitemap; use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Framework\Services\BuildService; -use Hyde\Framework\Services\BuildTaskService; -use Hyde\Framework\Services\DiscoveryService; use Hyde\Hyde; use Hyde\Pages\MarkdownPage; use Hyde\PublicationHelper; -use Illuminate\Support\Facades\Config; use LaravelZero\Framework\Commands\Command; use Rgasch\Collection\Collection; diff --git a/packages/framework/src/Console/Commands/BuildSiteCommand.php b/packages/framework/src/Console/Commands/BuildSiteCommand.php index 11a13fe4183..ce3b5740b6f 100644 --- a/packages/framework/src/Console/Commands/BuildSiteCommand.php +++ b/packages/framework/src/Console/Commands/BuildSiteCommand.php @@ -14,7 +14,6 @@ use Hyde\Hyde; use Illuminate\Support\Facades\Config; use LaravelZero\Framework\Commands\Command; - use function memory_get_peak_usage; /** From 05adc66f5199a021f5c94dcfeaccae6e98368a04 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:51:18 +0100 Subject: [PATCH 054/129] Breaking: Move PublicationHelper into Publications feature namespace --- .../src/Console/Commands/BuildPublicationsCommand.php | 3 +-- .../src/Console/Commands/MakePublicationCommand.php | 2 +- .../src/Console/Commands/MakePublicationTypeCommand.php | 2 +- packages/framework/src/Foundation/PageCollection.php | 2 +- .../src/Framework/Actions/CreatesNewPublicationFile.php | 3 ++- .../Framework/Actions/CreatesNewPublicationTypeSchema.php | 2 +- .../Features/Publications}/PublicationHelper.php | 6 ++++-- 7 files changed, 11 insertions(+), 9 deletions(-) rename packages/framework/src/{ => Framework/Features/Publications}/PublicationHelper.php (98%) diff --git a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php index c4a15c73a65..737dcc31e2f 100644 --- a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php +++ b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php @@ -6,10 +6,9 @@ use Hyde\Console\Commands\Interfaces\CommandHandleInterface; use Hyde\Framework\Features\Publications\Models\PublicationType; +use Hyde\Framework\Features\Publications\PublicationHelper; use Hyde\Framework\Services\BuildService; -use Hyde\Hyde; use Hyde\Pages\MarkdownPage; -use Hyde\PublicationHelper; use LaravelZero\Framework\Commands\Command; use Rgasch\Collection\Collection; diff --git a/packages/framework/src/Console/Commands/MakePublicationCommand.php b/packages/framework/src/Console/Commands/MakePublicationCommand.php index 44f5d1b13bc..a76ee52c5b2 100644 --- a/packages/framework/src/Console/Commands/MakePublicationCommand.php +++ b/packages/framework/src/Console/Commands/MakePublicationCommand.php @@ -6,7 +6,7 @@ use Hyde\Console\Commands\Interfaces\CommandHandleInterface; use Hyde\Framework\Actions\CreatesNewPublicationFile; -use Hyde\PublicationHelper; +use Hyde\Framework\Features\Publications\PublicationHelper; use Illuminate\Support\Str; use LaravelZero\Framework\Commands\Command; use Rgasch\Collection\Collection; diff --git a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php index 92ca2dcb0ce..351468fabaf 100644 --- a/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php +++ b/packages/framework/src/Console/Commands/MakePublicationTypeCommand.php @@ -6,7 +6,7 @@ use Hyde\Console\Commands\Interfaces\CommandHandleInterface; use Hyde\Framework\Actions\CreatesNewPublicationTypeSchema; -use Hyde\PublicationHelper; +use Hyde\Framework\Features\Publications\PublicationHelper; use LaravelZero\Framework\Commands\Command; use Rgasch\Collection\Collection; diff --git a/packages/framework/src/Foundation/PageCollection.php b/packages/framework/src/Foundation/PageCollection.php index 3c607b7f152..0ba2a075530 100644 --- a/packages/framework/src/Foundation/PageCollection.php +++ b/packages/framework/src/Foundation/PageCollection.php @@ -8,13 +8,13 @@ use Hyde\Foundation\Concerns\BaseFoundationCollection; use Hyde\Framework\Exceptions\FileNotFoundException; use Hyde\Framework\Features\Publications\Models\PublicationType; +use Hyde\Framework\Features\Publications\PublicationHelper; use Hyde\Pages\BladePage; use Hyde\Pages\Concerns\HydePage; use Hyde\Pages\DocumentationPage; use Hyde\Pages\HtmlPage; use Hyde\Pages\MarkdownPage; use Hyde\Pages\MarkdownPost; -use Hyde\PublicationHelper; use Illuminate\Support\Collection; /** diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php index e88de1523ae..173dbbbae59 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php @@ -6,9 +6,10 @@ use Hyde\Framework\Actions\Interfaces\CreateActionInterface; use Hyde\Framework\Concerns\InteractsWithDirectories; -use Hyde\PublicationHelper; +use Hyde\Framework\Features\Publications\PublicationHelper; use Illuminate\Support\Str; use Rgasch\Collection\Collection; + use function Safe\date; use function Safe\file_put_contents; diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php index 4d1f0cebfa7..927bcbd684c 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationTypeSchema.php @@ -6,7 +6,7 @@ use Hyde\Framework\Actions\Interfaces\CreateActionInterface; use Hyde\Framework\Concerns\InteractsWithDirectories; -use Hyde\PublicationHelper; +use Hyde\Framework\Features\Publications\PublicationHelper; use Rgasch\Collection\Collection; use function Safe\file_put_contents; use function Safe\json_encode; diff --git a/packages/framework/src/PublicationHelper.php b/packages/framework/src/Framework/Features/Publications/PublicationHelper.php similarity index 98% rename from packages/framework/src/PublicationHelper.php rename to packages/framework/src/Framework/Features/Publications/PublicationHelper.php index 82f824f63c6..57bd161b270 100644 --- a/packages/framework/src/PublicationHelper.php +++ b/packages/framework/src/Framework/Features/Publications/PublicationHelper.php @@ -2,19 +2,21 @@ declare(strict_types=1); -namespace Hyde; +namespace Hyde\Framework\Features\Publications; use Carbon\Carbon; use Hyde\Foundation\HydeKernel; use Hyde\Framework\Features\Publications\Models\PublicationType; +use Hyde\Hyde; use Hyde\Pages\PublicationPage; use Illuminate\Contracts\Validation\Factory as ValidationFactory; use Illuminate\Support\Str; use LaravelZero\Framework\Commands\Command; use Rgasch\Collection\Collection; -use function Safe\file_get_contents; use Spatie\YamlFrontMatter\YamlFrontMatter; +use function Safe\file_get_contents; + class PublicationHelper { /** From 59b08b2695c7c2cdac3a88f026236485be50223c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:39:09 +0100 Subject: [PATCH 055/129] Create PublicationListPage.php --- .../Publications/Models/PublicationListPage.php | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php new file mode 100644 index 00000000000..733f593ca11 --- /dev/null +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -0,0 +1,10 @@ + Date: Sat, 19 Nov 2022 15:48:42 +0100 Subject: [PATCH 056/129] Override directory information --- .../Features/Publications/Models/PublicationListPage.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 733f593ca11..57ca2e455ce 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -6,5 +6,7 @@ class PublicationListPage extends \Hyde\Pages\BladePage { - // + public static string $sourceDirectory = '%type%'; + public static string $outputDirectory = '%type%'; + public static string $fileExtension = ''; } From 7a42176319e26c79f4bd0742de3e5c956faa8d1c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:48:55 +0100 Subject: [PATCH 057/129] Empty directory information --- .../Features/Publications/Models/PublicationListPage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 57ca2e455ce..f608d068eb4 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -6,7 +6,7 @@ class PublicationListPage extends \Hyde\Pages\BladePage { - public static string $sourceDirectory = '%type%'; - public static string $outputDirectory = '%type%'; + public static string $sourceDirectory = ''; + public static string $outputDirectory = ''; public static string $fileExtension = ''; } From d9ea6432fe2eff78ab55995db0726d9951c8a545 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:49:47 +0100 Subject: [PATCH 058/129] Dynamically discover publication listing pages --- packages/framework/src/Foundation/PageCollection.php | 8 ++++++++ packages/framework/tests/Feature/PageCollectionTest.php | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Foundation/PageCollection.php b/packages/framework/src/Foundation/PageCollection.php index 0ba2a075530..b31fe6f4c7c 100644 --- a/packages/framework/src/Foundation/PageCollection.php +++ b/packages/framework/src/Foundation/PageCollection.php @@ -7,6 +7,7 @@ use Hyde\Facades\Features; use Hyde\Foundation\Concerns\BaseFoundationCollection; use Hyde\Framework\Exceptions\FileNotFoundException; +use Hyde\Framework\Features\Publications\Models\PublicationListPage; use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Framework\Features\Publications\PublicationHelper; use Hyde\Pages\BladePage; @@ -104,6 +105,7 @@ protected function discoverPublicationPages(): void { PublicationHelper::getPublicationTypes()->each(function (PublicationType $type) { $this->discoverPublicationPagesForType($type); + $this->generatePublicationListingPageForType($type); }); } @@ -113,4 +115,10 @@ protected function discoverPublicationPagesForType(PublicationType $type): void $this->discover($publication); }); } + + protected function generatePublicationListingPageForType(PublicationType $type): void + { + $page = new PublicationListPage($type->getDirectory().'/index'); + $this->put($page->getSourcePath(), $page); + } } diff --git a/packages/framework/tests/Feature/PageCollectionTest.php b/packages/framework/tests/Feature/PageCollectionTest.php index d6df8b7f0b7..2218147e0c1 100644 --- a/packages/framework/tests/Feature/PageCollectionTest.php +++ b/packages/framework/tests/Feature/PageCollectionTest.php @@ -5,6 +5,7 @@ namespace Hyde\Framework\Testing\Feature; use Hyde\Foundation\PageCollection; +use Hyde\Framework\Features\Publications\Models\PublicationListPage; use Hyde\Hyde; use Hyde\Pages\BladePage; use Hyde\Pages\DocumentationPage; @@ -12,6 +13,7 @@ use Hyde\Pages\MarkdownPage; use Hyde\Pages\MarkdownPost; use Hyde\Pages\PublicationPage; +use Hyde\PublicationHelper; use Hyde\Testing\TestCase; use Illuminate\Support\Collection; use Illuminate\Support\Facades\File; @@ -193,9 +195,12 @@ public function test_publication_pages_are_discovered() '); $collection = PageCollection::boot(Hyde::getInstance())->getPages(); - // $this->assertCount(1, $collection); // TODO: Fix this + // $this->assertCount(2, $collection); // TODO: Fix this $this->assertInstanceOf(PublicationPage::class, $collection->get('__publications/foo.md')); + // Test listing pages for publications are discovered + $this->assertInstanceOf(PublicationListPage::class, $collection->get('/publication/index.')); // TODO Fix ugly route key + File::deleteDirectory(Hyde::path('publication')); } } From 6bd5d85e35c79f79448b986451b9b00ed4e82b5e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:54:35 +0100 Subject: [PATCH 059/129] Create PublicationListPageTest.php --- .../Models/PublicationListPageTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php diff --git a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php new file mode 100644 index 00000000000..ef47f687dbf --- /dev/null +++ b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php @@ -0,0 +1,14 @@ + Date: Sat, 19 Nov 2022 15:54:46 +0100 Subject: [PATCH 060/129] Replace qualifier with an import --- .../Features/Publications/Models/PublicationListPage.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index f608d068eb4..23d41934ed8 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -4,7 +4,9 @@ namespace Hyde\Framework\Features\Publications\Models; -class PublicationListPage extends \Hyde\Pages\BladePage +use Hyde\Pages\BladePage; + +class PublicationListPage extends BladePage { public static string $sourceDirectory = ''; public static string $outputDirectory = ''; From 07dbd6064ac2072fb5d930a45d15a11d2351550c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:55:25 +0100 Subject: [PATCH 061/129] Add PublicationType property to listing page --- .../Features/Publications/Models/PublicationListPage.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 23d41934ed8..6daee095481 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -11,4 +11,6 @@ class PublicationListPage extends BladePage public static string $sourceDirectory = ''; public static string $outputDirectory = ''; public static string $fileExtension = ''; + + public PublicationType $type; } From dc442f95c188242d25232cce5bd43b777bf66e6a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:56:48 +0100 Subject: [PATCH 062/129] Override listing page constructor to only accept the publication type --- packages/framework/src/Foundation/PageCollection.php | 2 +- .../Features/Publications/Models/PublicationListPage.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Foundation/PageCollection.php b/packages/framework/src/Foundation/PageCollection.php index b31fe6f4c7c..99b26ccada8 100644 --- a/packages/framework/src/Foundation/PageCollection.php +++ b/packages/framework/src/Foundation/PageCollection.php @@ -118,7 +118,7 @@ protected function discoverPublicationPagesForType(PublicationType $type): void protected function generatePublicationListingPageForType(PublicationType $type): void { - $page = new PublicationListPage($type->getDirectory().'/index'); + $page = new PublicationListPage($type); $this->put($page->getSourcePath(), $page); } } diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 6daee095481..1cef93cf609 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -13,4 +13,10 @@ class PublicationListPage extends BladePage public static string $fileExtension = ''; public PublicationType $type; + + public function __construct(PublicationType $type) + { + parent::__construct(); + $this->type = $type; + } } From 5c295231e178c2878057e2ffc2fa1f0d4ef83ced Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 15:57:32 +0100 Subject: [PATCH 063/129] Add strict types declaration --- .../Features/Publications/Models/PublicationListPageTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php index ef47f687dbf..cd55fa3f113 100644 --- a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php +++ b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php @@ -1,5 +1,7 @@ Date: Sat, 19 Nov 2022 15:58:34 +0100 Subject: [PATCH 064/129] Revert "Empty directory information" This reverts commit 7a42176319e26c79f4bd0742de3e5c956faa8d1c. --- .../Features/Publications/Models/PublicationListPage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 1cef93cf609..70910853515 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -8,8 +8,8 @@ class PublicationListPage extends BladePage { - public static string $sourceDirectory = ''; - public static string $outputDirectory = ''; + public static string $sourceDirectory = '%type%'; + public static string $outputDirectory = '%type%'; public static string $fileExtension = ''; public PublicationType $type; From f9cf6cb7df441f663a677c7f7f5709aea2268a5b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:03:48 +0100 Subject: [PATCH 065/129] Add testing helpers --- .../Models/PublicationListPageTest.php | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php index cd55fa3f113..1e3b0a3eb2d 100644 --- a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php +++ b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php @@ -5,12 +5,40 @@ namespace Hyde\Framework\Testing\Framework\Features\Publications\Models; use Hyde\Framework\Features\Publications\Models\PublicationListPage; +use Hyde\Framework\Features\Publications\Models\PublicationType; +use Hyde\Hyde; +use Hyde\Pages\PublicationPage; use Hyde\Testing\TestCase; +use Illuminate\Support\Facades\File; + +use function file_put_contents; +use function json_encode; + /** * @covers \Hyde\Framework\Features\Publications\Models\PublicationListPage */ class PublicationListPageTest extends TestCase { - // + protected function createPublicationFiles(): void + { + mkdir(Hyde::path('test-publication')); + file_put_contents(Hyde::path('test-publication/schema.json'), json_encode(['foo' => 'bar'])); + file_put_contents( + Hyde::path('test-publication/foo.md'), + '--- +__canonical: canonical +__createdAt: 2022-11-16 11:32:52 +foo: bar +--- + +Hello World! +' + ); + } + + protected function getPublicationType(): PublicationType + { + return new PublicationType('test-publication/schema.json'); + } } From cd6d99fe7cf1656ffc9369f59f4ac5fa63a4f8fb Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:05:33 +0100 Subject: [PATCH 066/129] Add test for source path mappings --- .../Publications/Models/PublicationListPageTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php index 1e3b0a3eb2d..4d4a1f27660 100644 --- a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php +++ b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php @@ -20,6 +20,16 @@ */ class PublicationListPageTest extends TestCase { + public function testSourcePathMappings() + { + $this->createPublicationFiles(); + + $page = new PublicationListPage($this->getPublicationType()); + $this->assertSame('test-publication/index', $page->getIdentifier()); + + File::deleteDirectory(Hyde::path('publications')); + } + protected function createPublicationFiles(): void { mkdir(Hyde::path('test-publication')); From d5e5f3e13830ac43cf35ebaad385bf4310dbd841 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:05:41 +0100 Subject: [PATCH 067/129] Construct identifier --- .../Features/Publications/Models/PublicationListPage.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 70910853515..a00df5c24bd 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -18,5 +18,6 @@ public function __construct(PublicationType $type) { parent::__construct(); $this->type = $type; + $this->identifier = "{$type->getDirectory()}/index"; } } From fcdf9e19240be67131b996c2f2538d48457263af Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:06:54 +0100 Subject: [PATCH 068/129] Construct identifier via parent constructor --- .../Features/Publications/Models/PublicationListPage.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index a00df5c24bd..8540376a03f 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -16,8 +16,7 @@ class PublicationListPage extends BladePage public function __construct(PublicationType $type) { - parent::__construct(); + parent::__construct("{$type->getDirectory()}/index"); $this->type = $type; - $this->identifier = "{$type->getDirectory()}/index"; } } From ffc48ba677a11acb24fcacb859204d344e4cee36 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:07:57 +0100 Subject: [PATCH 069/129] Blank out output directory --- .../Features/Publications/Models/PublicationListPage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 8540376a03f..d12898a5a51 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -9,7 +9,7 @@ class PublicationListPage extends BladePage { public static string $sourceDirectory = '%type%'; - public static string $outputDirectory = '%type%'; + public static string $outputDirectory = ''; public static string $fileExtension = ''; public PublicationType $type; From 894ee93b902ebb30e0d7cc4035779bd07688a5cd Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:09:19 +0100 Subject: [PATCH 070/129] Add additional tests --- .../Features/Publications/Models/PublicationListPageTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php index 4d4a1f27660..41ad09079d2 100644 --- a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php +++ b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php @@ -26,6 +26,9 @@ public function testSourcePathMappings() $page = new PublicationListPage($this->getPublicationType()); $this->assertSame('test-publication/index', $page->getIdentifier()); + $this->assertSame('test-publication/index', $page->getRouteKey()); + $this->assertSame('test-publication/index.html', $page->getOutputPath()); + File::deleteDirectory(Hyde::path('publications')); } From 940eec03d0a3c0b5c765c244f8423a6a7e0c230a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:09:30 +0100 Subject: [PATCH 071/129] Set file extension to JSON --- .../Features/Publications/Models/PublicationListPage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index d12898a5a51..07467fc5ee2 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -10,7 +10,7 @@ class PublicationListPage extends BladePage { public static string $sourceDirectory = '%type%'; public static string $outputDirectory = ''; - public static string $fileExtension = ''; + public static string $fileExtension = 'json'; public PublicationType $type; From ae1719be3e396cf8e6417cdf8300a08ab37a629e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:09:52 +0100 Subject: [PATCH 072/129] Remove extra newline --- .../Features/Publications/Models/PublicationListPageTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php index 41ad09079d2..3fd11dbddd1 100644 --- a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php +++ b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php @@ -29,7 +29,6 @@ public function testSourcePathMappings() $this->assertSame('test-publication/index', $page->getRouteKey()); $this->assertSame('test-publication/index.html', $page->getOutputPath()); - File::deleteDirectory(Hyde::path('publications')); } From 0bc8e29e5b93f7d083add74ac0596e4e760c6d85 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:10:38 +0100 Subject: [PATCH 073/129] Change dynamic source directory to __publications --- .../Features/Publications/Models/PublicationListPage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 07467fc5ee2..2f558ba3ceb 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -8,7 +8,7 @@ class PublicationListPage extends BladePage { - public static string $sourceDirectory = '%type%'; + public static string $sourceDirectory = '__publications'; public static string $outputDirectory = ''; public static string $fileExtension = 'json'; From a29ac3603b782a3f1c498dbdaadb688f68a7f953 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:11:02 +0100 Subject: [PATCH 074/129] Test getSourcePath --- .../Features/Publications/Models/PublicationListPageTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php index 3fd11dbddd1..c534feb8bc1 100644 --- a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php +++ b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php @@ -28,6 +28,7 @@ public function testSourcePathMappings() $this->assertSame('test-publication/index', $page->getIdentifier()); $this->assertSame('test-publication/index', $page->getRouteKey()); $this->assertSame('test-publication/index.html', $page->getOutputPath()); + $this->assertSame('__publications/test-publication/index.json', $page->getSourcePath()); File::deleteDirectory(Hyde::path('publications')); } From 370c3dfa6f4d4f42ba774e4b4570eaf8e7f2ff8d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:12:15 +0100 Subject: [PATCH 075/129] Fix delete path issue in test --- .../Features/Publications/Models/PublicationListPageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php index c534feb8bc1..bdb5623278d 100644 --- a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php +++ b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php @@ -30,7 +30,7 @@ public function testSourcePathMappings() $this->assertSame('test-publication/index.html', $page->getOutputPath()); $this->assertSame('__publications/test-publication/index.json', $page->getSourcePath()); - File::deleteDirectory(Hyde::path('publications')); + File::deleteDirectory(Hyde::path('test-publication')); } protected function createPublicationFiles(): void From af64d910b5f1f5ede7588909fe67e171f11e9206 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:13:17 +0100 Subject: [PATCH 076/129] Update expected route key --- packages/framework/tests/Feature/PageCollectionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PageCollectionTest.php b/packages/framework/tests/Feature/PageCollectionTest.php index 2218147e0c1..6bdf941dd81 100644 --- a/packages/framework/tests/Feature/PageCollectionTest.php +++ b/packages/framework/tests/Feature/PageCollectionTest.php @@ -199,7 +199,7 @@ public function test_publication_pages_are_discovered() $this->assertInstanceOf(PublicationPage::class, $collection->get('__publications/foo.md')); // Test listing pages for publications are discovered - $this->assertInstanceOf(PublicationListPage::class, $collection->get('/publication/index.')); // TODO Fix ugly route key + $this->assertInstanceOf(PublicationListPage::class, $collection->get('__publications/publication/index.json')); File::deleteDirectory(Hyde::path('publication')); } From 7816c50e3e6e29dc4a299fdc8217d327432c55fe Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:13:58 +0100 Subject: [PATCH 077/129] Convert test method case --- .../Features/Publications/Models/PublicationListPageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php index bdb5623278d..a66f014a148 100644 --- a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php +++ b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php @@ -20,7 +20,7 @@ */ class PublicationListPageTest extends TestCase { - public function testSourcePathMappings() + public function test_source_path_mappings() { $this->createPublicationFiles(); From 80981bae87fce1804e3f18f28535e8faac8d9375 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sat, 19 Nov 2022 15:14:13 +0000 Subject: [PATCH 078/129] Apply fixes from StyleCI --- .../src/Framework/Actions/CreatesNewPublicationFile.php | 1 - .../Framework/Features/Publications/PublicationHelper.php | 3 +-- packages/framework/tests/Feature/PageCollectionTest.php | 1 - .../Features/Publications/Models/PublicationListPageTest.php | 5 +---- 4 files changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php index 173dbbbae59..534e99f6379 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php @@ -9,7 +9,6 @@ use Hyde\Framework\Features\Publications\PublicationHelper; use Illuminate\Support\Str; use Rgasch\Collection\Collection; - use function Safe\date; use function Safe\file_put_contents; diff --git a/packages/framework/src/Framework/Features/Publications/PublicationHelper.php b/packages/framework/src/Framework/Features/Publications/PublicationHelper.php index 57bd161b270..49f212fbfc4 100644 --- a/packages/framework/src/Framework/Features/Publications/PublicationHelper.php +++ b/packages/framework/src/Framework/Features/Publications/PublicationHelper.php @@ -13,9 +13,8 @@ use Illuminate\Support\Str; use LaravelZero\Framework\Commands\Command; use Rgasch\Collection\Collection; -use Spatie\YamlFrontMatter\YamlFrontMatter; - use function Safe\file_get_contents; +use Spatie\YamlFrontMatter\YamlFrontMatter; class PublicationHelper { diff --git a/packages/framework/tests/Feature/PageCollectionTest.php b/packages/framework/tests/Feature/PageCollectionTest.php index 6bdf941dd81..09add33bada 100644 --- a/packages/framework/tests/Feature/PageCollectionTest.php +++ b/packages/framework/tests/Feature/PageCollectionTest.php @@ -13,7 +13,6 @@ use Hyde\Pages\MarkdownPage; use Hyde\Pages\MarkdownPost; use Hyde\Pages\PublicationPage; -use Hyde\PublicationHelper; use Hyde\Testing\TestCase; use Illuminate\Support\Collection; use Illuminate\Support\Facades\File; diff --git a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php index a66f014a148..80ab73cbfbc 100644 --- a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php +++ b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php @@ -4,15 +4,12 @@ namespace Hyde\Framework\Testing\Framework\Features\Publications\Models; +use function file_put_contents; use Hyde\Framework\Features\Publications\Models\PublicationListPage; use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Hyde; -use Hyde\Pages\PublicationPage; use Hyde\Testing\TestCase; - use Illuminate\Support\Facades\File; - -use function file_put_contents; use function json_encode; /** From 99e08f99b3cdc54aeb590c39aced0e1c19891374 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:28:55 +0100 Subject: [PATCH 079/129] Implement listing page compiler --- .../Models/PublicationListPage.php | 16 +++++++++++++ .../Models/PublicationListPageTest.php | 23 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 2f558ba3ceb..42483e5f9f5 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -4,8 +4,13 @@ namespace Hyde\Framework\Features\Publications\Models; +use Hyde\Framework\Features\Publications\PublicationHelper; use Hyde\Pages\BladePage; +use Illuminate\Support\Str; + +use function view; + class PublicationListPage extends BladePage { public static string $sourceDirectory = '__publications'; @@ -19,4 +24,15 @@ public function __construct(PublicationType $type) parent::__construct("{$type->getDirectory()}/index"); $this->type = $type; } + + public function compile(): string + { + $listTemplate = $this->type->getSchema()['listTemplate']; + $listTemplate = Str::before("$listTemplate", '.blade.php'); + + $pubType = $this->type; + $template = 'pubtypes.'.$listTemplate; + $publications = PublicationHelper::getPublicationsForPubType($pubType); + return view($template)->with('publications', $publications)->render(); + } } diff --git a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php index 80ab73cbfbc..e14b297f671 100644 --- a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php +++ b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php @@ -11,6 +11,8 @@ use Hyde\Testing\TestCase; use Illuminate\Support\Facades\File; use function json_encode; +use function mkdir; +use function resource_path; /** * @covers \Hyde\Framework\Features\Publications\Models\PublicationListPage @@ -30,10 +32,29 @@ public function test_source_path_mappings() File::deleteDirectory(Hyde::path('test-publication')); } + public function test_listing_page_can_be_compiled() + { + $this->createPublicationFiles(); + // Temporary until we settle on where to store templates + + @mkdir(resource_path('views/pubtypes')); + $this->file('resources/views/pubtypes/test_list.blade.php', 'Listing Page'); + + $page = new PublicationListPage($this->getPublicationType()); + + Hyde::shareViewData($page); + $this->assertStringContainsString('Listing Page', $page->compile()); + File::deleteDirectory(Hyde::path('test-publication')); + } + protected function createPublicationFiles(): void { mkdir(Hyde::path('test-publication')); - file_put_contents(Hyde::path('test-publication/schema.json'), json_encode(['foo' => 'bar'])); + file_put_contents(Hyde::path('test-publication/schema.json'), json_encode([ + 'foo' => 'bar', + 'detailTemplate' => 'test_detail.blade.php', + 'listTemplate' => 'test_list.blade.php', + ])); file_put_contents( Hyde::path('test-publication/foo.md'), '--- From e2cae22946e5926a2450f00ce335de1cade63477 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sat, 19 Nov 2022 15:30:11 +0000 Subject: [PATCH 080/129] Apply fixes from StyleCI --- .../Features/Publications/Models/PublicationListPage.php | 5 ++--- .../Features/Publications/Models/PublicationListPageTest.php | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 42483e5f9f5..4aaf6002e31 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -6,9 +6,7 @@ use Hyde\Framework\Features\Publications\PublicationHelper; use Hyde\Pages\BladePage; - use Illuminate\Support\Str; - use function view; class PublicationListPage extends BladePage @@ -30,9 +28,10 @@ public function compile(): string $listTemplate = $this->type->getSchema()['listTemplate']; $listTemplate = Str::before("$listTemplate", '.blade.php'); - $pubType = $this->type; + $pubType = $this->type; $template = 'pubtypes.'.$listTemplate; $publications = PublicationHelper::getPublicationsForPubType($pubType); + return view($template)->with('publications', $publications)->render(); } } diff --git a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php index e14b297f671..c96163f3b4a 100644 --- a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php +++ b/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php @@ -46,7 +46,7 @@ public function test_listing_page_can_be_compiled() $this->assertStringContainsString('Listing Page', $page->compile()); File::deleteDirectory(Hyde::path('test-publication')); } - + protected function createPublicationFiles(): void { mkdir(Hyde::path('test-publication')); From 2833bbf0c592e4e949511ef8765e01d00893bfb7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:33:48 +0100 Subject: [PATCH 081/129] Test source path mappings --- .../framework/tests/Feature/PublicationPageTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index 59b8fc0cb9f..cd578f12b89 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -34,6 +34,18 @@ protected function tearDown(): void parent::tearDown(); } + public function test_source_path_mappings() + { + $this->createPublicationFiles(); + + $page = new PublicationPage(new PublicationType('test-publication/schema.json'), 'foo'); + + $this->assertSame('test-publication/foo', $page->getIdentifier()); + $this->assertSame('test-publication/foo', $page->getRouteKey()); + $this->assertSame('test-publication/foo.md', $page->getSourcePath()); + $this->assertSame('test-publication/foo.html', $page->getOutputPath()); + } + public function test_publication_pages_are_routable() { $this->createPublicationFiles(); From 6b2c3439e939ec1819e8bb5a9ca049880887e867 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:34:30 +0100 Subject: [PATCH 082/129] Prefix publication directory to identifier using parent constructor --- packages/framework/src/Pages/PublicationPage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index c6de2824424..01096f612eb 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -26,7 +26,7 @@ public function __construct(PublicationType $type, string $identifier = '', Fron { $this->type = $type; - parent::__construct($identifier, $matter, $markdown); + parent::__construct("{$type->getDirectory()}/$identifier", $matter, $markdown); } // TODO: override method to get output directory from publication type etc From d1b16274b7fece2a25bb3e55317e4af1be4d0700 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:34:48 +0100 Subject: [PATCH 083/129] Blank out source and output directories --- packages/framework/src/Pages/PublicationPage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index 01096f612eb..161ce31d13b 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -18,8 +18,8 @@ class PublicationPage extends Concerns\BaseMarkdownPage { public PublicationType $type; - public static string $sourceDirectory = '__publications'; - public static string $outputDirectory = '__publications'; + public static string $sourceDirectory = ''; + public static string $outputDirectory = ''; public static string $template = '__dynamic'; public function __construct(PublicationType $type, string $identifier = '', FrontMatter|array $matter = [], Markdown|string $markdown = '') From 4480cfb1d8ff5c1f1d1c98a39d8d10cab854119e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:35:09 +0100 Subject: [PATCH 084/129] Reorder constructor calls --- packages/framework/src/Pages/PublicationPage.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index 161ce31d13b..292f1260143 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -24,9 +24,8 @@ class PublicationPage extends Concerns\BaseMarkdownPage public function __construct(PublicationType $type, string $identifier = '', FrontMatter|array $matter = [], Markdown|string $markdown = '') { - $this->type = $type; - parent::__construct("{$type->getDirectory()}/$identifier", $matter, $markdown); + $this->type = $type; } // TODO: override method to get output directory from publication type etc From 290cc4589f2806ded4c77c9fa936e974ef99f292 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:35:47 +0100 Subject: [PATCH 085/129] Unslash page source and output paths --- packages/framework/src/Pages/Concerns/HydePage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Pages/Concerns/HydePage.php b/packages/framework/src/Pages/Concerns/HydePage.php index 0b42d82aadd..6c761742104 100644 --- a/packages/framework/src/Pages/Concerns/HydePage.php +++ b/packages/framework/src/Pages/Concerns/HydePage.php @@ -170,7 +170,7 @@ abstract public function compile(): string; */ public function getSourcePath(): string { - return static::sourcePath($this->identifier); + return unslash(static::sourcePath($this->identifier)); } /** @@ -180,7 +180,7 @@ public function getSourcePath(): string */ public function getOutputPath(): string { - return static::outputPath($this->identifier); + return unslash(static::outputPath($this->identifier)); } // Section: Routing From a793906634f84320a3163f4eafc0ee4ba3709133 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:44:06 +0100 Subject: [PATCH 086/129] Fall back to current time if stat fails in sitemap generator --- .../src/Framework/Features/XmlGenerators/SitemapGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/XmlGenerators/SitemapGenerator.php b/packages/framework/src/Framework/Features/XmlGenerators/SitemapGenerator.php index 387015d84a8..0f0f568e1d0 100644 --- a/packages/framework/src/Framework/Features/XmlGenerators/SitemapGenerator.php +++ b/packages/framework/src/Framework/Features/XmlGenerators/SitemapGenerator.php @@ -69,7 +69,7 @@ protected function addRoute(Route $route): void protected function getLastModDate(string $file): string { - return date('c', filemtime($file)); + return date('c', @filemtime($file) ?: time()); } protected function getPriority(string $pageClass, string $slug): string From 79a4e143cb3bdfe05884a7b783a7ccec1bac7666 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:49:59 +0100 Subject: [PATCH 087/129] Delete blah directory --- blah/123.md | 8 -------- blah/aaa.md | 8 -------- blah/abc.md | 8 -------- blah/schema.json | 30 ------------------------------ 4 files changed, 54 deletions(-) delete mode 100644 blah/123.md delete mode 100644 blah/aaa.md delete mode 100644 blah/abc.md delete mode 100644 blah/schema.json diff --git a/blah/123.md b/blah/123.md deleted file mode 100644 index c1f19b8ab37..00000000000 --- a/blah/123.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -__canonical: 123 -__createdAt: 2022-11-16 11:32:52 -f1: 123 -f2: 456 -f3: 789 ---- -Raw MD text ... diff --git a/blah/aaa.md b/blah/aaa.md deleted file mode 100644 index b098ae172e8..00000000000 --- a/blah/aaa.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -__canonical: aaa -__createdAt: 2022-11-16 11:33:05 -f1: aaa -f2: bbb -f3: ccc ---- -Raw MD text ... diff --git a/blah/abc.md b/blah/abc.md deleted file mode 100644 index 2391eba6522..00000000000 --- a/blah/abc.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -__canonical: abc -__createdAt: 2022-11-16 11:32:36 -f1: abc -f2: def -f3: ghi ---- -Raw MD text ... diff --git a/blah/schema.json b/blah/schema.json deleted file mode 100644 index 1deae36440d..00000000000 --- a/blah/schema.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "blah", - "canonicalField": "f1", - "sortField": "__createdAt", - "sortDirection": "DESC", - "pagesize": 0, - "prevNextLinks": true, - "detailTemplate": "blah_detail.blade.php", - "listTemplate": "blah_list.blade.php", - "fields": [ - { - "name": "f1", - "min": "0", - "max": "0", - "type": "string" - }, - { - "name": "f2", - "min": "0", - "max": "0", - "type": "string" - }, - { - "name": "f3", - "min": "0", - "max": "0", - "type": "string" - } - ] -} \ No newline at end of file From a8a32ac08db3128eb1d5fd1101281376b881df82 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 16:53:49 +0100 Subject: [PATCH 088/129] Update PageCollectionTest.php --- packages/framework/tests/Feature/PageCollectionTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Feature/PageCollectionTest.php b/packages/framework/tests/Feature/PageCollectionTest.php index 09add33bada..e47f0c2b293 100644 --- a/packages/framework/tests/Feature/PageCollectionTest.php +++ b/packages/framework/tests/Feature/PageCollectionTest.php @@ -194,8 +194,8 @@ public function test_publication_pages_are_discovered() '); $collection = PageCollection::boot(Hyde::getInstance())->getPages(); - // $this->assertCount(2, $collection); // TODO: Fix this - $this->assertInstanceOf(PublicationPage::class, $collection->get('__publications/foo.md')); + $this->assertCount(4, $collection); // Default pages + publication index + publication page + $this->assertInstanceOf(PublicationPage::class, $collection->get('publication/foo.md')); // Test listing pages for publications are discovered $this->assertInstanceOf(PublicationListPage::class, $collection->get('__publications/publication/index.json')); From 2a215c48bc7e178926af5e3491ef6970526b2ecd Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 18:27:07 +0100 Subject: [PATCH 089/129] Update PublicationPageTest.php --- .../framework/tests/Feature/PublicationPageTest.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index cd578f12b89..2cbdabc296a 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -64,16 +64,18 @@ public function test_publication_pages_are_discoverable() $this->createPublicationFiles(); $collection = Hyde::pages()->getPages(); - $this->assertInstanceOf(PublicationPage::class, $collection->get('__publications/foo.md')); + $this->assertInstanceOf(PublicationPage::class, $collection->get('test-publication/foo.md')); } public function test_publication_pages_are_properly_parsed() { $this->createPublicationFiles(); - $page = Hyde::pages()->getPages()->get('__publications/foo.md'); + $page = Hyde::pages()->getPages()->get('test-publication/foo.md'); $this->assertInstanceOf(PublicationPage::class, $page); - $this->assertEquals('foo', $page->getIdentifier()); + $this->assertEquals('test-publication/foo', $page->getIdentifier()); + $this->assertEquals('Foo', $page->title); + $this->assertEquals('bar', $page->matter('foo')); $this->assertEquals('canonical', $page->matter('__canonical')); $this->assertEquals("Hello World!\n", $page->markdown()->body()); @@ -83,7 +85,7 @@ public function test_publication_pages_are_compilable() { $this->createRealPublicationFiles(); - $page = Hyde::pages()->getPages()->get('__publications/foo.md'); + $page = Hyde::pages()->getPages()->get('test-publication/foo.md'); Hyde::shareViewData($page); $this->assertStringContainsString('Hello World!', $page->compile()); From 3ce9cca3522659cac617d754e1cb1787bea25096 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 18:29:10 +0100 Subject: [PATCH 090/129] Move test to feature namespace --- packages/framework/tests/ConfigurableSourceRootsFeatureTest.php | 2 +- .../tests/{Unit => Feature}/HydeServiceProviderTest.php | 2 +- .../framework/tests/Feature/YamlConfigurationServiceTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename packages/framework/tests/{Unit => Feature}/HydeServiceProviderTest.php (99%) diff --git a/packages/framework/tests/ConfigurableSourceRootsFeatureTest.php b/packages/framework/tests/ConfigurableSourceRootsFeatureTest.php index 9a7b5a88568..a33fe7c5d23 100644 --- a/packages/framework/tests/ConfigurableSourceRootsFeatureTest.php +++ b/packages/framework/tests/ConfigurableSourceRootsFeatureTest.php @@ -20,7 +20,7 @@ * Also see these tests which cover specific implementation details: * * @see \Hyde\Framework\Testing\Feature\HydeKernelTest - * @see \Hyde\Framework\Testing\Unit\HydeServiceProviderTest + * @see \Hyde\Framework\Testing\Feature\HydeServiceProviderTest */ class ConfigurableSourceRootsFeatureTest extends TestCase { diff --git a/packages/framework/tests/Unit/HydeServiceProviderTest.php b/packages/framework/tests/Feature/HydeServiceProviderTest.php similarity index 99% rename from packages/framework/tests/Unit/HydeServiceProviderTest.php rename to packages/framework/tests/Feature/HydeServiceProviderTest.php index 8e644273bd1..8fb5bcc06ec 100644 --- a/packages/framework/tests/Unit/HydeServiceProviderTest.php +++ b/packages/framework/tests/Feature/HydeServiceProviderTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Hyde\Framework\Testing\Unit; +namespace Hyde\Framework\Testing\Feature; use function app; use function array_filter; diff --git a/packages/framework/tests/Feature/YamlConfigurationServiceTest.php b/packages/framework/tests/Feature/YamlConfigurationServiceTest.php index 22e79c91a8f..4b47ee67f0c 100644 --- a/packages/framework/tests/Feature/YamlConfigurationServiceTest.php +++ b/packages/framework/tests/Feature/YamlConfigurationServiceTest.php @@ -11,7 +11,7 @@ /** * @covers \Hyde\Framework\Services\YamlConfigurationService * - * @see \Hyde\Framework\Testing\Unit\HydeServiceProviderTest as it determines if this service should be booted. + * @see \Hyde\Framework\Testing\Feature\HydeServiceProviderTest as it determines if this service should be booted. */ class YamlConfigurationServiceTest extends TestCase { From baf1c634cea094b2ea0bbe2c21472ffbc21251ac Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 18:35:49 +0100 Subject: [PATCH 091/129] Test HtmlPages --- packages/framework/tests/Feature/RouteCollectionTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/RouteCollectionTest.php b/packages/framework/tests/Feature/RouteCollectionTest.php index 97cf8942efc..6c4126ae9cd 100644 --- a/packages/framework/tests/Feature/RouteCollectionTest.php +++ b/packages/framework/tests/Feature/RouteCollectionTest.php @@ -8,6 +8,7 @@ use Hyde\Hyde; use Hyde\Pages\BladePage; use Hyde\Pages\DocumentationPage; +use Hyde\Pages\HtmlPage; use Hyde\Pages\MarkdownPage; use Hyde\Pages\MarkdownPost; use Hyde\Support\Models\Route; @@ -75,14 +76,16 @@ protected function test_get_routes_for_model_returns_collection_of_routes_of_giv $this->file('_pages/markdown.md'); $this->file('_posts/post.md'); $this->file('_docs/docs.md'); + $this->file('_html/html.html'); $collection = Hyde::routes(); - $this->assertCount(4, $collection); + $this->assertCount(5, $collection); $this->assertEquals(new Route(new BladePage('blade')), $collection->getRoutes(BladePage::class)->first()); $this->assertEquals(new Route(new MarkdownPage('markdown')), $collection->getRoutes(MarkdownPage::class)->first()); $this->assertEquals(new Route(new MarkdownPost('post')), $collection->getRoutes(MarkdownPost::class)->first()); $this->assertEquals(new Route(new DocumentationPage('docs')), $collection->getRoutes(DocumentationPage::class)->first()); + $this->assertEquals(new Route(new HtmlPage('html')), $collection->getRoutes(HtmlPage::class)->first()); $this->restoreDefaultPages(); } From a9175ac80346d0b9354b15e41472237b2269692a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 18:46:02 +0100 Subject: [PATCH 092/129] Revert "Delete blah directory" This reverts commit 79a4e143cb3bdfe05884a7b783a7ccec1bac7666. --- blah/123.md | 8 ++++++++ blah/aaa.md | 8 ++++++++ blah/abc.md | 8 ++++++++ blah/schema.json | 30 ++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 blah/123.md create mode 100644 blah/aaa.md create mode 100644 blah/abc.md create mode 100644 blah/schema.json diff --git a/blah/123.md b/blah/123.md new file mode 100644 index 00000000000..c1f19b8ab37 --- /dev/null +++ b/blah/123.md @@ -0,0 +1,8 @@ +--- +__canonical: 123 +__createdAt: 2022-11-16 11:32:52 +f1: 123 +f2: 456 +f3: 789 +--- +Raw MD text ... diff --git a/blah/aaa.md b/blah/aaa.md new file mode 100644 index 00000000000..b098ae172e8 --- /dev/null +++ b/blah/aaa.md @@ -0,0 +1,8 @@ +--- +__canonical: aaa +__createdAt: 2022-11-16 11:33:05 +f1: aaa +f2: bbb +f3: ccc +--- +Raw MD text ... diff --git a/blah/abc.md b/blah/abc.md new file mode 100644 index 00000000000..2391eba6522 --- /dev/null +++ b/blah/abc.md @@ -0,0 +1,8 @@ +--- +__canonical: abc +__createdAt: 2022-11-16 11:32:36 +f1: abc +f2: def +f3: ghi +--- +Raw MD text ... diff --git a/blah/schema.json b/blah/schema.json new file mode 100644 index 00000000000..1deae36440d --- /dev/null +++ b/blah/schema.json @@ -0,0 +1,30 @@ +{ + "name": "blah", + "canonicalField": "f1", + "sortField": "__createdAt", + "sortDirection": "DESC", + "pagesize": 0, + "prevNextLinks": true, + "detailTemplate": "blah_detail.blade.php", + "listTemplate": "blah_list.blade.php", + "fields": [ + { + "name": "f1", + "min": "0", + "max": "0", + "type": "string" + }, + { + "name": "f2", + "min": "0", + "max": "0", + "type": "string" + }, + { + "name": "f3", + "min": "0", + "max": "0", + "type": "string" + } + ] +} \ No newline at end of file From cfbbf8a25b0ce9c5ac0670ec6f2804da6e90356c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 18:52:59 +0100 Subject: [PATCH 093/129] Fix test namespace --- .../Models => Feature}/PublicationListPageTest.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) rename packages/framework/tests/{Framework/Features/Publications/Models => Feature}/PublicationListPageTest.php (92%) diff --git a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php b/packages/framework/tests/Feature/PublicationListPageTest.php similarity index 92% rename from packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php rename to packages/framework/tests/Feature/PublicationListPageTest.php index c96163f3b4a..580f9eb853b 100644 --- a/packages/framework/tests/Framework/Features/Publications/Models/PublicationListPageTest.php +++ b/packages/framework/tests/Feature/PublicationListPageTest.php @@ -2,17 +2,13 @@ declare(strict_types=1); -namespace Hyde\Framework\Testing\Framework\Features\Publications\Models; +namespace Hyde\Framework\Testing\Feature; -use function file_put_contents; use Hyde\Framework\Features\Publications\Models\PublicationListPage; use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Hyde; use Hyde\Testing\TestCase; use Illuminate\Support\Facades\File; -use function json_encode; -use function mkdir; -use function resource_path; /** * @covers \Hyde\Framework\Features\Publications\Models\PublicationListPage From e537511917b18b2cb29a175fcde9b991c2d67a43 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 18:53:55 +0100 Subject: [PATCH 094/129] Link to the test --- .../Features/Publications/Models/PublicationListPage.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 4aaf6002e31..15d0419934a 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -9,6 +9,9 @@ use Illuminate\Support\Str; use function view; +/** + * @see \Hyde\Framework\Testing\Feature\PublicationListPageTest + */ class PublicationListPage extends BladePage { public static string $sourceDirectory = '__publications'; From 5a738c8dc8bec3ba98acbbd534900c9bdd71e6c5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 18:54:41 +0100 Subject: [PATCH 095/129] Link to the test --- packages/framework/src/Pages/PublicationPage.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index 292f1260143..e505248fd57 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -13,6 +13,8 @@ /** * Publication pages adds an easy way to create custom no-code page types, * with support using a custom front matter schema and Blade templates. + * + * @see \Hyde\Framework\Testing\Feature\PublicationPageTest */ class PublicationPage extends Concerns\BaseMarkdownPage { From a8a16ddbbbce122357c5dc9d47397838ee509707 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 18:54:20 +0100 Subject: [PATCH 096/129] Link to related class --- .../Features/Publications/Models/PublicationListPage.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 15d0419934a..86765d3151e 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -10,6 +10,7 @@ use function view; /** + * @see \Hyde\Pages\PublicationPage * @see \Hyde\Framework\Testing\Feature\PublicationListPageTest */ class PublicationListPage extends BladePage From f7aeae8305d5f8d4559458d1a23ba76dc4fd9631 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 18:55:16 +0100 Subject: [PATCH 097/129] Force FQCN in PHPDocs --- .editorconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index 83f43e36661..95ae81e9f0f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -729,7 +729,7 @@ ij_php_phpdoc_keep_blank_lines = true ij_php_phpdoc_param_spaces_between_name_and_description = 1 ij_php_phpdoc_param_spaces_between_tag_and_type = 1 ij_php_phpdoc_param_spaces_between_type_and_name = 1 -ij_php_phpdoc_use_fqcn = false +ij_php_phpdoc_use_fqcn = true ij_php_phpdoc_wrap_long_lines = false ij_php_place_assignment_sign_on_next_line = false ij_php_place_parens_for_constructor = 0 From baae78e87fa295d63dc02172799b66f7e095c726 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 18:58:01 +0100 Subject: [PATCH 098/129] Override source page method to get consistent behaviour --- .../Features/Publications/Models/PublicationListPage.php | 5 +++++ packages/framework/tests/Feature/PublicationListPageTest.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 86765d3151e..957b10431a2 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -38,4 +38,9 @@ public function compile(): string return view($template)->with('publications', $publications)->render(); } + + public function getSourcePath(): string + { + return $this->type->getDirectory().'/index.json'; + } } diff --git a/packages/framework/tests/Feature/PublicationListPageTest.php b/packages/framework/tests/Feature/PublicationListPageTest.php index 580f9eb853b..7d1ce758283 100644 --- a/packages/framework/tests/Feature/PublicationListPageTest.php +++ b/packages/framework/tests/Feature/PublicationListPageTest.php @@ -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('__publications/test-publication/index.json', $page->getSourcePath()); + $this->assertSame('test-publication/index.json', $page->getSourcePath()); File::deleteDirectory(Hyde::path('test-publication')); } From ab1566ad33ca9895cd2604321e2d8f6025e4323c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 18:58:23 +0100 Subject: [PATCH 099/129] Change source path to be schema.json for listing pages --- .../Features/Publications/Models/PublicationListPage.php | 2 +- packages/framework/tests/Feature/PublicationListPageTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 957b10431a2..561a03a015f 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -41,6 +41,6 @@ public function compile(): string public function getSourcePath(): string { - return $this->type->getDirectory().'/index.json'; + return $this->type->getDirectory().'/schema.json'; } } diff --git a/packages/framework/tests/Feature/PublicationListPageTest.php b/packages/framework/tests/Feature/PublicationListPageTest.php index 7d1ce758283..d0482784808 100644 --- a/packages/framework/tests/Feature/PublicationListPageTest.php +++ b/packages/framework/tests/Feature/PublicationListPageTest.php @@ -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/index.json', $page->getSourcePath()); + $this->assertSame('test-publication/schema.json', $page->getSourcePath()); File::deleteDirectory(Hyde::path('test-publication')); } From bc8bf55552e8b9b5bcb2079a63aa900cd1c2791d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 19:00:09 +0100 Subject: [PATCH 100/129] Use basename instead of str_replace --- packages/framework/src/Console/Commands/RouteListCommand.php | 4 +++- .../Features/Publications/Models/PublicationListPage.php | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Console/Commands/RouteListCommand.php b/packages/framework/src/Console/Commands/RouteListCommand.php index 522e04f6962..e68e60633e3 100644 --- a/packages/framework/src/Console/Commands/RouteListCommand.php +++ b/packages/framework/src/Console/Commands/RouteListCommand.php @@ -8,6 +8,8 @@ use Hyde\Hyde; use LaravelZero\Framework\Commands\Command; +use function basename; + /** * Hyde command to display the list of site routes. * @@ -51,7 +53,7 @@ protected function getRoutes(): array protected function formatPageType(string $class): string { - return str_replace('Hyde\\Pages\\', '', $class); + return basename($class); } protected function formatSourcePath(string $path): string diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 561a03a015f..f693b5021eb 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -23,8 +23,9 @@ class PublicationListPage extends BladePage public function __construct(PublicationType $type) { - parent::__construct("{$type->getDirectory()}/index"); $this->type = $type; + + parent::__construct("{$type->getDirectory()}/index"); } public function compile(): string From 9c44c8b5a20b4018bc43a64f63f665ad3fc35337 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 19:03:18 +0100 Subject: [PATCH 101/129] Display fully qualified class name for non-Hyde pages --- packages/framework/src/Console/Commands/RouteListCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Console/Commands/RouteListCommand.php b/packages/framework/src/Console/Commands/RouteListCommand.php index e68e60633e3..620a361781d 100644 --- a/packages/framework/src/Console/Commands/RouteListCommand.php +++ b/packages/framework/src/Console/Commands/RouteListCommand.php @@ -9,6 +9,7 @@ use LaravelZero\Framework\Commands\Command; use function basename; +use function str_starts_with; /** * Hyde command to display the list of site routes. @@ -53,7 +54,7 @@ protected function getRoutes(): array protected function formatPageType(string $class): string { - return basename($class); + return str_starts_with($class, 'Hyde') ? basename($class) : $class; } protected function formatSourcePath(string $path): string From 537d423367a3451b3b554ade229555163b16d382 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 19:05:38 +0100 Subject: [PATCH 102/129] Remove class BuildPublicationsCommand merged into standard build command --- .../Commands/BuildPublicationsCommand.php | 67 ------------------- .../Console/HydeConsoleServiceProvider.php | 1 - 2 files changed, 68 deletions(-) diff --git a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php index 737dcc31e2f..c7f49c5d27a 100644 --- a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php +++ b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php @@ -11,70 +11,3 @@ use Hyde\Pages\MarkdownPage; use LaravelZero\Framework\Commands\Command; use Rgasch\Collection\Collection; - -/** - * Hyde Command to run the Build Process. - * - * @see \Hyde\Framework\Testing\Feature\StaticSiteServiceTest - */ -class BuildPublicationsCommand extends Command implements CommandHandleInterface -{ - /** @var string */ - protected $signature = 'build:publications'; - - /** @var string */ - protected $description = 'Build the site publications'; - - protected BuildService $service; - - public function handle(): int - { - $this->build(); - - return Command::SUCCESS; - } - - // Warning: This is extremely hacky ... - protected function build(): void - { - $pubTypes = PublicationHelper::getPublicationTypes(); - foreach ($pubTypes as $dir => $pubType) { - $targetDirectory = "_site/$dir"; - @mkdir($targetDirectory); - $publications = PublicationHelper::getPublicationsForPubType($pubType); - $this->info("Building [$pubType->name] into [$targetDirectory] ..."); - $this->buildDetailPages($targetDirectory, $pubType, $publications); - $this->buildListPage($targetDirectory, $pubType, $publications); - } - } - - // TODO: Is detail page the right name? - protected function buildDetailPages(string $targetDirectory, PublicationType $pubType, Collection $publications): void - { - $template = $pubType->detailTemplate; - - // Mock a page - $page = new MarkdownPage($template); - view()->share('page', $page); - view()->share('currentPage', $template); - view()->share('currentRoute', $page->getRoute()); - - // TODO this should not be in the hyde namespace as user is expected to implement this right? - $detailTemplate = 'hyde::pubtypes.'.$template; - foreach ($publications as $publication) { - $slug = $publication->matter->__slug; - $this->info(" Building [$slug] ..."); - $html = view('hyde::layouts.pubtype')->with(['component' => $detailTemplate, 'publication' => $publication])->render(); - file_put_contents("$targetDirectory/{$slug}.html", $html); - } - } - - // TODO: Move to post build task? - protected function buildListPage(string $targetDirectory, PublicationType $pubType, Collection $publications): void - { - $template = 'hyde::pubtypes.'.$pubType->listTemplate; - $this->info(' Building list page ...'); - $html = view($template)->with('publications', $publications)->render(); - file_put_contents("$targetDirectory/index.html", $html); - } -} diff --git a/packages/framework/src/Console/HydeConsoleServiceProvider.php b/packages/framework/src/Console/HydeConsoleServiceProvider.php index ff954a4d160..2a34d84405f 100644 --- a/packages/framework/src/Console/HydeConsoleServiceProvider.php +++ b/packages/framework/src/Console/HydeConsoleServiceProvider.php @@ -18,7 +18,6 @@ public function register(): void { $this->commands( [ - Commands\BuildPublicationsCommand::class, Commands\BuildRssFeedCommand::class, Commands\BuildSearchCommand::class, Commands\BuildSiteCommand::class, From 447904109b24e6877f59698b20fd91dc970412fa Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 19:06:26 +0100 Subject: [PATCH 103/129] Delete BuildPublicationsCommand.php --- .../Console/Commands/BuildPublicationsCommand.php | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 packages/framework/src/Console/Commands/BuildPublicationsCommand.php diff --git a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php b/packages/framework/src/Console/Commands/BuildPublicationsCommand.php deleted file mode 100644 index c7f49c5d27a..00000000000 --- a/packages/framework/src/Console/Commands/BuildPublicationsCommand.php +++ /dev/null @@ -1,13 +0,0 @@ - Date: Sat, 19 Nov 2022 18:06:47 +0000 Subject: [PATCH 104/129] Apply fixes from StyleCI --- packages/framework/src/Console/Commands/RouteListCommand.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/src/Console/Commands/RouteListCommand.php b/packages/framework/src/Console/Commands/RouteListCommand.php index 620a361781d..3a637909d1e 100644 --- a/packages/framework/src/Console/Commands/RouteListCommand.php +++ b/packages/framework/src/Console/Commands/RouteListCommand.php @@ -4,11 +4,10 @@ namespace Hyde\Console\Commands; +use function basename; use Hyde\Framework\Services\DiscoveryService; use Hyde\Hyde; use LaravelZero\Framework\Commands\Command; - -use function basename; use function str_starts_with; /** From a3cacf759db57bb16ac43e03e76f3905167ed298 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 19:14:00 +0100 Subject: [PATCH 105/129] Add todo --- packages/framework/src/Foundation/PageCollection.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/src/Foundation/PageCollection.php b/packages/framework/src/Foundation/PageCollection.php index 99b26ccada8..21ef6a35e5a 100644 --- a/packages/framework/src/Foundation/PageCollection.php +++ b/packages/framework/src/Foundation/PageCollection.php @@ -67,6 +67,8 @@ protected function runDiscovery(): self $this->discoverPublicationPages(); } + // TODO: Add package developer hook to discover custom page types + return $this; } From 4ff2525ffbdab2a554b147ae0e084486e3180226 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 19:14:31 +0100 Subject: [PATCH 106/129] Remove legacy comment --- packages/framework/src/Foundation/PageCollection.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/framework/src/Foundation/PageCollection.php b/packages/framework/src/Foundation/PageCollection.php index 21ef6a35e5a..cc0b1ec2b87 100644 --- a/packages/framework/src/Foundation/PageCollection.php +++ b/packages/framework/src/Foundation/PageCollection.php @@ -97,7 +97,6 @@ protected function parsePagesFor(string $pageClass): Collection protected function discover(HydePage $page): self { - // Create a new route for the given page, and add it to the index. $this->put($page->getSourcePath(), $page); return $this; From 6cfd02c96ed7f1b1abcc68a88731adfd5b82c673 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 19:14:55 +0100 Subject: [PATCH 107/129] Remove resolved todo --- packages/framework/src/Pages/PublicationPage.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index e505248fd57..a65431ef9a1 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -30,8 +30,6 @@ public function __construct(PublicationType $type, string $identifier = '', Fron $this->type = $type; } - // TODO: override method to get output directory from publication type etc - public function compile(): string { $detailTemplate = $this->type->getSchema()['detailTemplate']; From 079b667e681e1eb95299e76f9e3aefcb8cfd1014 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 19:15:11 +0100 Subject: [PATCH 108/129] Update constructor semantics to match sibling class --- packages/framework/src/Pages/PublicationPage.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index a65431ef9a1..fd52911518c 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -26,8 +26,9 @@ class PublicationPage extends Concerns\BaseMarkdownPage public function __construct(PublicationType $type, string $identifier = '', FrontMatter|array $matter = [], Markdown|string $markdown = '') { - parent::__construct("{$type->getDirectory()}/$identifier", $matter, $markdown); $this->type = $type; + + parent::__construct("{$type->getDirectory()}/$identifier", $matter, $markdown); } public function compile(): string From fa79eb529b2dc685cd843bea3e7de4e4053a4c73 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 19:46:46 +0100 Subject: [PATCH 109/129] Delete blah directory --- blah/123.md | 8 -------- blah/aaa.md | 8 -------- blah/abc.md | 8 -------- blah/schema.json | 30 ------------------------------ 4 files changed, 54 deletions(-) delete mode 100644 blah/123.md delete mode 100644 blah/aaa.md delete mode 100644 blah/abc.md delete mode 100644 blah/schema.json diff --git a/blah/123.md b/blah/123.md deleted file mode 100644 index c1f19b8ab37..00000000000 --- a/blah/123.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -__canonical: 123 -__createdAt: 2022-11-16 11:32:52 -f1: 123 -f2: 456 -f3: 789 ---- -Raw MD text ... diff --git a/blah/aaa.md b/blah/aaa.md deleted file mode 100644 index b098ae172e8..00000000000 --- a/blah/aaa.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -__canonical: aaa -__createdAt: 2022-11-16 11:33:05 -f1: aaa -f2: bbb -f3: ccc ---- -Raw MD text ... diff --git a/blah/abc.md b/blah/abc.md deleted file mode 100644 index 2391eba6522..00000000000 --- a/blah/abc.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -__canonical: abc -__createdAt: 2022-11-16 11:32:36 -f1: abc -f2: def -f3: ghi ---- -Raw MD text ... diff --git a/blah/schema.json b/blah/schema.json deleted file mode 100644 index 4822065f77b..00000000000 --- a/blah/schema.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "blah", - "canonicalField": "f1", - "sortField": "__createdAt", - "sortDirection": "DESC", - "pagesize": 0, - "prevNextLinks": true, - "detailTemplate": "blah_detail", - "listTemplate": "blah_list", - "fields": [ - { - "name": "f1", - "min": "0", - "max": "0", - "type": "string" - }, - { - "name": "f2", - "min": "0", - "max": "0", - "type": "string" - }, - { - "name": "f3", - "min": "0", - "max": "0", - "type": "string" - } - ] -} \ No newline at end of file From b21cae6111ec82c15a44d13261c3dd2bbfa233ab Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 19:47:20 +0100 Subject: [PATCH 110/129] Remove file extension from templates to match actual schema --- packages/framework/tests/Feature/PublicationListPageTest.php | 4 ++-- packages/framework/tests/Feature/PublicationPageTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/framework/tests/Feature/PublicationListPageTest.php b/packages/framework/tests/Feature/PublicationListPageTest.php index d0482784808..b03d0ff15e0 100644 --- a/packages/framework/tests/Feature/PublicationListPageTest.php +++ b/packages/framework/tests/Feature/PublicationListPageTest.php @@ -48,8 +48,8 @@ protected function createPublicationFiles(): void mkdir(Hyde::path('test-publication')); file_put_contents(Hyde::path('test-publication/schema.json'), json_encode([ 'foo' => 'bar', - 'detailTemplate' => 'test_detail.blade.php', - 'listTemplate' => 'test_list.blade.php', + 'detailTemplate' => 'test_detail', + 'listTemplate' => 'test_list', ])); file_put_contents( Hyde::path('test-publication/foo.md'), diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index 2cbdabc296a..960236b1970 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -100,8 +100,8 @@ protected function createRealPublicationFiles(): void "sortDirection": "DESC", "pagesize": 0, "prevNextLinks": true, - "detailTemplate": "test_detail.blade.php", - "listTemplate": "test_list.blade.php", + "detailTemplate": "test_detail", + "listTemplate": "test_list", "fields": [ { "name": "slug", From 594e9fe66533a7f66b9bc826b79c9aa1fe1eaa3f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 19:59:30 +0100 Subject: [PATCH 111/129] No longer need to trim file extension not present in schema anymore --- .../Features/Publications/Models/PublicationListPage.php | 1 - packages/framework/src/Pages/PublicationPage.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index f693b5021eb..935c70c811d 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -31,7 +31,6 @@ public function __construct(PublicationType $type) public function compile(): string { $listTemplate = $this->type->getSchema()['listTemplate']; - $listTemplate = Str::before("$listTemplate", '.blade.php'); $pubType = $this->type; $template = 'pubtypes.'.$listTemplate; diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index fd52911518c..24b9cf415a5 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -34,7 +34,7 @@ public function __construct(PublicationType $type, string $identifier = '', Fron public function compile(): string { $detailTemplate = $this->type->getSchema()['detailTemplate']; - $component = Str::before("pubtypes.$detailTemplate", '.blade.php'); + $component = "pubtypes.$detailTemplate"; return view('hyde::layouts.pubtype')->with(['component' => $component, 'publication' => $this])->render(); } From 76870167caf804929147300317a92b2fed4411f5 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sat, 19 Nov 2022 18:59:42 +0000 Subject: [PATCH 112/129] Apply fixes from StyleCI --- .../Features/Publications/Models/PublicationListPage.php | 1 - packages/framework/src/Pages/PublicationPage.php | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 935c70c811d..a6c4391152d 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -6,7 +6,6 @@ use Hyde\Framework\Features\Publications\PublicationHelper; use Hyde\Pages\BladePage; -use Illuminate\Support\Str; use function view; /** diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index 24b9cf415a5..b0a91009c34 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -7,7 +7,6 @@ use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Markdown\Models\FrontMatter; use Hyde\Markdown\Models\Markdown; -use Illuminate\Support\Str; use function view; /** From 275299b3c489391e54eb177a004b5cc9b297595e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 20:08:19 +0100 Subject: [PATCH 113/129] Update legacy path expectation --- packages/framework/tests/Feature/PageCollectionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/PageCollectionTest.php b/packages/framework/tests/Feature/PageCollectionTest.php index e47f0c2b293..bc65f22b35c 100644 --- a/packages/framework/tests/Feature/PageCollectionTest.php +++ b/packages/framework/tests/Feature/PageCollectionTest.php @@ -198,7 +198,7 @@ public function test_publication_pages_are_discovered() $this->assertInstanceOf(PublicationPage::class, $collection->get('publication/foo.md')); // Test listing pages for publications are discovered - $this->assertInstanceOf(PublicationListPage::class, $collection->get('__publications/publication/index.json')); + $this->assertInstanceOf(PublicationListPage::class, $collection->get('publication/schema.json')); File::deleteDirectory(Hyde::path('publication')); } From 47780d62c4c92afd17b294400d9dc56e1e034404 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 20:12:47 +0100 Subject: [PATCH 114/129] Split out into two tests --- .../tests/Feature/PageCollectionTest.php | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/packages/framework/tests/Feature/PageCollectionTest.php b/packages/framework/tests/Feature/PageCollectionTest.php index bc65f22b35c..3d1bb088b09 100644 --- a/packages/framework/tests/Feature/PageCollectionTest.php +++ b/packages/framework/tests/Feature/PageCollectionTest.php @@ -183,23 +183,38 @@ public function test_pages_with_custom_source_directories_are_discovered_properl public function test_publication_pages_are_discovered() { mkdir(Hyde::path('publication')); - file_put_contents(Hyde::path('publication/schema.json'), json_encode(['foo' => 'bar'])); - file_put_contents(Hyde::path('publication/foo.md'), '--- -__canonical: canonical -__createdAt: 2022-11-16 11:32:52 -foo: bar ---- - -Hello World! -'); + $this->createPublication(); $collection = PageCollection::boot(Hyde::getInstance())->getPages(); $this->assertCount(4, $collection); // Default pages + publication index + publication page $this->assertInstanceOf(PublicationPage::class, $collection->get('publication/foo.md')); - // Test listing pages for publications are discovered - $this->assertInstanceOf(PublicationListPage::class, $collection->get('publication/schema.json')); + File::deleteDirectory(Hyde::path('publication')); + } + + public function test_listing_pages_for_publications_are_discovered() + { + mkdir(Hyde::path('publication')); + $this->createPublication(); + + $this->assertInstanceOf(PublicationListPage::class, PageCollection::boot(Hyde::getInstance())->getPage('publication/schema.json')); File::deleteDirectory(Hyde::path('publication')); } + + protected function createPublication(): void + { + file_put_contents(Hyde::path('publication/schema.json'), json_encode(['foo' => 'bar'])); + file_put_contents( + Hyde::path('publication/foo.md'), + '--- +__canonical: canonical +__createdAt: 2022-11-16 11:32:52 +foo: bar +--- + +Hello World! +' + ); + } } From d9213198aff1f8e1011ce19253251d139b59bdd5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 20:12:56 +0100 Subject: [PATCH 115/129] Formatting --- packages/framework/tests/Feature/PageCollectionTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/framework/tests/Feature/PageCollectionTest.php b/packages/framework/tests/Feature/PageCollectionTest.php index 3d1bb088b09..b96db553a41 100644 --- a/packages/framework/tests/Feature/PageCollectionTest.php +++ b/packages/framework/tests/Feature/PageCollectionTest.php @@ -197,7 +197,10 @@ public function test_listing_pages_for_publications_are_discovered() mkdir(Hyde::path('publication')); $this->createPublication(); - $this->assertInstanceOf(PublicationListPage::class, PageCollection::boot(Hyde::getInstance())->getPage('publication/schema.json')); + $this->assertInstanceOf( + PublicationListPage::class, + PageCollection::boot(Hyde::getInstance())->getPage('publication/schema.json') + ); File::deleteDirectory(Hyde::path('publication')); } @@ -205,8 +208,7 @@ public function test_listing_pages_for_publications_are_discovered() protected function createPublication(): void { file_put_contents(Hyde::path('publication/schema.json'), json_encode(['foo' => 'bar'])); - file_put_contents( - Hyde::path('publication/foo.md'), + file_put_contents(Hyde::path('publication/foo.md'), '--- __canonical: canonical __createdAt: 2022-11-16 11:32:52 From 64f1ad6bc5da5e5fd828199684b814028f3ff53a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 20:22:33 +0100 Subject: [PATCH 116/129] Use class_basename as basename only works for classes on Windows --- packages/framework/src/Console/Commands/RouteListCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Console/Commands/RouteListCommand.php b/packages/framework/src/Console/Commands/RouteListCommand.php index 3a637909d1e..7bf1a4e39a9 100644 --- a/packages/framework/src/Console/Commands/RouteListCommand.php +++ b/packages/framework/src/Console/Commands/RouteListCommand.php @@ -53,7 +53,7 @@ protected function getRoutes(): array protected function formatPageType(string $class): string { - return str_starts_with($class, 'Hyde') ? basename($class) : $class; + return str_starts_with($class, 'Hyde') ? class_basename($class) : $class; } protected function formatSourcePath(string $path): string From 171a144e5c672702b136135e21932828d52e520f Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sat, 19 Nov 2022 19:23:25 +0000 Subject: [PATCH 117/129] Apply fixes from StyleCI --- packages/framework/src/Console/Commands/RouteListCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/framework/src/Console/Commands/RouteListCommand.php b/packages/framework/src/Console/Commands/RouteListCommand.php index 7bf1a4e39a9..73d353c1a15 100644 --- a/packages/framework/src/Console/Commands/RouteListCommand.php +++ b/packages/framework/src/Console/Commands/RouteListCommand.php @@ -4,7 +4,6 @@ namespace Hyde\Console\Commands; -use function basename; use Hyde\Framework\Services\DiscoveryService; use Hyde\Hyde; use LaravelZero\Framework\Commands\Command; From 40e065a71c181b21964960eab6a9f2fd11039a7a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 20:26:56 +0100 Subject: [PATCH 118/129] Update view function call syntax to match other classes This doesn't change semantics --- .../Features/Publications/Models/PublicationListPage.php | 4 +++- packages/framework/src/Pages/PublicationPage.php | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index a6c4391152d..b5f6da1f9db 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -35,7 +35,9 @@ public function compile(): string $template = 'pubtypes.'.$listTemplate; $publications = PublicationHelper::getPublicationsForPubType($pubType); - return view($template)->with('publications', $publications)->render(); + return view($template, [ + 'publications' => $publications + ])->render(); } public function getSourcePath(): string diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index b0a91009c34..d98f607d50d 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -35,6 +35,9 @@ public function compile(): string $detailTemplate = $this->type->getSchema()['detailTemplate']; $component = "pubtypes.$detailTemplate"; - return view('hyde::layouts.pubtype')->with(['component' => $component, 'publication' => $this])->render(); + return view('hyde::layouts.pubtype', [ + 'component' => $component, + 'publication' => $this + ])->render(); } } From 636ecdd6c67bbe19f70ee05d20c0f9b0a50f9418 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 20:28:57 +0100 Subject: [PATCH 119/129] Inline unnecessary local variables --- .../Publications/Models/PublicationListPage.php | 10 ++-------- packages/framework/src/Pages/PublicationPage.php | 5 +---- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index b5f6da1f9db..ff6f32c2b2f 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -29,14 +29,8 @@ public function __construct(PublicationType $type) public function compile(): string { - $listTemplate = $this->type->getSchema()['listTemplate']; - - $pubType = $this->type; - $template = 'pubtypes.'.$listTemplate; - $publications = PublicationHelper::getPublicationsForPubType($pubType); - - return view($template, [ - 'publications' => $publications + return view("pubtypes.{$this->type->getSchema()['listTemplate']}", [ + 'publications' => PublicationHelper::getPublicationsForPubType($this->type) ])->render(); } diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index d98f607d50d..76e95f720d5 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -32,11 +32,8 @@ public function __construct(PublicationType $type, string $identifier = '', Fron public function compile(): string { - $detailTemplate = $this->type->getSchema()['detailTemplate']; - $component = "pubtypes.$detailTemplate"; - return view('hyde::layouts.pubtype', [ - 'component' => $component, + 'component' => "pubtypes.{$this->type->getSchema()['detailTemplate']}", 'publication' => $this ])->render(); } From ef8192e6760f199480cd485610df712c4c2c377d Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sat, 19 Nov 2022 19:29:08 +0000 Subject: [PATCH 120/129] Apply fixes from StyleCI --- .../Features/Publications/Models/PublicationListPage.php | 2 +- packages/framework/src/Pages/PublicationPage.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index ff6f32c2b2f..039650bf87c 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -30,7 +30,7 @@ public function __construct(PublicationType $type) public function compile(): string { return view("pubtypes.{$this->type->getSchema()['listTemplate']}", [ - 'publications' => PublicationHelper::getPublicationsForPubType($this->type) + 'publications' => PublicationHelper::getPublicationsForPubType($this->type), ])->render(); } diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index 76e95f720d5..add257732b1 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -34,7 +34,7 @@ public function compile(): string { return view('hyde::layouts.pubtype', [ 'component' => "pubtypes.{$this->type->getSchema()['detailTemplate']}", - 'publication' => $this + 'publication' => $this, ])->render(); } } From ac810b06cc3a1f26aa7a5d8b376260f74015c81b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 20:30:17 +0100 Subject: [PATCH 121/129] Update Blade comment to match file --- packages/framework/resources/views/layouts/pubtype.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/resources/views/layouts/pubtype.blade.php b/packages/framework/resources/views/layouts/pubtype.blade.php index 08f49411951..d27772ec0d7 100644 --- a/packages/framework/resources/views/layouts/pubtype.blade.php +++ b/packages/framework/resources/views/layouts/pubtype.blade.php @@ -1,4 +1,4 @@ -{{-- The Post Page Layout --}} +{{-- The Publication Page Layout --}} @extends('hyde::layouts.app') @section('content') From 4c48512365f7425e4a21491a71401f0059d50ec4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 19 Nov 2022 20:31:09 +0100 Subject: [PATCH 122/129] Breaking: Rename view pubtype to publication --- .../views/layouts/{pubtype.blade.php => publication.blade.php} | 0 packages/framework/src/Pages/PublicationPage.php | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename packages/framework/resources/views/layouts/{pubtype.blade.php => publication.blade.php} (100%) diff --git a/packages/framework/resources/views/layouts/pubtype.blade.php b/packages/framework/resources/views/layouts/publication.blade.php similarity index 100% rename from packages/framework/resources/views/layouts/pubtype.blade.php rename to packages/framework/resources/views/layouts/publication.blade.php diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index add257732b1..f59a5f1e13c 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -32,7 +32,7 @@ public function __construct(PublicationType $type, string $identifier = '', Fron public function compile(): string { - return view('hyde::layouts.pubtype', [ + return view('hyde::layouts.publication', [ 'component' => "pubtypes.{$this->type->getSchema()['detailTemplate']}", 'publication' => $this, ])->render(); From 0fffa9745c0b6c17cfafc5fe694d43d4bec30f61 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 15:57:42 +0100 Subject: [PATCH 123/129] Store publication list template in the publication directory --- .../Models/PublicationListPage.php | 20 +++++++++++++++++-- .../tests/Feature/PublicationListPageTest.php | 4 +--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 039650bf87c..5286bb48fda 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -5,7 +5,17 @@ namespace Hyde\Framework\Features\Publications\Models; use Hyde\Framework\Features\Publications\PublicationHelper; +use Hyde\Hyde; use Hyde\Pages\BladePage; + +use Illuminate\Support\Facades\Blade; + +use function array_merge; +use function array_unique; +use function base_path; +use function config; +use function file_get_contents; +use function str_contains; use function view; /** @@ -29,9 +39,15 @@ public function __construct(PublicationType $type) public function compile(): string { - return view("pubtypes.{$this->type->getSchema()['listTemplate']}", [ + $data = [ 'publications' => PublicationHelper::getPublicationsForPubType($this->type), - ])->render(); + ]; + + $template = $this->type->getSchema()['listTemplate']; + return Blade::render( + file_get_contents(Hyde::path("{$this->type->getDirectory()}/$template") . ".blade.php"), + $data + ); } public function getSourcePath(): string diff --git a/packages/framework/tests/Feature/PublicationListPageTest.php b/packages/framework/tests/Feature/PublicationListPageTest.php index b03d0ff15e0..fdaa7b14f66 100644 --- a/packages/framework/tests/Feature/PublicationListPageTest.php +++ b/packages/framework/tests/Feature/PublicationListPageTest.php @@ -31,10 +31,8 @@ public function test_source_path_mappings() public function test_listing_page_can_be_compiled() { $this->createPublicationFiles(); - // Temporary until we settle on where to store templates - @mkdir(resource_path('views/pubtypes')); - $this->file('resources/views/pubtypes/test_list.blade.php', 'Listing Page'); + file_put_contents(Hyde::path('test-publication/test_list.blade.php'), 'Listing Page'); $page = new PublicationListPage($this->getPublicationType()); From 4005ca86c4189b68cfd5df3b6cbfa75e93cef911 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 15:57:58 +0100 Subject: [PATCH 124/129] Render template as is if it's a vendor view --- .../Features/Publications/Models/PublicationListPage.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 5286bb48fda..d34bad4850f 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -44,6 +44,9 @@ public function compile(): string ]; $template = $this->type->getSchema()['listTemplate']; + if (str_contains($template, '::')) { + return view($template, $data)->render(); + } return Blade::render( file_get_contents(Hyde::path("{$this->type->getDirectory()}/$template") . ".blade.php"), $data From b8709da0ecc422bbe5ea725a23a2da0f1720f87f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 15:58:22 +0100 Subject: [PATCH 125/129] Style fix --- .../Features/Publications/Models/PublicationListPage.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index d34bad4850f..7b456e6ce6c 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -48,8 +48,7 @@ public function compile(): string return view($template, $data)->render(); } return Blade::render( - file_get_contents(Hyde::path("{$this->type->getDirectory()}/$template") . ".blade.php"), - $data + file_get_contents(Hyde::path("{$this->type->getDirectory()}/$template").'.blade.php'), $data ); } From f910db146cb09df401b7105db1dbddb99184a5ca Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 20 Nov 2022 14:58:34 +0000 Subject: [PATCH 126/129] Apply fixes from StyleCI --- .../Features/Publications/Models/PublicationListPage.php | 9 ++------- .../framework/tests/Feature/PublicationListPageTest.php | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 7b456e6ce6c..9b0693a836f 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -4,17 +4,11 @@ namespace Hyde\Framework\Features\Publications\Models; +use function file_get_contents; use Hyde\Framework\Features\Publications\PublicationHelper; use Hyde\Hyde; use Hyde\Pages\BladePage; - use Illuminate\Support\Facades\Blade; - -use function array_merge; -use function array_unique; -use function base_path; -use function config; -use function file_get_contents; use function str_contains; use function view; @@ -47,6 +41,7 @@ public function compile(): string if (str_contains($template, '::')) { return view($template, $data)->render(); } + return Blade::render( file_get_contents(Hyde::path("{$this->type->getDirectory()}/$template").'.blade.php'), $data ); diff --git a/packages/framework/tests/Feature/PublicationListPageTest.php b/packages/framework/tests/Feature/PublicationListPageTest.php index fdaa7b14f66..6edb65f1880 100644 --- a/packages/framework/tests/Feature/PublicationListPageTest.php +++ b/packages/framework/tests/Feature/PublicationListPageTest.php @@ -32,7 +32,7 @@ public function test_listing_page_can_be_compiled() { $this->createPublicationFiles(); - file_put_contents(Hyde::path('test-publication/test_list.blade.php'), 'Listing Page'); + file_put_contents(Hyde::path('test-publication/test_list.blade.php'), 'Listing Page'); $page = new PublicationListPage($this->getPublicationType()); From fbee205117eb09722db640ed4f45944137098c73 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 16:03:06 +0100 Subject: [PATCH 127/129] Add code documentation --- .../Features/Publications/Models/PublicationListPage.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php index 9b0693a836f..45a2ee03eec 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationListPage.php @@ -42,6 +42,7 @@ public function compile(): string return view($template, $data)->render(); } + // Using the Blade facade we can render any file without having to register the directory with the view finder. return Blade::render( file_get_contents(Hyde::path("{$this->type->getDirectory()}/$template").'.blade.php'), $data ); From ae16ae18393a8f47dad05880a6288f5d1a1dab08 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 20 Nov 2022 16:09:40 +0100 Subject: [PATCH 128/129] Refactor to render detail page in page class --- .../views/layouts/publication.blade.php | 2 +- .../framework/src/Pages/PublicationPage.php | 25 +++++++++++++++++-- .../tests/Feature/PublicationPageTest.php | 4 +-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/packages/framework/resources/views/layouts/publication.blade.php b/packages/framework/resources/views/layouts/publication.blade.php index d27772ec0d7..7808448a5e5 100644 --- a/packages/framework/resources/views/layouts/publication.blade.php +++ b/packages/framework/resources/views/layouts/publication.blade.php @@ -3,7 +3,7 @@ @section('content')
- @include($component, ['publication' => $publication]) + {{ $publication }}
@endsection \ No newline at end of file diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index f59a5f1e13c..5d02d869849 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -5,8 +5,13 @@ namespace Hyde\Pages; use Hyde\Framework\Features\Publications\Models\PublicationType; +use Hyde\Hyde; use Hyde\Markdown\Models\FrontMatter; use Hyde\Markdown\Models\Markdown; +use Illuminate\Support\Facades\Blade; +use Illuminate\Support\HtmlString; + +use function file_get_contents; use function view; /** @@ -33,8 +38,24 @@ public function __construct(PublicationType $type, string $identifier = '', Fron public function compile(): string { return view('hyde::layouts.publication', [ - 'component' => "pubtypes.{$this->type->getSchema()['detailTemplate']}", - 'publication' => $this, + 'publication' => new HtmlString($this->renderComponent()), ])->render(); } + + protected function renderComponent(): string + { + $data = [ + 'publication' => $this, + ]; + + $template = $this->type->getSchema()['detailTemplate']; + if (str_contains($template, '::')) { + return view($template, $data)->render(); + } + + // Using the Blade facade we can render any file without having to register the directory with the view finder. + return Blade::render( + file_get_contents(Hyde::path("{$this->type->getDirectory()}/$template.blade.php")), $data + ); + } } diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index 960236b1970..790f8a94dcd 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -124,9 +124,7 @@ protected function createRealPublicationFiles(): void ); // Temporary until we settle on where to store templates - @mkdir(resource_path('views/pubtypes')); - $this->file('resources/views/pubtypes/test_list.blade.php'); - $this->file('resources/views/pubtypes/test_detail.blade.php', '{{ ($publication->markdown()->body()) }}'); + file_put_contents(Hyde::path('test-publication/test_detail.blade.php'), '{{ ($publication->markdown()->body()) }}'); } protected function createPublicationFiles(): void From a7c862b8c06cbdf417bcc1bd4378354df028df42 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 20 Nov 2022 15:10:24 +0000 Subject: [PATCH 129/129] Apply fixes from StyleCI --- packages/framework/src/Pages/PublicationPage.php | 3 +-- packages/framework/tests/Feature/PublicationPageTest.php | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/framework/src/Pages/PublicationPage.php b/packages/framework/src/Pages/PublicationPage.php index 5d02d869849..7ce93a1ce84 100644 --- a/packages/framework/src/Pages/PublicationPage.php +++ b/packages/framework/src/Pages/PublicationPage.php @@ -4,14 +4,13 @@ namespace Hyde\Pages; +use function file_get_contents; use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Hyde; use Hyde\Markdown\Models\FrontMatter; use Hyde\Markdown\Models\Markdown; use Illuminate\Support\Facades\Blade; use Illuminate\Support\HtmlString; - -use function file_get_contents; use function view; /** diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index 790f8a94dcd..4c59fed8f34 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -13,7 +13,6 @@ use Hyde\Testing\TestCase; use function json_encode; use function mkdir; -use function resource_path; /** * @covers \Hyde\Pages\PublicationPage