Skip to content

Commit

Permalink
Add parent Method
Browse files Browse the repository at this point in the history
  • Loading branch information
taufik-nurrohman committed Jun 11, 2022
1 parent e82bf8f commit b1265f0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion about.page
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Convert file and folder structure into web pages.
icon: 'M19 2L14 6.5V17.5L19 13V2M6.5 5C4.55 5 2.45 5.4 1 6.5V21.16C1 21.41 1.25 21.66 1.5 21.66C1.6 21.66 1.65 21.59 1.75 21.59C3.1 20.94 5.05 20.5 6.5 20.5C8.45 20.5 10.55 20.9 12 22C13.35 21.15 15.8 20.5 17.5 20.5C19.15 20.5 20.85 20.81 22.25 21.56C22.35 21.61 22.4 21.59 22.5 21.59C22.75 21.59 23 21.34 23 21.09V6.5C22.4 6.05 21.75 5.75 21 5.5V19C19.9 18.65 18.7 18.5 17.5 18.5C15.8 18.5 13.35 19.15 12 20V6.5C10.55 5.4 8.45 5 6.5 5Z'
author: Taufik Nurrohman
type: Markdown
version: 2.0.3
version: 2.1.0

use:
'.\lot\x\layout': 1
Expand Down
12 changes: 12 additions & 0 deletions engine/kernel/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ public function offsetUnset($key): void {
unset($this->cache[$key], $this->lot[$key]);
}

public function parent(array $lot = []) {
if (!$this->exist()) {
return null;
}
$folder = dirname($this->path);
$path = exist([
$folder . '.archive',
$folder . '.page'
], 1);
return $path ? new static($path, $lot) : null;
}

public function time(string $format = null) {
$name = parent::name();
// Set `time` value from the page’s file name
Expand Down
8 changes: 4 additions & 4 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ function route($content, $path, $query, $hash) {
$folder . '.page'
], 1)) {
$page = new \Page($file);
$pager = new \Pager\Page([], null, (object) [
$pager = new \Pager\Page([], null, new \Page(null, [
'link' => $path ? $url . "" : null
]);
]));
$chunk = $page['chunk'] ?? 5;
$deep = $page['deep'] ?? 0;
$sort = $page['sort'] ?? [1, 'path'];
Expand Down Expand Up @@ -136,9 +136,9 @@ function route($content, $path, $query, $hash) {
return ['page', [], 200];
}
// Create pager for “pages” mode
$pager = new \Pager\Pages($pages->get(), [$chunk, $i], (object) [
$pager = new \Pager\Pages($pages->get(), [$chunk, $i], new \Page(null, [
'link' => $url . '/' . ($path ?: $route)
]);
]));
// Disable parent link in root page
if (!$path || false === \strpos($path, '/') && $i < 1) {
$pager->parent = null;
Expand Down

0 comments on commit b1265f0

Please sign in to comment.