map('GET', '/', function() {}, 'home'); $router->map('GET', '/rss', function() {}, 'rss'); $router->map('GET', '/rss.xml', function() {}, 'rss-xml'); $router->map('GET', '/rss/all', function() {}, 'rss-all'); $router->map('GET', '/rss/blog', function() {}, 'rss-blog'); $router->map('GET', '/rss/notes', function() {}, 'rss-notes'); $router->map('GET', '/blog', function() {}, 'blog'); $router->map('GET', '/blog/[*:slug]', function() {}, 'blog_post'); $router->map('GET', '/notes', function() {}, 'notes'); $router->map('GET', '/notes/[*:slug]', function() {}, 'notes_post'); $router->map('GET', '/projects', function() {}, 'projects'); $router->map('GET', '/projects/[*:slug]', function() {}, 'projects_details'); $router->map('GET', '/foss', function() {}, 'foss'); $router->map('GET', '/vinyl', function() {}, 'vinyl'); $router->map('GET', '/pgp', function() {}, 'pgp'); $router->map('GET', '/contact', function() {}, 'contact'); // Router matching $match = $router->match(); // Template engine settings and variables $environment = getenv('ENVIRONMENT') ?: 'production'; $options = [ 'paths' => [ 'views/', ], 'cache_dir' => 'cache/', 'enable_profiler' => false, 'profiler' => [ 'time_precision' => 3, 'line_height' => 30, 'display' => true, 'log' => false, ], ]; $variables = [ 'title' => 'Yarmo Mackenbach' ]; // If we are dealing with the home page if ($match['name'] == 'home') { $variables['icons'] = getIcons(); } // If we are dealing with the rss feed if ($match['name'] == 'rss' || $match['name'] == 'rss-all' || $match['name'] == 'rss-xml') { $blogposts = getBlogPosts($variables['params']); $notes = getNotes($variables['params']); $variables['posts'] = array_merge($blogposts, $notes); $variables['feed']['title'] = "Yarmo's blog and notes"; $variables['feed']['description'] = "Blog and notes feed for yarmo.eu discussing homelab and selfhosted stuff"; $variables['feed']['url'] = "https://yarmo.eu"; $variables['feed']['linkself'] = "https://yarmo.eu/rss/all"; } // If we are dealing with the blog rss feed if ($match['name'] == 'rss-blog') { $variables['posts'] = getBlogPosts($variables['params']); $variables['feed']['title'] = "Yarmo's blog"; $variables['feed']['description'] = "Blog feed for yarmo.eu discussing homelab and selfhosted stuff"; $variables['feed']['url'] = "https://yarmo.eu/blog"; $variables['feed']['linkself'] = "https://yarmo.eu/rss/blog"; } // If we are dealing with the notes rss feed if ($match['name'] == 'rss-notes') { $variables['posts'] = getNotes($variables['params']); $variables['feed']['title'] = "Yarmo's blog"; $variables['feed']['description'] = "Notes feed for yarmo.eu discussing homelab and selfhosted stuff"; $variables['feed']['url'] = "https://yarmo.eu/notes"; $variables['feed']['linkself'] = "https://yarmo.eu/rss/notes"; } // If we are dealing with the blog if ($match['name'] == 'blog') { $variables['posts'] = getBlogPosts($variables['params']); $variables['title'] = 'Blog — Yarmo Mackenbach'; } // If we are dealing with a blog post if ($match['name'] == 'blog_post') { $variables['params']['slug'] = $match['params']['slug']; $variables['post'] = getBlogPosts($variables['params']); $variables['post'] = $variables['post'][0]; $variables['title'] = htmlspecialchars_decode(str_replace('·','·',$variables['post']['title'])).' — Yarmo Mackenbach'; } // If we are dealing with the notes if ($match['name'] == 'notes') { $variables['posts'] = getNotes($variables['params']); $variables['title'] = 'Notes — Yarmo Mackenbach'; } // If we are dealing with a notes post if ($match['name'] == 'notes_post') { $variables['params']['slug'] = $match['params']['slug']; $variables['post'] = getNotes($variables['params']); $variables['post'] = $variables['post'][0]; $variables['title'] = htmlspecialchars_decode(str_replace('·','·',$variables['post']['title'])).' — Yarmo Mackenbach'; } // If we are dealing with the projects if ($match['name'] == 'projects') { $variables['projects'] = getProjects($variables['params']); $variables['title'] = 'Projects — Yarmo Mackenbach'; } // If we are dealing with a project's details if ($match['name'] == 'projects_details') { $variables['params']['slug'] = $match['params']['slug']; $variables['project'] = getProjects($variables['params']); $variables['project'] = $variables['project'][0]; $variables['title'] = htmlspecialchars_decode(str_replace('·','·',$variables['project']['title'])).' — Yarmo Mackenbach'; } // If we are dealing with foss if ($match['name'] == 'foss') { $variables['foss'] = getFOSS(); $variables['title'] = 'FOSS — Yarmo Mackenbach'; } // If we are dealing with vinyl if ($match['name'] == 'vinyl') { $variables['vinyl'] = getVinyl(); $variables['albums'] = $variables['vinyl']['albums']; $variables['title'] = 'Vinyl — Yarmo Mackenbach'; } // If we are dealing with the pgp page if ($match['name'] == 'pgp') { $variables['title'] = 'PGP — Yarmo Mackenbach'; } // If we are dealing with the contact page if ($match['name'] == 'contact') { $variables['title'] = 'Contact me — Yarmo Mackenbach'; } // Add Phug dyninclude Phug::addKeyword('dyninclude', function ($args) { return array( 'beginPhp' => 'echo file_get_contents(' . $args . ');', ); }); // PRODUCTION // Render the appropriate route if ($environment === 'production') { if(is_array($match) && is_callable($match['target'])) { switch ($match['name']) { case 'home': // Phug optimizer \Phug\Optimizer::call('displayFile', ['index', $variables], $options); // Phug::displayFile('index', $variables, $options); break; case 'rss': case 'rss-xml': case 'rss-all': case 'rss-blog': case 'rss-notes': getRSS($variables); break; case 'blog': \Phug\Optimizer::call('displayFile', ['blog', $variables], $options); break; case 'blog_post': \Phug\Optimizer::call('displayFile', ['blog_post', $variables], $options); break; case 'notes': \Phug\Optimizer::call('displayFile', ['notes', $variables], $options); break; case 'notes_post': \Phug\Optimizer::call('displayFile', ['notes_post', $variables], $options); break; case 'projects': \Phug\Optimizer::call('displayFile', ['projects', $variables], $options); break; case 'projects_details': \Phug\Optimizer::call('displayFile', ['projects_details', $variables], $options); break; case 'foss': \Phug\Optimizer::call('displayFile', ['foss', $variables], $options); break; case 'vinyl': \Phug\Optimizer::call('displayFile', ['vinyl', $variables], $options); break; case 'contact': \Phug\Optimizer::call('displayFile', ['contact', $variables], $options); break; case 'pgp': \Phug\Optimizer::call('displayFile', ['pgp', $variables], $options); break; default: \Phug\Optimizer::call('displayFile', ['404', $variables], $options); break; } } else { // No route was matched \Phug\Optimizer::call('displayFile', ['404', $variables], $options); } exit; } # DEVELOPMENT // Render the appropriate route if(is_array($match) && is_callable($match['target'])) { switch ($match['name']) { case 'home': Phug::displayFile('index', $variables, $options); break; case 'rss': case 'rss-xml': case 'rss-all': case 'rss-blog': case 'rss-notes': getRSS($variables); break; case 'blog': Phug::displayFile('blog', $variables, $options); break; case 'blog_post': Phug::displayFile('blog_post', $variables, $options); break; case 'notes': Phug::displayFile('notes', $variables, $options); break; case 'notes_post': Phug::displayFile('notes_post', $variables, $options); break; case 'projects': Phug::displayFile('projects', $variables, $options); break; case 'projects_details': Phug::displayFile('projects_details', $variables, $options); break; case 'foss': Phug::displayFile('foss', $variables, $options); break; case 'vinyl': Phug::displayFile('vinyl', $variables, $options); break; case 'contact': Phug::displayFile('contact', $variables, $options); break; case 'pgp': Phug::displayFile('pgp', $variables, $options); break; default: Phug::displayFile('404', $variables, $options); break; } } else { // No route was matched Phug::displayFile('404', $variables, $options); }