Skip to content

Commit 67950dc

Browse files
Blog page update
1 parent 7e217ec commit 67950dc

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

backend/blog/templates/blog/blog_detail.html

+64-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<!-- Featured Image -->
2222
{% if post.large_image_webp or post.large_image_jpeg %}
23-
<div class="mb-8">
23+
<div class="mb-14">
2424
<picture>
2525
{% if post.large_image_webp %}
2626
<source
@@ -45,7 +45,7 @@
4545
{% endif %}
4646

4747
<!-- Blog Header -->
48-
<div class="mb-10 text-center">
48+
<div class="mb-12 text-center">
4949
<h1 class="text-4xl font-bold tracking-tight text-gray-900 font-display">{{ post.title }}</h1>
5050
<div class="mt-4 text-gray-600">
5151
<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>
7777
{% endif %}
7878
</div>
7979
{% 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

Comments
 (0)