summaryrefslogtreecommitdiff
path: root/src/web/_model/projects.php
blob: 5373a782fb0ac42046246e4da09e0b559b3078f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php /* Copyright (c) 2024 Freya Murphy */
class Projects_model extends Model {

	private $markdown;

	function __construct($load) {
		parent::__construct($load);
		$this->markdown = new MarkdownParser();
	}

	private function load_projects(&$data) {
		$projects = array();
		$dir = $GLOBALS['assetroot'] . '/projects';
		if ($handle = opendir($dir)) {
			while (false !== ($entry = readdir($handle))) {
				if (str_starts_with($entry, ".")) {
					continue;
				}
				$path = $dir . '/' . $entry;
				$md = $this->markdown->parse($path);
				$projects[$entry] = $md;
			}
		}
		krsort($projects);
		$data['projects'] = $projects;
	}

	public function get_data(): ?array {
		$data = parent::get_data();
		$this->load_projects($data);
		$data['title'] = lang('title');
		$data['desc'] = lang('short_desc');
		return $data;
	}
}
?>