Controllers+Views: Move tag splitting logic to controller
This commit is contained in:
@@ -54,9 +54,20 @@ class BlogController extends PageController {
|
|||||||
return "<u class=\"text-decoration-none text-reset\" title=\"{$timestamp}\">{$date}</u>";
|
return "<u class=\"text-decoration-none text-reset\" title=\"{$timestamp}\">{$date}</u>";
|
||||||
};
|
};
|
||||||
|
|
||||||
$this->router->service()->tags = function (string $tags): array {
|
$this->router->service()->tags = function (string $tags): string {
|
||||||
|
$result = "";
|
||||||
|
|
||||||
// Remove empty elements via array_filter()
|
// Remove empty elements via array_filter()
|
||||||
return array_filter(explode(':', $tags));
|
$splitTags = array_filter(explode(':', $tags), function ($tag) {
|
||||||
|
return !empty(trim($tag));
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach ($splitTags as $key => $tag) {
|
||||||
|
$result .= $tag;
|
||||||
|
$result .= (($key === array_key_last($splitTags)) ? '' : ', ');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,13 +15,7 @@
|
|||||||
</p>
|
</p>
|
||||||
<?php if (_exists($post, 'tag')) { ?>
|
<?php if (_exists($post, 'tag')) { ?>
|
||||||
<small>
|
<small>
|
||||||
<i>
|
<i>tags: <?= ($this->tags)($post['tag']); ?></i>
|
||||||
tags:
|
|
||||||
<?php $tags = ($this->tags)($post['tag']); ?>
|
|
||||||
<?php foreach ($tags as $key => $tag) { ?>
|
|
||||||
<?= $tag . (($key === array_key_last($tags)) ? '' : ', '); ?>
|
|
||||||
<?php } ?>
|
|
||||||
</i>
|
|
||||||
</small>
|
</small>
|
||||||
<div class="d-md-none mb-3"></div>
|
<div class="d-md-none mb-3"></div>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|||||||
Reference in New Issue
Block a user