diff --git a/formwork/config/site.yaml b/formwork/config/site.yaml index d61f9986..c70662d0 100644 --- a/formwork/config/site.yaml +++ b/formwork/config/site.yaml @@ -1,7 +1,9 @@ -canonicalRoute: null +author: '' defaultTemplate: page +description: '' + maintenance: enabled: false page: null diff --git a/formwork/fields/markdown.php b/formwork/fields/markdown.php index 366d4a8e..7d843331 100644 --- a/formwork/fields/markdown.php +++ b/formwork/fields/markdown.php @@ -2,8 +2,8 @@ use Formwork\Fields\Exceptions\ValidationException; use Formwork\Fields\Field; -use Formwork\Pages\Site; use Formwork\Parsers\Markdown; +use Formwork\Site; use Formwork\Utils\Constraint; use Formwork\Utils\Str; diff --git a/formwork/fields/page.php b/formwork/fields/page.php index 915df8ad..8e19303b 100644 --- a/formwork/fields/page.php +++ b/formwork/fields/page.php @@ -4,7 +4,7 @@ use Formwork\Fields\Exceptions\ValidationException; use Formwork\Fields\Field; use Formwork\Pages\Page; use Formwork\Pages\PageCollection; -use Formwork\Pages\Site; +use Formwork\Site; return function (Site $site) { return [ diff --git a/formwork/fields/template.php b/formwork/fields/template.php index 24a31684..ae6cd7cc 100644 --- a/formwork/fields/template.php +++ b/formwork/fields/template.php @@ -1,7 +1,7 @@ filesCache->clear(); - if ($this->site->path() !== null) { - FileSystem::touch($this->site->path()); + if ($this->site->contentPath() !== null) { + FileSystem::touch($this->site->contentPath()); } } diff --git a/formwork/src/Files/FileUriGenerator.php b/formwork/src/Files/FileUriGenerator.php index 02f32896..010e8850 100644 --- a/formwork/src/Files/FileUriGenerator.php +++ b/formwork/src/Files/FileUriGenerator.php @@ -4,8 +4,8 @@ namespace Formwork\Files; use Formwork\Config\Config; use Formwork\Files\Exceptions\FileUriGenerationException; -use Formwork\Pages\Site; use Formwork\Router\Router; +use Formwork\Site; use Formwork\Utils\FileSystem; use Formwork\Utils\Str; use RuntimeException; diff --git a/formwork/src/Pages/Page.php b/formwork/src/Pages/Page.php index e222b761..cbf4d911 100644 --- a/formwork/src/Pages/Page.php +++ b/formwork/src/Pages/Page.php @@ -16,6 +16,7 @@ use Formwork\Pages\Traits\PageStatus; use Formwork\Pages\Traits\PageTraversal; use Formwork\Pages\Traits\PageUid; use Formwork\Pages\Traits\PageUri; +use Formwork\Site; use Formwork\Utils\Arr; use Formwork\Utils\FileSystem; use Formwork\Utils\Path; @@ -493,6 +494,16 @@ class Page extends Model implements Stringable $this->__construct($data); } + public function contentPath(): ?string + { + return $this->path; + } + + public function contentRelativePath(): ?string + { + return $this->relativePath; + } + /** * Load files related to page */ @@ -602,11 +613,11 @@ class Page extends Model implements Stringable { $this->path = FileSystem::normalizePath($path . '/'); - if ($this->site()->path() === null) { + if ($this->site()->contentPath() === null) { throw new UnexpectedValueException('Unexpected missing site path'); } - $this->relativePath = Str::prepend(Path::makeRelative($this->path, $this->site()->path(), DS), DS); + $this->relativePath = Str::prepend(Path::makeRelative($this->path, $this->site()->contentPath(), DS), DS); $routePath = preg_replace('~[/\\\](\d+-)~', '/', $this->relativePath) ?? throw new RuntimeException(sprintf('Replacement failed with error: %s', preg_last_error_msg())); diff --git a/formwork/src/Pages/PageCollection.php b/formwork/src/Pages/PageCollection.php index fe773b1e..80e4f7c7 100644 --- a/formwork/src/Pages/PageCollection.php +++ b/formwork/src/Pages/PageCollection.php @@ -4,6 +4,7 @@ namespace Formwork\Pages; use Formwork\Data\AbstractCollection; use Formwork\Data\Contracts\Paginable; +use Formwork\Site; use Formwork\Utils\Str; use RuntimeException; diff --git a/formwork/src/Pages/Templates/Template.php b/formwork/src/Pages/Templates/Template.php index 725f33c3..3e35b848 100644 --- a/formwork/src/Pages/Templates/Template.php +++ b/formwork/src/Pages/Templates/Template.php @@ -5,7 +5,7 @@ namespace Formwork\Pages\Templates; use Closure; use Formwork\App; use Formwork\Assets; -use Formwork\Pages\Site; +use Formwork\Site; use Formwork\Utils\Constraint; use Formwork\Utils\FileSystem; use Formwork\View\Exceptions\RenderingException; diff --git a/formwork/src/Pages/Traits/PageTraversal.php b/formwork/src/Pages/Traits/PageTraversal.php index dc65bf5c..1d43bc1c 100644 --- a/formwork/src/Pages/Traits/PageTraversal.php +++ b/formwork/src/Pages/Traits/PageTraversal.php @@ -4,7 +4,7 @@ namespace Formwork\Pages\Traits; use Formwork\Pages\Page; use Formwork\Pages\PageCollection; -use Formwork\Pages\Site; +use Formwork\Site; use Formwork\Utils\FileSystem; use RuntimeException; @@ -43,7 +43,7 @@ trait PageTraversal /** * Get page or site path */ - abstract public function path(): ?string; + abstract public function contentPath(): ?string; /** * Get page or site route @@ -66,13 +66,13 @@ trait PageTraversal return $this->parent; } - if ($this->path() === null) { + if ($this->contentPath() === null) { return null; } - $parentPath = FileSystem::joinPaths(dirname($this->path()), '/'); + $parentPath = FileSystem::joinPaths(dirname($this->contentPath()), '/'); - if ($parentPath === $this->site()->path()) { + if ($parentPath === $this->site()->contentPath()) { return $this->parent = $this->site(); } @@ -104,11 +104,11 @@ trait PageTraversal return $this->children; } - if ($this->path() === null) { + if ($this->contentPath() === null) { return $this->children = new PageCollection(); } - return $this->children = $this->site()->retrievePages($this->path()); + return $this->children = $this->site()->retrievePages($this->contentPath()); } /** @@ -136,11 +136,11 @@ trait PageTraversal return $this->descendants; } - if ($this->path() === null) { + if ($this->contentPath() === null) { return $this->descendants = new PageCollection(); } - return $this->descendants = $this->site()->retrievePages($this->path(), recursive: true); + return $this->descendants = $this->site()->retrievePages($this->contentPath(), recursive: true); } /** @@ -213,7 +213,7 @@ trait PageTraversal return $this->inclusiveSiblings; } - if ($this->path() === null || $this->parent() === null) { + if ($this->contentPath() === null || $this->parent() === null) { return $this->inclusiveSiblings = new PageCollection([$this->route() => $this]); } diff --git a/formwork/src/Pages/Traits/PageUid.php b/formwork/src/Pages/Traits/PageUid.php index c32a1d22..ef7358cc 100644 --- a/formwork/src/Pages/Traits/PageUid.php +++ b/formwork/src/Pages/Traits/PageUid.php @@ -14,7 +14,7 @@ trait PageUid /** * Get page or site relative path */ - abstract public function relativePath(): ?string; + abstract public function contentRelativePath(): ?string; /** * Get the page unique identifier @@ -25,7 +25,7 @@ trait PageUid return $this->uid; } - $id = $this->relativePath() ?: spl_object_hash($this); + $id = $this->contentRelativePath() ?: spl_object_hash($this); return $this->uid = Str::chunk(substr(hash('sha256', (string) $id), 0, 32), 8, '-'); } diff --git a/formwork/src/Pages/Traits/PageUri.php b/formwork/src/Pages/Traits/PageUri.php index 13add050..05b71904 100644 --- a/formwork/src/Pages/Traits/PageUri.php +++ b/formwork/src/Pages/Traits/PageUri.php @@ -3,7 +3,7 @@ namespace Formwork\Pages\Traits; use Formwork\App; -use Formwork\Pages\Site; +use Formwork\Site; use Formwork\Utils\Path; use Formwork\Utils\Uri; diff --git a/formwork/src/Panel/Controllers/AbstractController.php b/formwork/src/Panel/Controllers/AbstractController.php index fb3f1131..3ffe4045 100644 --- a/formwork/src/Panel/Controllers/AbstractController.php +++ b/formwork/src/Panel/Controllers/AbstractController.php @@ -8,7 +8,6 @@ use Formwork\Controllers\AbstractController as BaseAbstractController; use Formwork\Http\RedirectResponse; use Formwork\Http\Request; use Formwork\Http\ResponseStatus; -use Formwork\Pages\Site; use Formwork\Panel\Modals\Modal; use Formwork\Panel\Modals\ModalCollection; use Formwork\Panel\Modals\ModalFactory; @@ -18,6 +17,7 @@ use Formwork\Parsers\Json; use Formwork\Router\Router; use Formwork\Security\CsrfToken; use Formwork\Services\Container; +use Formwork\Site; use Formwork\Translations\Translations; use Formwork\Utils\Date; use Formwork\Utils\Uri; diff --git a/formwork/src/Panel/Controllers/OptionsController.php b/formwork/src/Panel/Controllers/OptionsController.php index e5060496..787e3cab 100644 --- a/formwork/src/Panel/Controllers/OptionsController.php +++ b/formwork/src/Panel/Controllers/OptionsController.php @@ -50,10 +50,10 @@ class OptionsController extends AbstractController // Touch content folder to invalidate cache if ($differ) { - if ($this->site()->path() === null) { + if ($this->site()->contentPath() === null) { throw new UnexpectedValueException('Unexpected missing site path'); } - FileSystem::touch($this->site()->path()); + FileSystem::touch($this->site()->contentPath()); } $this->panel()->notify($this->translate('panel.options.updated'), 'success'); @@ -93,10 +93,10 @@ class OptionsController extends AbstractController // Touch content folder to invalidate cache if ($differ) { - if ($this->site()->path() === null) { + if ($this->site()->contentPath() === null) { throw new UnexpectedValueException('Unexpected missing site path'); } - FileSystem::touch($this->site()->path()); + FileSystem::touch($this->site()->contentPath()); } $this->panel()->notify($this->translate('panel.options.updated'), 'success'); diff --git a/formwork/src/Panel/Controllers/PagesController.php b/formwork/src/Panel/Controllers/PagesController.php index 8aadf694..a3cf2bc7 100644 --- a/formwork/src/Panel/Controllers/PagesController.php +++ b/formwork/src/Panel/Controllers/PagesController.php @@ -15,12 +15,12 @@ use Formwork\Http\RequestMethod; use Formwork\Http\Response; use Formwork\Images\Image; use Formwork\Pages\Page; -use Formwork\Pages\Site; use Formwork\Panel\ContentHistory\ContentHistory; use Formwork\Panel\ContentHistory\ContentHistoryEvent; use Formwork\Parsers\Yaml; use Formwork\Router\RouteParams; use Formwork\Schemes\Schemes; +use Formwork\Site; use Formwork\Utils\Arr; use Formwork\Utils\Constraint; use Formwork\Utils\Date; @@ -655,12 +655,12 @@ class PagesController extends AbstractController throw new UnexpectedValueException('Unexpected missing page path'); } - if ($this->site()->path() === null) { + if ($this->site()->contentPath() === null) { throw new UnexpectedValueException('Unexpected missing site path'); } FileSystem::write($page->path() . $filename, $fileContent); - FileSystem::touch($this->site()->path()); + FileSystem::touch($this->site()->contentPath()); $contentHistory = new ContentHistory($page->path()); diff --git a/formwork/src/Services/Loaders/SiteServiceLoader.php b/formwork/src/Services/Loaders/SiteServiceLoader.php index 344ba5b4..06cefad7 100644 --- a/formwork/src/Services/Loaders/SiteServiceLoader.php +++ b/formwork/src/Services/Loaders/SiteServiceLoader.php @@ -4,11 +4,10 @@ namespace Formwork\Services\Loaders; use Formwork\Config\Config; use Formwork\Languages\Languages; -use Formwork\Pages\Site; -use Formwork\Parsers\Yaml; use Formwork\Schemes\Schemes; use Formwork\Services\Container; use Formwork\Services\ResolutionAwareServiceLoaderInterface; +use Formwork\Site; class SiteServiceLoader implements ResolutionAwareServiceLoaderInterface { @@ -19,12 +18,13 @@ class SiteServiceLoader implements ResolutionAwareServiceLoaderInterface public function load(Container $container): Site { $this->schemes->loadFromPath($this->config->get('system.schemes.paths.site')); - $config = Yaml::parseFile(ROOT_PATH . '/site/config/site.yaml'); + $config = $this->config->get('site'); return $container->build(Site::class, ['data' => [ - 'path' => $this->config->get('system.pages.path'), - 'languages' => $this->languages, - ] + $config]); + ...$config, + 'contentPath' => $this->config->get('system.pages.path'), + 'languages' => $this->languages, + ]]); } /** diff --git a/formwork/src/Pages/Site.php b/formwork/src/Site.php similarity index 91% rename from formwork/src/Pages/Site.php rename to formwork/src/Site.php index b897fd60..1a312a09 100644 --- a/formwork/src/Pages/Site.php +++ b/formwork/src/Site.php @@ -1,19 +1,20 @@ config->getDefaults('site'); return [...$defaults, ...Arr::reject($this->fields()->pluck('default'), fn ($value) => $value === null)]; } @@ -150,14 +148,6 @@ class Site extends Model implements Stringable return $this->path; } - /** - * Get site relative path - */ - public function relativePath(): ?string - { - return $this->relativePath; - } - /** * Get site filename */ @@ -166,6 +156,16 @@ class Site extends Model implements Stringable return $this->contentFile; } + public function contentPath(): ?string + { + return $this->contentPath; + } + + public function contentRelativePath(): ?string + { + return '/'; + } + /** * Get site route */ @@ -254,10 +254,10 @@ class Site extends Model implements Stringable */ public function modifiedSince(int $time): bool { - if ($this->path === null) { + if ($this->contentPath === null) { return false; } - return FileSystem::directoryModifiedSince($this->path, $time); + return FileSystem::directoryModifiedSince($this->contentPath, $time); } /** @@ -322,7 +322,7 @@ class Site extends Model implements Stringable } $components = explode('/', trim($route, '/')); - $path = $this->path; + $path = $this->contentPath; if ($path === null) { return null; @@ -432,6 +432,14 @@ class Site extends Model implements Stringable $this->fields->setValues($this->data); } + /** + * @param array $metadata + */ + protected function setMetadata(array $metadata): void + { + $this->data['metadata'] = $metadata; + } + protected function loadTemplates(): void { $path = $this->config->get('system.templates.path'); @@ -460,9 +468,12 @@ class Site extends Model implements Stringable protected function setPath(string $path): void { - $this->path = FileSystem::normalizePath($path . '/'); + $this->path = $this->data['path'] = FileSystem::normalizePath($path . '/'); + } - $this->relativePath = DS; + protected function setContentPath(string $path): void + { + $this->contentPath = FileSystem::normalizePath($path . '/'); $this->route = '/'; diff --git a/panel/routes.php b/panel/routes.php index b921e161..3e12e1f7 100644 --- a/panel/routes.php +++ b/panel/routes.php @@ -4,9 +4,9 @@ use Formwork\Http\JsonResponse; use Formwork\Http\RedirectResponse; use Formwork\Http\Request; use Formwork\Http\ResponseStatus; -use Formwork\Pages\Site; use Formwork\Panel\Panel; use Formwork\Security\CsrfToken; +use Formwork\Site; use Formwork\Translations\Translations; use Formwork\Utils\FileSystem; diff --git a/site/config/site.yaml b/site/config/site.yaml index 0fc8f498..1f1fe742 100644 --- a/site/config/site.yaml +++ b/site/config/site.yaml @@ -1,2 +1 @@ title: Formwork -description: ''