|
20 | 20 |
|
21 | 21 | <!-- Featured Image -->
|
22 | 22 | {% if post.large_image_webp or post.large_image_jpeg %}
|
23 |
| - <div class="mb-8"> |
| 23 | + <div class="mb-14"> |
24 | 24 | <picture>
|
25 | 25 | {% if post.large_image_webp %}
|
26 | 26 | <source
|
|
45 | 45 | {% endif %}
|
46 | 46 |
|
47 | 47 | <!-- Blog Header -->
|
48 |
| - <div class="mb-10 text-center"> |
| 48 | + <div class="mb-12 text-center"> |
49 | 49 | <h1 class="text-4xl font-bold tracking-tight text-gray-900 font-display">{{ post.title }}</h1>
|
50 | 50 | <div class="mt-4 text-gray-600">
|
51 | 51 | <span>Published on {{ post.datetime_created|date:"F j, Y" }}</span>
|
@@ -77,3 +77,65 @@ <h2 class="text-2xl font-bold text-gray-900">Comments</h2>
|
77 | 77 | {% endif %}
|
78 | 78 | </div>
|
79 | 79 | {% endblock %}
|
| 80 | + |
| 81 | +{% block js %} |
| 82 | +<script> |
| 83 | + document.addEventListener('DOMContentLoaded', function () { |
| 84 | + const tables = document.querySelectorAll('.prose table'); |
| 85 | + |
| 86 | + tables.forEach(table => { |
| 87 | + const headers = table.querySelectorAll('th'); |
| 88 | + const tbody = table.querySelector('tbody'); |
| 89 | + |
| 90 | + function sortTableByColumn(colIndex, ascending) { |
| 91 | + const rows = Array.from(tbody.querySelectorAll('tr')); |
| 92 | + |
| 93 | + rows.sort((a, b) => { |
| 94 | + const aText = a.children[colIndex].textContent.trim(); |
| 95 | + const bText = b.children[colIndex].textContent.trim(); |
| 96 | + |
| 97 | + const aNum = parseFloat(aText.replace(/[^\d.-]/g, '')); |
| 98 | + const bNum = parseFloat(bText.replace(/[^\d.-]/g, '')); |
| 99 | + const isNumeric = !isNaN(aNum) && !isNaN(bNum); |
| 100 | + |
| 101 | + if (isNumeric) { |
| 102 | + return ascending ? aNum - bNum : bNum - aNum; |
| 103 | + } else { |
| 104 | + return ascending |
| 105 | + ? aText.localeCompare(bText) |
| 106 | + : bText.localeCompare(aText); |
| 107 | + } |
| 108 | + }); |
| 109 | + |
| 110 | + // Clear sort indicators |
| 111 | + headers.forEach((th, i) => { |
| 112 | + th.dataset.sort = ''; |
| 113 | + th.innerHTML = th.textContent.trim(); // remove arrows |
| 114 | + }); |
| 115 | + |
| 116 | + // Update current header |
| 117 | + const arrow = ascending ? ' ↑' : ' ↓'; |
| 118 | + headers[colIndex].dataset.sort = ascending ? 'asc' : 'desc'; |
| 119 | + headers[colIndex].innerHTML = headers[colIndex].textContent.trim() + arrow; |
| 120 | + |
| 121 | + // Reinsert sorted rows |
| 122 | + rows.forEach(row => tbody.appendChild(row)); |
| 123 | + } |
| 124 | + |
| 125 | + // Add click events to headers |
| 126 | + headers.forEach((th, colIndex) => { |
| 127 | + th.style.cursor = 'pointer'; |
| 128 | + th.addEventListener('click', () => { |
| 129 | + const isAsc = th.dataset.sort !== 'asc'; |
| 130 | + sortTableByColumn(colIndex, isAsc); |
| 131 | + }); |
| 132 | + }); |
| 133 | + |
| 134 | + // Automatically sort by first column on load |
| 135 | + if (headers.length > 0) { |
| 136 | + sortTableByColumn(0, true); |
| 137 | + } |
| 138 | + }); |
| 139 | + }); |
| 140 | +</script> |
| 141 | +{% endblock js %} |
0 commit comments