flash.moe/pages/projects.php

127 lines
4.4 KiB
PHP
Raw Normal View History

2020-07-30 00:55:37 +00:00
<?php
2022-02-04 20:30:52 +00:00
namespace Makai;
2022-02-05 03:35:42 +00:00
$router->get('/projects.php', mkiRedirect('/projects'));
$router->get('/projects.html', mkiRedirect('/projects'));
$router->get('/utilities', mkiRedirect('/projects'));
$router->get('/utilities.php', mkiRedirect('/projects'));
$router->get('/utilities.html', mkiRedirect('/projects'));
2020-07-30 00:55:37 +00:00
2022-02-05 03:35:42 +00:00
$router->get('/projects', function() use ($db) {
$projects = (new Projects($db))->getAll();
$languages = new Languages($db);
$sections = [
'projects' => [
2020-07-30 00:55:37 +00:00
'title' => 'Active Projects',
'desc' => 'Projects that I work on on a fairly regular basis.',
2022-02-05 03:35:42 +00:00
'items' => [],
2020-07-30 00:55:37 +00:00
],
2022-02-05 03:35:42 +00:00
'tools' => [
2020-07-30 00:55:37 +00:00
'title' => 'Tools',
'desc' => 'Personal quality of life tools that I update when I need something new from them.',
2022-02-05 03:35:42 +00:00
'items' => [],
2020-07-30 00:55:37 +00:00
],
2022-02-05 03:35:42 +00:00
'archives' => [
2020-07-30 00:55:37 +00:00
'title' => 'Archived Projects',
'desc' => 'Past projects that I no longer work on.',
2022-02-05 03:35:42 +00:00
'items' => [],
2020-07-30 00:55:37 +00:00
],
];
2022-02-05 03:35:42 +00:00
foreach($projects as $project) {
if($project->isArchived())
$sections['archives']['items'][] = $project;
else {
if($project->isTool())
$sections['tools']['items'][] = $project;
else
$sections['projects']['items'][] = $project;
}
}
$body = fm_component('header', [
'title' => 'flash.moe / projects',
]);
foreach($sections as $sectionId => $section) {
$body .= <<<HTML
<div class="section" id="section-{$sectionId}">
<div class="section-content">
<div class="section-background"></div>
<h1>{$section['title']}</h1>
<p>{$section['desc']}</p>
2020-07-30 00:55:37 +00:00
</div>
2022-02-05 03:35:42 +00:00
</div>
HTML;
foreach($section['items'] as $project) {
$links = [];
if($project->hasHomePageUrl())
$links[] = ['class' => 'homepage', 'text' => 'Homepage', 'url' => $project->getHomePageUrl()];
if($project->hasSourceUrl())
$links[] = ['class' => 'repository', 'text' => 'Source', 'url' => $project->getSourceUrl()];
if($project->hasDiscussionUrl())
$links[] = ['class' => 'forum', 'text' => 'Discussion', 'url' => $project->getDiscussionUrl()];
$descLines = $project->hasDescription() ? $project->getDescription()->trim()->split("\n") : [];
$langs = $languages->getByProject($project);
if($project->hasColour())
$colour = $project->getColour();
else
foreach($langs as $lang)
if($lang->hasColour()) {
$colour = $lang->getColour();
break;
}
$colour = str_pad(dechex($colour), 6, '0', STR_PAD_LEFT);
$body .= <<<HTML
<div class="project project-type-{$sectionId}" id="{$project->getCleanName()}" style="--project-colour: #{$colour};">
2020-07-30 00:55:37 +00:00
<div class="project-content">
<div class="project-details">
2022-02-05 03:35:42 +00:00
<h2>{$project->getName()}<div class="project-languages">
HTML;
foreach($langs as $lang) {
$langColour = str_pad(dechex($lang->getColour() ?? 0), 6, '0', STR_PAD_LEFT);
$body .= "<div class=\"project-language\" style=\"--language-colour: #{$langColour};\">{$lang->getName()}</div>";
}
$body .= '</div></h2>';
if($project->hasSummary())
$body .= "<p class=\"project-details-summary\">{$project->getSummary()}</p>";
foreach($descLines as $line) {
$line = $line->trim();
if($line->isEmpty())
continue;
$body .= "<p>{$line}</p>";
}
$body .= '</div>';
if(!empty($links)) {
$body .= '<div class="project-links">';
foreach($links as $link)
$body .= "<a class=\"project-link project-link-{$link['class']}\" href=\"{$link['url']}\" rel=\"noopener\" target=\"_blank\">{$link['text']}</a>";
$body .= '</div>';
}
$body .= '</div></div>';
}
}
2020-07-30 00:55:37 +00:00
2022-02-05 03:35:42 +00:00
$body .= fm_component('footer');
2020-07-30 00:55:37 +00:00
2022-02-05 03:35:42 +00:00
return $body;
});