49 lines
1.7 KiB
PHP
49 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
$tagIndex = load_tag_index();
|
|
$originalNames = [];
|
|
$tagCounts = [];
|
|
if ($tagIndex) {
|
|
foreach ($tagIndex as $slug => $entry) {
|
|
$originalNames[$slug] = $entry['name'];
|
|
$tagCounts[$slug] = is_array($entry['posts'] ?? null) ? count($entry['posts']) : count($entry);
|
|
}
|
|
}
|
|
uksort($tagCounts, function (string $a, string $b) use ($originalNames): int {
|
|
return strcasecmp($originalNames[$a] ?? $a, $originalNames[$b] ?? $b);
|
|
});
|
|
$maxCount = $tagCounts ? max($tagCounts) : 1;
|
|
$minCount = $tagCounts ? min($tagCounts) : 1;
|
|
$range = $maxCount > $minCount ? $maxCount - $minCount : 1;
|
|
|
|
$pageTitle = 'Tag Cloud';
|
|
$metaDescription = 'Browse all the tags on my site.';
|
|
|
|
require PUREBLOG_BASE_PATH . '/includes/header.php';
|
|
render_masthead_layout($config, ['page' => null]);
|
|
?>
|
|
<main>
|
|
<h1>Tag Cloud</h1>
|
|
|
|
<?php if (empty($tagCounts)): ?>
|
|
<p>No tags found.</p>
|
|
<?php else: ?>
|
|
<p class="tag-cloud">
|
|
<?php foreach ($tagCounts as $slug => $count):
|
|
$name = $originalNames[$slug] ?? $slug;
|
|
$ratio = ($count - $minCount) / $range;
|
|
$fontSize = round(0.85 + $ratio * 1.4, 2);
|
|
$postWord = $count === 1 ? 'post' : 'posts';
|
|
echo '<a href="/tag/' . e(rawurlencode((string) $slug)) . '"'
|
|
. ' style="font-size: ' . $fontSize . 'em"'
|
|
. ' title="' . e((string) $count) . ' ' . $postWord . '">'
|
|
. e($name) . ' (' . e((string) $count) . ')' . '</a>' . ' ';
|
|
endforeach; ?>
|
|
</p>
|
|
<?php endif; ?>
|
|
</main>
|
|
<?php render_footer_layout($config, ['page' => null]); ?>
|
|
</body>
|
|
</html>
|