From a32773b003cde42d5d48fee1423c06f50cf2040b Mon Sep 17 00:00:00 2001 From: Taufik Nurrohman Date: Sun, 22 May 2022 11:26:13 +0700 Subject: [PATCH] Update --- about.page | 9 +++++---- index.php | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/about.page b/about.page index c3804a4..0abbc46 100644 --- a/about.page +++ b/about.page @@ -1,6 +1,6 @@ --- title: Layout -description: Common automation function used to speed up site development. +description: Common automation features to speed up the site creation process. icon: 'M13,3V9H21V3M13,21H21V11H13M3,21H11V15H3M3,13H11V3H3V13Z' author: Taufik Nurrohman type: Markdown @@ -9,6 +9,7 @@ version: 2.0.0 ### Features - - Detect asset path relative to the `.\lot\asset` and `.\lot\y\*` folder. - - Detect layout path relative to the `.\lot\y\*` folder. - - Add HTML classes automatically to the `` element based on the current page conditional statements. \ No newline at end of file + - Add HTML classes automatically to the `` element based on the current page conditional statements. + - Custom layout path using page’s `layout` property. + - Detect asset path relative to the `.\lot\y\*` folder. + - Detect layout path relative to the `.\lot\y\*` folder. \ No newline at end of file diff --git a/index.php b/index.php index 1b8b1c0..4b165ca 100644 --- a/index.php +++ b/index.php @@ -24,7 +24,7 @@ function content($content) { $r = new \HTML($m[0]); $c = true === $r['class'] ? [] : \preg_split('/\s+/', $r['class'] ?? ""); $c = \array_unique(\array_merge($c, \array_keys(\array_filter((array) \State::get('[y]', true))))); - \sort($c); + \sort($c); // Sort class name(s) $r['class'] = \trim(\implode(' ', $c)); return $r; } @@ -34,9 +34,12 @@ function content($content) { return $content; } function get() { + if (!\class_exists("\\Asset")) { + return; + } foreach ($GLOBALS['Y'][1] ?? [] as $use) { // Detect relative asset path to the `.\lot\y\*` folder - if (\class_exists("\\Asset") && $assets = \Asset::get()) { + if ($assets = \Asset::get()) { foreach ($assets as $k => $v) { foreach ($v as $kk => $vv) { // Full path, no change! @@ -59,6 +62,17 @@ function get() { function route($content, $path) { \ob_start(); \ob_start("\\ob_gzhandler"); + if (\is_array($content) && \class_exists("\\Page")) { + $page = $GLOBALS['page'] ?? new \Page; + if ($page && $page instanceof \Page && ($layout = $page->layout)) { + // `$content = ['.\lot\y\log\page\gallery.php', [], 200];` + if (0 === \strpos($layout, ".\\")) { + $layout = \stream_resolve_include_path(\PATH . \D . \strtr(\substr($layout, 2), ["\\" => \D])); + } + // `$content = ['page/gallery', [], 200];` + $content[0] = $layout; + } + } // `$content = ['page', [], 200];` if (\is_array($content) && isset($content[0]) && \is_string($content[0])) { if ($r = \Layout::get(...$content)) {