aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby <[email protected]>2022-12-29 05:03:17 -0500
committerBobby <[email protected]>2022-12-29 05:03:17 -0500
commita0f9aed243c8825500d4cec17b03fcec398bd1cc (patch)
tree14c1eef4527861795a6271e80a25d5f5ec106440
parent7cd45bf7c332fcbee6c3c19e673e43c219a9564b (diff)
downloadthatcomputerscientist-a0f9aed243c8825500d4cec17b03fcec398bd1cc.tar.xz
thatcomputerscientist-a0f9aed243c8825500d4cec17b03fcec398bd1cc.zip
Updates to home page
-rw-r--r--blog/context_processors.py14
-rw-r--r--templates/blog/home.html8
2 files changed, 16 insertions, 6 deletions
diff --git a/blog/context_processors.py b/blog/context_processors.py
index 5f8ef8c4..00d4323d 100644
--- a/blog/context_processors.py
+++ b/blog/context_processors.py
@@ -5,7 +5,19 @@ from django.conf import settings
def recent_posts():
recent_posts = Post.objects.filter(is_public=True).order_by('-date')[:5]
for post in recent_posts:
- post.excerpt = post.body.split('>')[1].split('<')[0]
+ from bs4 import BeautifulSoup
+ soup = BeautifulSoup(post.body, 'html.parser')
+
+ # Create excerpt, count min 1000 characters and max upto next paragraph
+ excerpt = ''
+ for paragraph in soup.find_all('p'):
+ excerpt += str(paragraph)
+
+ if len(excerpt) >= 1000:
+ break
+ post.excerpt = excerpt
+
+
post.num_comments = Comment.objects.filter(post=post).count()
return recent_posts
diff --git a/templates/blog/home.html b/templates/blog/home.html
index 44c931ae..6abaae39 100644
--- a/templates/blog/home.html
+++ b/templates/blog/home.html
@@ -62,14 +62,12 @@
<em><a href="#">{{ post.author }}</a> in</em>
<em><a href="#">{{ post.category }}</a></em>
</p>
- <p style="text-align: justify; font-size: 13px; margin-bottom: 0px;">
+ <div style="text-align: justify; font-size: 13px; margin-bottom: 0px;">
<span>
- <img src="{% url 'ignis:post_image' '200' post.id %}.gif" alt="Cover image for {{ post.title }}" style="float: left; margin-right: 10px; margin-bottom: 10px; width: 200px; height: auto;">
+ <img src="{% url 'ignis:post_image' '320' post.id %}.gif" alt="Cover image for {{ post.title }}" style="float: left; margin-right: 11px; margin-top: 4px; width: 320px; height: auto;">
</span>
- <span>
{{ post.excerpt | safe }}
- </span>
- </p>
+ </div>
<div class="post-actions" style="clear: both;">
<a href="{% url 'blog:post' post.slug %}">Continue Reading</a> | <a href="{% url 'blog:post' post.slug %}#comments">{{ post.num_comments }} Comments</a>
</div>