feat(*): refactor dynamic vs. static structure and distinctions; make additional elements dynamic

This commit is contained in:
Cory Dransfeldt 2025-06-13 16:31:36 -07:00
parent 7a0b808f24
commit eaab389cb9
No known key found for this signature in database
136 changed files with 984 additions and 960 deletions

View file

@ -0,0 +1,25 @@
<?php
require_once __DIR__ . '/../../bootstrap.php';
use App\Classes\ArtistFetcher;
$requestUri = $_SERVER["REQUEST_URI"];
$url = trim(parse_url($requestUri, PHP_URL_PATH), "/");
if (strpos($url, "music/artists/") !== 0) redirectTo404();
$fetcher = new ArtistFetcher();
$artist = $fetcher->fetch($url);
if (!$artist) redirectTo404();
$artist["description_html"] = parseMarkdown($artist["description"]);
$artist["globals"] = $fetcher->getGlobals();
$page = $artist;
extract(setupPageMetadata($page, $requestUri));
header("Cache-Control: public, max-age=3600");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
?>

View file

@ -0,0 +1,26 @@
<?php
require_once __DIR__ . '/../../bootstrap.php';
use App\Classes\BookFetcher;
$requestUri = $_SERVER["REQUEST_URI"];
$url = trim(parse_url($requestUri, PHP_URL_PATH), "/");
if (!preg_match('/^reading\/books\/([\dXx-]+)$/', $url)) redirectTo404();
$fetcher = new BookFetcher();
$book = $fetcher->fetch($url);
if (!$book) redirectTo404();
$book["description_html"] = parseMarkdown($book["description"]);
$book["globals"] = $fetcher->getGlobals();
$page = $book;
$globals = $page["globals"];
extract(setupPageMetadata($page, $requestUri));
header("Cache-Control: public, max-age=3600");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
?>

View file

@ -0,0 +1,25 @@
<?php
require_once __DIR__ . '/../../bootstrap.php';
use App\Classes\GenreFetcher;
$requestUri = $_SERVER["REQUEST_URI"];
$url = trim(parse_url($requestUri, PHP_URL_PATH), "/");
if (!preg_match('/^music\/genres\/[\w-]+$/', $url)) redirectTo404();
$fetcher = new GenreFetcher();
$genre = $fetcher->fetch($url);
if (!$genre) redirectTo404();
$genre["globals"] = $fetcher->getGlobals();
$page = $genre;
$globals = $page["globals"];
extract(setupPageMetadata($page, $requestUri));
header("Cache-Control: public, max-age=3600");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
?>

View file

@ -0,0 +1,26 @@
<?php
require_once __DIR__ . '/../../bootstrap.php';
use App\Classes\MovieFetcher;
$requestUri = $_SERVER["REQUEST_URI"];
$url = trim(parse_url($requestUri, PHP_URL_PATH), "/");
if (!preg_match('/^watching\/movies\/[\w-]+$/', $url)) redirectTo404();
$fetcher = new MovieFetcher();
$movie = $fetcher->fetch($url);
if (!$movie) redirectTo404();
$movie["description_html"] = parseMarkdown($movie["description"]);
$movie["globals"] = $fetcher->getGlobals();
$page = $movie;
$globals = $page["globals"];
extract(setupPageMetadata($page, $requestUri));
header("Cache-Control: public, max-age=3600");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
?>

View file

@ -0,0 +1,26 @@
<?php
require_once __DIR__ . '/../../bootstrap.php';
use App\Classes\ShowFetcher;
$requestUri = $_SERVER["REQUEST_URI"];
$url = trim(parse_url($requestUri, PHP_URL_PATH), "/");
if (!preg_match('/^watching\/shows\/[\w-]+$/', $url)) redirectTo404();
$fetcher = new ShowFetcher();
$show = $fetcher->fetch($url);
if (!$show) redirectTo404();
$show["description_html"] = parseMarkdown($show["description"]);
$show["globals"] = $fetcher->getGlobals();
$page = $show;
$globals = $page["globals"];
extract(setupPageMetadata($page, $requestUri));
header("Cache-Control: public, max-age=3600");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
?>

View file

