summaryrefslogtreecommitdiff
path: root/public/index.php
blob: 2a9ccb7291f43603e786b040efdb76d2e8c215ba (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
<?php

declare(strict_types=1);

use DTS\BookmarkRepository;
use DTS\Template;
use function DTS\Functions\respondAndExit;

require_once(__DIR__.'/../autoload.php');

$config = require_once(__DIR__.'/../config.php');

$bookmarks = new BookmarkRepository($config['path_to_repository']);

$template = new Template($config['path_to_templates']);

$sort = $_GET['sort'] ?? null;

$tag = $_GET['tag'] ?? null;

$bookmarks->load();

if ($tag !== null) {
    $bookmarks->filter($tag);
}

$bookmarks->sort($sort === 'asc');

$html = $template->render('index', compact('bookmarks'));

respondAndExit(200, 'OK', $html);