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;
$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;
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;
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);
}
<p>Find me <a href="https://mastodon.gamedev.place/@btsherratt" rel="me">@btsherratt</a> or on <a href="https://bts.itch.io/">itch.io</a></p>
</header>
+ <nav>
+ <ul>
+ <?php foreach($categorised_items as $category_name => $category_items): ?>
+ <?php if ($category_name != ''): ?>
+ <li>
+ <?= $category_name ?>
+ <ul>
+ <?php foreach($category_items as $category_item): ?>
+ <li><a href="<?= $category_item->url ?>"><?= $category_item->title ?></a></li>
+ <?php endforeach; ?>
+ </ul>
+ </li>
+ <?php else: ?>
+ <?php foreach($category_items as $category_item): ?>
+ <li><a href="<?= $category_item->url ?>"><?= $category_item->title ?></a></li>
+ <?php endforeach; ?>
+ <?php endif ?>
+ <?php endforeach ?>
+ </ul>
+ </nav>
+
<?= garden_template_content(); ?>
<footer>