@ -0,0 +1,68 @@
<?php
require __DIR__ . "/../../vendor/autoload.php";
require __DIR__ . "/../../config/dynamic/init.php";
use App\Classes\TagFetcher;
use App\Classes\GlobalsFetcher;
$requestUri = $_SERVER["REQUEST_URI"];
$url = trim(parse_url($requestUri, PHP_URL_PATH), "/");
if ($url === "tags") {
readfile("index.html");
exit();
}
if (!preg_match('/^tags\/(.+?)(?:\/(\d+))?$/', $url, $matches)) redirectTo404();
if (isset($matches[2]) && (int)$matches[2] === 1) {
header("Location: /tags/{$matches[1]}", true, 301);
exit();
}
$tag = strtolower(urldecode($matches[1]));
if (!preg_match('/^[\p{L}\p{N} _\.\-\&]+$/u', $tag)) redirectTo404();
$pageNum = isset($matches[2]) ? max(1, (int)$matches[2]) : 1;
$pageSize = 20;
$fetcher = new TagFetcher();
$tagged = $fetcher->fetch($tag, $pageNum, $pageSize);
if (!$tagged || count($tagged) === 0) {
header("Location: /404/", true, 302);
exit();
}
$totalCount = $tagged[0]['total_count'] ?? 0;
$totalPages = max(ceil($totalCount / $pageSize), 1);
$pagination = [
'pageNumber' => $pageNum,
'pages' => range(1, $totalPages),
'href' => [
'previous' => $pageNum > 1 ? "/tags/{$tag}/" . ($pageNum - 1) : null,
'next' => $pageNum < $totalPages ? "/tags/{$tag}/" . ($pageNum + 1) : null
],
'links' => range(1, $totalPages)
];
$globals = (new GlobalsFetcher())->fetch();
$page = [
'tag' => $tag,
'items' => $tagged,
'pagination' => $pagination,
'metadata' => [
'title' => '#' . ucfirst($tag) . ' • ' . $globals['site_name'],
'description' => 'All content tagged with #' . ucfirst($tag) . '.',
'open_graph_image' => $globals['metadata']['open_graph_image'],
'url' => $globals['url'] . $requestUri,
'type' => 'tag'
],
'globals' => $globals
];
extract(setupPageMetadata($page, $requestUri));
header("Cache-Control: public, max-age=3600");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
?>

View file

@ -0,0 +1,15 @@
<?php
use App\Classes\LatestListenHandler;
$handler = new LatestListenHandler();
$data = $handler->getLatestListen();
if (!empty($data['content'])):
?>
<p class="now-playing">
<mark>Now playing</mark>&puncsp;
<span class="content"><?= $data['content'] ?></span>
</p>
<?php endif; ?>

View file

@ -0,0 +1,15 @@
<?php
use App\Classes\RecentMediaHandler;
$handler = new RecentMediaHandler();
$media = $handler->getRecentMedia();
if (!empty($media['recentMusic'])) echo renderMediaGrid($media['recentMusic'], 0, 'eager');
if (!empty($media['recentWatchedRead'])) echo renderMediaGrid($media['recentWatchedRead'], 0, 'eager');
?>
{% render "static/blocks/banners/rss.liquid",
url:"/feeds",
text:"Subscribe to my posts, movies, books, links or activity feed(s)"
%}

View file

@ -0,0 +1,41 @@
<?php if (!empty($music['recent_tracks'])): ?>
<div class="music-chart">
<?php foreach (array_slice($music['recent_tracks'], 0, 10) as $item): ?>
<?php $chart = $item['chart'] ?? []; ?>
<div class="chart-item">
<div class="meta">
<a href="<?= htmlspecialchars($chart['url'] ?? '#') ?>">
<img
srcset="
<?= htmlspecialchars($chart['image']) ?>?class=w50&type=webp 50w,
<?= htmlspecialchars($chart['image']) ?>?class=w100&type=webp 100w
"
sizes="(max-width: 450px) 50px, 100px"
src="<?= htmlspecialchars($chart['image']) ?>?class=w50&type=webp"
alt="<?= htmlspecialchars($chart['alt'] ?? '') ?>"
loading="lazy"
decoding="async"
width="64"
height="64"
>
</a>
<div class="meta-text">
<a class="title" href="<?= htmlspecialchars($chart['url'] ?? '#') ?>">
<?= htmlspecialchars($chart['title'] ?? '') ?>
</a>
<span class="subheader"><?= htmlspecialchars($chart['subtext'] ?? '') ?></span>
</div>
</div>
<?php if (!empty($chart['played_at'])): ?>
<?php
$timestamp = (int) $chart['played_at'];
$playedAt = (new DateTime("@$timestamp"))->setTimezone(new DateTimeZone('America/Los_Angeles'));
?>
<time datetime="<?= $playedAt->format('c') ?>">
<?= $playedAt->format('F j, g:ia') ?>
</time>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>

View file

@ -0,0 +1,16 @@
<title><?= cleanMeta($page['metadata']['title']) ?></title>
<meta name="description" content="<?= cleanMeta($page['metadata']['description']) ?>" />
<meta property="og:title" content="<?= cleanMeta($page['metadata']['title']) ?>" />
<meta property="og:description" content="<?= cleanMeta($page['metadata']['description']) ?>" />
<meta property="og:image" content="<?= cleanMeta($globals['url'] . '/og/w800' . $page['metadata']['open_graph_image']) ?>" />
<meta property="og:url" content="<?= cleanMeta($page['metadata']['url'] ?? $fullUrl) ?>" />
<link rel="alternate" type="application/json+oembed" href="<?= cleanMeta($oembedUrl) ?>" title="<?= cleanMeta($page['metadata']['title']) ?>">
<link rel="canonical" href="<?= cleanMeta($page['metadata']['url'] ?? $fullUrl) ?>" />
<?php if (!empty($pagination)): ?>
<?php if (!empty($pagination['href']['next'])): ?>
<link rel="next" href="<?= cleanMeta($pagination['href']['next']) ?>">
<?php endif; ?>
<?php if (!empty($pagination['href']['previous'])): ?>
<link rel="prev" href="<?= cleanMeta($pagination['href']['previous']) ?>">
<?php endif; ?>
<?php endif; ?>