Skip to content

Commit 30896d3

Browse files
committed
Add Plus Jakarta Sans font and plaintext filter for clean excerpts
1 parent 7eb01dd commit 30896d3

4 files changed

Lines changed: 34 additions & 5 deletions

File tree

portfolio/templates/portfolio/includes/post_slug.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
{{ post.title|truncatewords:8 }}
1818
</h3>
1919
<p class="text-xs sm:text-sm text-gray-600 dark:text-gray-400 mt-2
20-
line-clamp-3 break-words leading-relaxed">
21-
{{ post.excerpt|markdown|striptags|truncatewords:20 }}
20+
line-clamp-3 leading-relaxed tracking-normal">
21+
{{ post.excerpt|plaintext|truncatewords:20 }}
2222
</p>
2323
</div>
2424
</a>

portfolio/templates/portfolio/stored_post.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ <h3 class="text-base sm:text-lg font-semibold text-gray-900 dark:text-gray-100 b
3535
{{ post.title }}
3636
</h3>
3737
{% if post.excerpt %}
38-
<p class="text-sm text-gray-600 dark:text-gray-400 mt-2 line-clamp-2">
39-
{{ post.excerpt|markdown|striptags|truncatewords:20 }}
38+
<p class="text-sm text-gray-600 dark:text-gray-400 mt-2 line-clamp-2 tracking-normal">
39+
{{ post.excerpt|plaintext|truncatewords:20 }}
4040
</p>
4141
{% endif %}
4242
</a>

portfolio/templatetags/markdown_extras.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import re
12
import markdown
23
from django import template
4+
from django.utils.html import strip_tags
35
from django.utils.safestring import mark_safe
46

57
register = template.Library()
@@ -20,3 +22,25 @@ def markdown_format(text):
2022
])
2123

2224
return mark_safe(md.convert(text))
25+
26+
27+
@register.filter(name='plaintext')
28+
def plaintext(text):
29+
"""Convert markdown to plain text with normalized whitespace."""
30+
if not text:
31+
return ''
32+
33+
# Convert markdown to HTML
34+
md = markdown.Markdown(extensions=[
35+
'markdown.extensions.fenced_code',
36+
'markdown.extensions.tables',
37+
])
38+
html = md.convert(text)
39+
40+
# Strip HTML tags
41+
plain = strip_tags(html)
42+
43+
# Normalize whitespace: collapse multiple spaces/newlines into single space
44+
plain = re.sub(r'\s+', ' ', plain).strip()
45+
46+
return plain

templates/base.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
<link rel="apple-touch-icon" href="{% static 'favicon.png' %}"/>
3232
<title>{% block title %}Eric Gitangu - Deveric's Blog{% endblock %}</title>
3333

34+
<!-- Google Fonts - Plus Jakarta Sans -->
35+
<link rel="preconnect" href="https://fonts.googleapis.com">
36+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
37+
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,400;1,500&display=swap" rel="stylesheet">
38+
3439
<!-- Tailwind CSS CDN -->
3540
<script src="https://cdn.tailwindcss.com"></script>
3641
<script>
@@ -39,7 +44,7 @@
3944
theme: {
4045
extend: {
4146
fontFamily: {
42-
sans: ['system-ui', '-apple-system', 'BlinkMacSystemFont', 'Segoe UI', 'Roboto', 'Helvetica Neue', 'Arial', 'sans-serif'],
47+
sans: ['"Plus Jakarta Sans"', 'system-ui', '-apple-system', 'sans-serif'],
4348
}
4449
}
4550
}

0 commit comments

Comments
 (0)