Controllers+Views: Move tag splitting logic to controller

This commit is contained in:
Riyyi
2022-12-03 13:02:28 +01:00
parent 0138a14c29
commit f7c6276a7a
2 changed files with 14 additions and 9 deletions
+13 -2
View File
@@ -54,9 +54,20 @@ class BlogController extends PageController {
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()
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;
};
}