Skip to content

Commit

Permalink
Detect Recursive Page(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
taufik-nurrohman committed Dec 15, 2023
1 parent 4d85806 commit b60ddc3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 20 deletions.
2 changes: 1 addition & 1 deletion about.page
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ images:
author: Taufik Nurrohman
link: https://www.styleshout.com/legacy-templates
type: Markdown
version: 2.0.0
version: 2.0.1
...

A classic template designed by [StyleShout][1]. The first time I found it on the [BTemplates][2] website around 2009
Expand Down
20 changes: 10 additions & 10 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
return $links;
})([], $state, $url));

$defaults = [
$states = [
'route-blog' => '/article',
'x.comment.page.type' => 'Markdown',
'x.page.page.type' => 'Markdown'
'x.comment.page.type' => isset($state->x->comment) ? 'Markdown' : null,
'x.page.page.type' => isset($state->x->page) ? 'Markdown' : null
];

foreach ($defaults as $k => $v) {
!State::get($k) && State::set($k, $v);
foreach ($states as $k => $v) {
!State::get($k) && null !== $v && State::set($k, $v);
}

if (!empty($state->y->outdoor->page->header) && $state->is('pages')) {
Expand All @@ -38,7 +38,7 @@
if ($search = trim(strip_tags(isset($state->x->search) ? ($_GET[$state->x->search->key ?? 'query'] ?? "") : ""))) {
Hook::set('route.search', function ($content, $path, $query, $hash) use ($search, $state) {
if (!$state->is('archives') && !$state->is('tags')) {
Alert::info('Showing %s matched with query %s.', ['posts', '<em>' . $search . '</em>']);
Alert::info('Showing %s matched with query %s.', ['posts', '<b>' . $search . '</b>']);
}
});
}
Expand All @@ -48,9 +48,9 @@
$archive = new Time(substr_replace('1970-01-01-00-00-00', $name, 0, strlen($name)));
$format = (false === strpos($name, '-') ? "" : '%B ') . '%Y';
if ($search) {
Alert::info('Showing %s published in %s and matched with query %s.', ['posts', '<em>' . $archive->i($format) . '</em>', '<em>' . $search . '</em>']);
Alert::info('Showing %s published in %s and matched with query %s.', ['posts', '<b>' . $archive->i($format) . '</b>', '<b>' . $search . '</b>']);
} else {
Alert::info('Showing %s published in %s.', ['posts', '<em>' . $archive->i($format) . '</em>']);
Alert::info('Showing %s published in %s.', ['posts', '<b>' . $archive->i($format) . '</b>']);
}
}
});
Expand All @@ -60,9 +60,9 @@
if (is_file($file = LOT . D . 'tag' . D . $name . '.page')) {
$tag = new Tag($file);
if ($search) {
Alert::info('Showing %s tagged in %s and matched with query %s.', ['posts', '<em>' . $tag->title . '</em>', '<em>' . $search . '</em>']);
Alert::info('Showing %s tagged in %s and matched with query %s.', ['posts', '<b>' . $tag->title . '</b>', '<b>' . $search . '</b>']);
} else {
Alert::info('Showing %s tagged in %s.', ['posts', '<em>' . $tag->title . '</em>']);
Alert::info('Showing %s tagged in %s.', ['posts', '<b>' . $tag->title . '</b>']);
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion widget/archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@

if (isset($state->x->archive)) {
$archives = [];
$deep = 0;
$route_archive = $state->x->archive->route ?? '/archive';
$route_blog = $route ?? $state->routeBlog;
foreach (g(LOT . D . 'page' . $route_blog, 'page') as $k => $v) {
$folder = LOT . D . 'page' . $route_blog;
if ($file = exist([
$folder . '.archive',
$folder . '.page'
], 1)) {
$p = new Page($file);
$deep = $p->deep ?? 0;
}
foreach (g($folder, 'page', $deep) as $k => $v) {
$p = new Page($k);
$v = $p->time;
if ($v) {
Expand Down
12 changes: 11 additions & 1 deletion widget/page.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<?php

$deep = 0;
$folder = LOT . D . 'page' . ($route ?? $state->routeBlog);
if ($file = exist([
$folder . '.archive',
$folder . '.page'
], 1)) {
$page = new Page($file);
$deep = $page->deep ?? 0;
}

$pages = [];
$pages_data = Pages::from(LOT . D . 'page' . ($route ?? $state->routeBlog))->sort([$sort[0] ?? -1, $sort[1] ?? 'time']);
$pages_data = Pages::from($folder, 'page', $deep)->sort([$sort[0] ?? -1, $sort[1] ?? 'time']);

if (!empty($shake)) {
$pages_data->shake();
Expand Down
18 changes: 11 additions & 7 deletions widget/tag.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
<?php

if (isset($state->x->tag)) {
$deep = 0;
$folder = LOT . D . 'page' . ($route ?? $state->routeBlog);
if ($file = exist([
$folder . '.archive',
$folder . '.page'
], 1)) {
$page = new Page($file);
$deep = $page->deep ?? 0;
}
$tags = [];
$tags_found = [];
foreach (g($folder = LOT . D . 'page' . ($route ?? $state->routeBlog), 'page') as $k => $v) {
foreach (g($folder, 'page', $deep) as $k => $v) {
$page = new Page($k);
$v = (array) ($page->kind ?? []);
$v && ($tags_found = array_merge($tags_found, $v));
}
foreach (array_count_values($tags_found) as $k => $v) {
if ($n = To::tag($k)) {
if (is_file($f = LOT . D . 'tag' . D . $n . '.page')) {
$tag = new Tag($f, [
'parent' => exist([
$folder . '.archive',
$folder . '.page'
], 1) ?: null
]);
$tag = new Tag($f, ['parent' => $file ?: null]);
$tags[$tag->link] = $tag->title . ' <span aria-label="' . eat(i('%d post' . (1 === $v ? "" : 's'), [$v])) . '" role="status">' . $v . '</span>';
}
}
Expand Down

0 comments on commit b60ddc3

Please sign in to comment.