4 'januari', 'februari', 'maart', 'april', 'mei', 'juni',
5 'juli', 'augustus', 'september', 'oktober', 'november', 'december',
8 function showdate($parts)
11 return implode(' ', array_filter([
12 intval(@$parts[2]), $parts[1] > 0 ? $monthname[intval($parts[1])] : '', $parts[0],
13 count($parts) > 5 ? "$parts[3]:$parts[4]" : '',
19 public $raw, $preface, $title, $body;
22 function __construct($path)
24 $this->page = preg_replace('{^\.(?:/|$)}', '', $path);
25 $this->link = preg_replace('{(?:/index)?\.html$}', '', $this->page);
26 if (file_exists($this->page)) {
27 $this->raw = file_get_contents($this->page);
30 \G <meta \s+ property="( [^"]+ )" \s+ content="( [^"]* )" > \s*
31 }x', $this->raw, $meta)) {
32 $matchlen = array_sum(array_map('strlen', $meta[0]));
33 $this->raw = substr($this->raw, $matchlen); # delete matched contents
34 $this->meta = array_combine($meta[1], $meta[2]); # [property => content]
37 @list ($this->preface, $this->title, $this->body) =
38 preg_split('{<h2>(.*?)</h2>\s*}s', $this->raw, 2, PREG_SPLIT_DELIM_CAPTURE);
44 return $this->$col = $this->$col(); # run method and cache
49 return trim($this->meta['og:title'] ?? strip_tags($this->title));
53 return $this->safetitle ?: $this->link;
58 return filemtime($this->page);
62 return date(DATE_ATOM, $this->last);
67 preg_match('< / (\d{4}) [/-] (\d{2}) (?:- (\d{2}) )? - >x', $this->page, $ymd);
73 return implode('-', $this->dateparts()) . 'T12:00:00+02:00';
77 return showdate($this->dateparts);
83 \n (?: < (?: p | figure [^>]* ) >\s* )+ (<img\ [^>]*>) | \n <hr\ />
84 }x', $this->body, $img, PREG_OFFSET_CAPTURE) ) {
85 # strip part after matching divider (image)
87 $this->img = $img[1][0];
89 return substr($this->body, 0, $img[0][1]);
96 if ($override = @$this->meta['og:description']) {
97 # prefer specific page description if found in metadata
102 </h2> (?: \s+ | <p\sclass="nav\b.*?</p> | <div[^>]*> )* <p> \s* (.*?) </p>
103 }sx', $this->raw, $bodyp, PREG_OFFSET_CAPTURE)) {
104 # fallback paragraph contents following the page header
105 if ($bodyp[1][1] < 256) {
110 # starting paragraph for documents without title (assumed simple/partial)
111 if (strpos($this->raw, '<h2') === FALSE and preg_match('{
112 \A <p> \s* (.*?) </p>
113 }sx', $this->raw, $bodyp)) {
126 if ($override = @$this->meta['og:image']) {
127 # prefer specific page image if found in metadata
131 if ( preg_match('/\bsrc="([^"]*)"/', $this->img, $src) ) {
135 function thumb($size = '300x')
137 if (!$this->image or $this->image[0] !== '/') return;
139 ['{^(?:/thumb/[^/]*)?}', '/\.groot(?=\.\w+$)/'], ["thumb/$size", ''],
147 function __construct($path = '.')
149 $this->iterator = new RecursiveCallbackFilterIterator(
150 new RecursiveDirectoryIterator($path),
151 function ($current) {
152 if ($current->getFilename()[0] === '.') {
153 # skip hidden files and directories
156 if ($current->isLink()) {
157 # ignore symlinks, original contents only
160 if ($current->isDir()) {
161 # traverse subdirectories unless untracked in any amount
162 return !file_exists("$current/.gitignore");
165 return preg_match('/(?<!\.inc)\.html$/', $current->getFilename());
172 # order alphabetically by link
173 $dir = iterator_to_array(new RecursiveIteratorIterator($this->iterator));
174 array_walk($dir, function (&$row, $name) {
175 # prepare values for sorting (directory index first)
176 $row = preg_replace('{/index\.html$}', '', $name);