{{ post['title'] }}
+{{ post['title'] }}
{{ post['body']|safe }}
+{{ post['body'] }}
diff --git a/flaskr/static/collapse.js b/flaskr/static/collapse.js new file mode 100644 index 00000000..ea8145cd --- /dev/null +++ b/flaskr/static/collapse.js @@ -0,0 +1,24 @@ +document.addEventListener("DOMContentLoaded", function() { + const toggleAllButton = document.getElementById("toggle-all"); + const postHeaders = document.querySelectorAll(".post-header"); + const posts = document.querySelectorAll(".post"); + + toggleAllButton.addEventListener("click", function() { + posts.forEach(post => { + post.classList.toggle("collapsed"); + }); + }); + + postHeaders.forEach(header => { + header.addEventListener("click", function(event) { + const postId = event.currentTarget.getAttribute("onclick").match(/\d+/)[0]; + togglePostBody(postId); + }); + }); +}); + +function togglePostBody(postId) { + const postBody = document.getElementById(`post-body-${postId}`); + const post = postBody.closest(".post"); + post.classList.toggle("collapsed"); +} diff --git a/flaskr/static/style.css b/flaskr/static/style.css index 76254cb3..f1205f3f 100644 --- a/flaskr/static/style.css +++ b/flaskr/static/style.css @@ -88,6 +88,7 @@ nav ul li a, nav ul li span, header .action { display: flex; align-items: flex-end; font-size: 0.85em; + cursor: pointer; } .post > header > div:first-of-type { @@ -106,6 +107,7 @@ nav ul li a, nav ul li span, header .action { .post .body { white-space: pre-line; + display: block; } .content:last-child { @@ -249,3 +251,7 @@ body.dark-mode .editor-toolbar { body.dark-mode .CodeMirror { border: 1px solid #555; } + +.post.collapsed .body { + display: none; +} diff --git a/flaskr/templates/blog/index.html b/flaskr/templates/blog/index.html index f18d614f..f257bec6 100644 --- a/flaskr/templates/blog/index.html +++ b/flaskr/templates/blog/index.html @@ -1,7 +1,7 @@ {% extends 'base.html' %} {% block header %} -
{{ post['body']|safe }}
+{{ post['body'] }}