diff options
| author | Bobby <[email protected]> | 2022-09-25 20:16:51 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-09-25 20:16:51 -0400 |
| commit | 7e11c94866ff0da2a4eb30734bd0e24a18010951 (patch) | |
| tree | f7187515756c75b9d654250dc2422a1a60d19494 | |
| parent | 85569caf68819bc8f5736877b411ad87ecc7cea7 (diff) | |
| download | thatcomputerscientist-7e11c94866ff0da2a4eb30734bd0e24a18010951.tar.xz thatcomputerscientist-7e11c94866ff0da2a4eb30734bd0e24a18010951.zip | |
Fixed some positionings and display first paragraph of top 5 articles on home
| -rw-r--r-- | blog/context_processors.py | 4 | ||||
| -rw-r--r-- | blog/views.py | 4 | ||||
| -rw-r--r-- | static/css/main.css | 5 | ||||
| -rw-r--r-- | templates/blog/home.html | 36 | ||||
| -rw-r--r-- | templates/blog_admin/partials/category_topbar.html | 3 | ||||
| -rw-r--r-- | templates/blog_admin/partials/posts_topbar.html | 3 | ||||
| -rw-r--r-- | templates/blog_admin/partials/tags_topbar.html | 3 | ||||
| -rw-r--r-- | templates/blog_admin/partials/users_topbar.html | 4 |
8 files changed, 29 insertions, 33 deletions
diff --git a/blog/context_processors.py b/blog/context_processors.py index 7d2f7da0..de9371ae 100644 --- a/blog/context_processors.py +++ b/blog/context_processors.py @@ -1,7 +1,9 @@ from .models import Post, Category def recent_posts(): - recent_posts = Post.objects.filter(is_public=True).order_by('-date')[1:6] + 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] return recent_posts def categories(): diff --git a/blog/views.py b/blog/views.py index 28d693f1..03d0424e 100644 --- a/blog/views.py +++ b/blog/views.py @@ -15,9 +15,7 @@ from .context_processors import recent_posts, categories, archives # Create your views here. def home(request): - last_post = Post.objects.filter(is_public=True).order_by('-date')[0] - first_paragraph = last_post.body.split('<p>')[1].split('</p>')[0] - return render(request, 'blog/home.html', {'title': 'Home', 'last_post': last_post, 'first_paragraph': first_paragraph, 'recent_posts': recent_posts(), 'categories': categories(), 'archives': archives()}) + return render(request, 'blog/home.html', {'title': 'Home', 'recent_posts': recent_posts(), 'categories': categories(), 'archives': archives()}) def account(request): user = request.user diff --git a/static/css/main.css b/static/css/main.css index ff2a33bd..c9342852 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -225,10 +225,7 @@ nav > ul > li { } .float-right { - /* Float to the top right corner */ - position: absolute; - top: 2.5em; - right: 23.85rem; + float: right; } .table { diff --git a/templates/blog/home.html b/templates/blog/home.html index fb4f1c16..a57b7fc2 100644 --- a/templates/blog/home.html +++ b/templates/blog/home.html @@ -21,33 +21,27 @@ articles or edit existing ones. </p> </div> - {% if last_post %} + {% if recent_posts %} <h3 style="margin-bottom: 0px"><em>Recent Posts</em></h3> <hr /> <ul> - <li> - <h1 style="margin-bottom: 12px; font-size: 2rem;"><a href="{% url 'blog:post' last_post.slug %}">{{ last_post.title }}</a></h1> - <p style="line-height: 1.6em;"> - Latest post on <em><u>{{ last_post.date | date:"M d, Y" }}</u></em> by <em><a href="#">{{ last_post.author }}</a> in <a href="#">{{ last_post.category }}</a></em> - </p> - <hr> - <div class="article-body"> - <p> - {{ first_paragraph | safe }} + {% for post in recent_posts %} + <li> + <h1 style="margin-bottom: 12px; font-size: 2rem;"><a href="{% url 'blog:post' post.slug %}">{{ post.title }}</a></h1> + <p style="line-height: 1.6em;"> + Posted on <em><u>{{ post.date | date:"M d, Y" }}</u></em> by <em><a href="#">{{ post.author }}</a> in <a href="#">{{ post.category }}</a></em> </p> - </div> - <p><em><a href="{% url 'blog:post' last_post.slug %}">Click here</a></em> to read more.</p> + <hr> + <div class="article-body"> + <p> + {{ post.excerpt | safe }} + </p> + </div> + <p><em><a href="{% url 'blog:post' post.slug %}">Click here</a></em> to read more.</p> + </li> + {% endfor %} <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> - </li> {% endif %} - {% for post in recent_posts %} - <li> - <a href="{% url 'blog:post' post.slug %}">{{ post.title }}</a> - by <em><a href="#">{{ post.author.username }}</a></em> on {{ - post.date | date:"M d, Y" }}. - </li> - {% endfor %} - </ul> <br /> <h3 style="margin-bottom: 0px"><em>Archives</em></h3> <hr /> diff --git a/templates/blog_admin/partials/category_topbar.html b/templates/blog_admin/partials/category_topbar.html index d03f82db..a52b2bb3 100644 --- a/templates/blog_admin/partials/category_topbar.html +++ b/templates/blog_admin/partials/category_topbar.html @@ -1,4 +1,3 @@ -<h1 style="font-size: 2em">{{ title }}</h1> <div class="float-right"> <a href="{% url 'blog-admin:new-category' %}">Create New Category</a> <form @@ -16,7 +15,9 @@ <input style="display: inline-block" type="submit" value="Search" /> </form> </div> +<h1 style="font-size: 2em">{{ title }}</h1> <hr /> +<br> {% for message in messages %} <p class="{{message.tags}}" style="text-align: center">{{ message }}</p> {% endfor %} diff --git a/templates/blog_admin/partials/posts_topbar.html b/templates/blog_admin/partials/posts_topbar.html index 41b899a1..326854a2 100644 --- a/templates/blog_admin/partials/posts_topbar.html +++ b/templates/blog_admin/partials/posts_topbar.html @@ -1,4 +1,3 @@ -<h1 style="font-size: 2em;">{{ title }}</h1> <div class="float-right"> <a href="{% url 'blog-admin:new-post' %}" >Create New Post</a> {% comment %} Search Users Box {% endcomment %} @@ -7,7 +6,9 @@ <input style="display: inline-block" type="submit" value="Search" /> </form> </div> +<h1 style="font-size: 2em;">{{ title }}</h1> <hr> +<br> {% for message in messages %} <p class="{{message.tags}}" style="text-align:center;">{{ message }}</p> {% endfor %}
\ No newline at end of file diff --git a/templates/blog_admin/partials/tags_topbar.html b/templates/blog_admin/partials/tags_topbar.html index 1e7090f9..c4a49ccf 100644 --- a/templates/blog_admin/partials/tags_topbar.html +++ b/templates/blog_admin/partials/tags_topbar.html @@ -1,4 +1,3 @@ -<h1 style="font-size: 2em;">{{ title }}</h1> <div class="float-right"> <a href="{% url 'blog-admin:new-post' %}" >Create New Tag</a> {% comment %} Search Users Box {% endcomment %} @@ -7,7 +6,9 @@ <input style="display: inline-block" type="submit" value="Search" /> </form> </div> +<h1 style="font-size: 2em;">{{ title }}</h1> <hr> +<br> {% for message in messages %} <p class="{{message.tags}}" style="text-align:center;">{{ message }}</p> {% endfor %}
\ No newline at end of file diff --git a/templates/blog_admin/partials/users_topbar.html b/templates/blog_admin/partials/users_topbar.html index 0b3043ad..a0be6122 100644 --- a/templates/blog_admin/partials/users_topbar.html +++ b/templates/blog_admin/partials/users_topbar.html @@ -1,4 +1,4 @@ -<h1 style="font-size: 2em;">{{ title }}</h1> + <div class="float-right"> <a href="{% url 'blog-admin:new-user' %}" >Create New User</a> {% comment %} Search Users Box {% endcomment %} @@ -7,7 +7,9 @@ <input style="display: inline-block" type="submit" value="Search" /> </form> </div> +<h1 style="font-size: 2em;">{{ title }}</h1> <hr> +<br> {% for message in messages %} <p class="{{message.tags}}" style="text-align:center;">{{ message }}</p> {% endfor %}
\ No newline at end of file |
