44 lines
1.6 KiB
PHP
44 lines
1.6 KiB
PHP
<?php
|
|
$description = 'Welcome in. Make yourself at home.';
|
|
$gif_files = glob($_SERVER['DOCUMENT_ROOT'] . '/assets/gifs/*.gif');
|
|
$gifs = array_map(fn($f) => '/assets/gifs/' . basename($f), $gif_files);
|
|
$default = !empty($gifs) ? $gifs[array_rand($gifs)] : ''; // random gif, server-side, no JS
|
|
|
|
$quotes = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/assets/data/quotes.json'), true)['quotes'] ?? [];
|
|
$quote = !empty($quotes) ? $quotes[array_rand($quotes)] : 'Welcome in.'; // random quote, no JS
|
|
|
|
include $_SERVER['DOCUMENT_ROOT'] . '/includes/head.php';
|
|
?>
|
|
<body>
|
|
<?php include $_SERVER['DOCUMENT_ROOT'] . '/includes/nav.php'; ?>
|
|
|
|
<main class="home">
|
|
<div id="gif-frame">
|
|
<img id="main-gif" src="<?= htmlspecialchars($default) ?>" alt="">
|
|
</div>
|
|
<p class="home-tagline"><?= htmlspecialchars($quote) ?></p>
|
|
</main>
|
|
|
|
<script>
|
|
// scale the gif so its longer side hits a target — small gifs scale up, large scale down, frame hugs
|
|
(function () {
|
|
var img = document.getElementById('' +
|
|
'main-gif');
|
|
if (!img) return;
|
|
function size() {
|
|
if (!img.naturalWidth) return;
|
|
var factor = window.innerWidth < 640 ? 0.72 : 0.46;
|
|
var target = Math.min(window.innerWidth, window.innerHeight) * factor;
|
|
var scale = target / Math.max(img.naturalWidth, img.naturalHeight);
|
|
img.style.width = Math.round(img.naturalWidth * scale) + 'px';
|
|
img.style.height = Math.round(img.naturalHeight * scale) + 'px';
|
|
}
|
|
img.addEventListener('load', size);
|
|
if (img.complete && img.naturalWidth) size();
|
|
window.addEventListener('resize', size);
|
|
})();
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|