From: Ben Sherratt Date: Sat, 27 Dec 2025 11:15:55 +0000 (+0000) Subject: Added category support X-Git-Url: https://git.bts.cx/garden.git/commitdiff_plain/cfc60d8f609562a48f36be4cadfb1e238a434500?ds=inline Added category support --- diff --git a/garden/garden.php b/garden/garden.php index ada43bb..210ab58 100644 --- a/garden/garden.php +++ b/garden/garden.php @@ -92,16 +92,18 @@ class GardenItem { public $type; public $id; public $title; + public $category; public $url; public $date; public $source_filename; public $target_filename; - public function __construct($path, $type, $id, $title, $url, $date, $source_filename, $target_filename) { + public function __construct($path, $type, $id, $title, $category, $url, $date, $source_filename, $target_filename) { $this->path = $path; $this->type = $type; $this->id = $id; $this->title = $title; + $this->category = $category; $this->url = $url; $this->date = $date; $this->source_filename = $source_filename; @@ -146,12 +148,15 @@ function garden_make_process_items($output_directory, $content_paths) { $target_basename .= '.' . $target_extension; } + $category_components = explode(DIRECTORY_SEPARATOR, $item->path); + $category = count($category_components) >= 2 ? $category_components[1] : ""; + $url = GARDEN_SITE_BASE_URL . garden_url($item->path, $target_basename); $target_path = garden_path($output_directory, garden_url($item->path, $target_basename)); $date = filemtime($item->full_path); - $output_items[] = new GardenItem($item, $type, $id, $item->filename, $url, $date, $item->full_path, $target_path); + $output_items[] = new GardenItem($item, $type, $id, $item->filename, $category, $url, $date, $item->full_path, $target_path); } return $output_items; @@ -467,6 +472,18 @@ class GardenExtendedParsedown extends Parsedown { function garden_generate_html($output_directory, $content_items) { $output_items = []; + $categorised_items = []; + foreach ($content_items as $item) { + if ($item->type != GardenItemType::Article) { + continue; + } + + if (isset($categorised_items[$item->category]) == false) { + $categorised_items[$item->category] = []; + } + $categorised_items[$item->category][] = $item; + } + foreach ($content_items as $item) { if ($item->type != GardenItemType::Article) { continue; @@ -481,7 +498,7 @@ function garden_generate_html($output_directory, $content_items) { array_push($output_items, ...$parsedown->post_process_items); } - $html_data = garden_template_render('article', [ 'article' => $item, 'article_content' => $markdown_html ]); + $html_data = garden_template_render('article', [ 'article' => $item, 'article_content' => $markdown_html, 'categorised_items' => $categorised_items ]); garden_write_file($item->target_filename, $html_data); } diff --git a/templates/base.php b/templates/base.php index 95cd625..0a72302 100644 --- a/templates/base.php +++ b/templates/base.php @@ -17,6 +17,27 @@

Find me @btsherratt or on itch.io

+ +