Skip to content

Commit

Permalink
Merge pull request #21 from stuartmaxwell/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartmaxwell authored May 1, 2024
2 parents 5f8893a + 06ae064 commit 5c15faf
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 20 deletions.
1 change: 1 addition & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,4 @@
CACHE_CATEGORIES: bool = True
CACHE_RECENT_PUBLISHED_POSTS: bool = False
RECENT_PUBLISHED_POSTS_COUNT: int = 20
BLOG_TITLE = "stuartm.nz"
91 changes: 74 additions & 17 deletions djpress/templates/djpress/index.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,89 @@
{% extends '_base.html' %}
{% load djpress_tags %}

{% block title %}Home{% endblock %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% get_blog_title %}</title>
</head>
<body>
<header>
<h1><a href="{% url "djpress:index" %}">{% get_blog_title %}</a></h1>
</header>

{% block content %}
<main>

{% if slug %}
{% comment %} If there's a slug, we only display a single post. {% endcomment %}
{% if slug %}
{% comment %} If there's a slug, we only display a single post. {% endcomment %}

{% get_single_published_content slug as post %}
{% get_single_published_content slug as post %}

{% include "djpress/snippets/content_detail.html" %}
<article>
<header>
<h1>{{ post.title }}</h1>
<p>By <span rel="author">{{ post.author.first_name }}</span></p>
<p><time datetime="2023-05-01">{{ post.date }}</time></p>
</header>
<section>
{{ post.content_markdown|safe }}
</section>
<footer>
<p>Categories:</p>
<ul>
{% for category in post.categories.all %}
<li><a href="{% url 'djpress:category_posts' category.slug %}">{{ category.name }}</a></li>
{% endfor %}
</ul>
</footer>
</article>

{% else %}
{% comment %} If there's no slug, we loop through recent published content. {% endcomment %}
{% else %}
{% comment %} If there's no slug, we loop through recent published content. {% endcomment %}

{% get_recent_published_content as posts %}
{% get_recent_published_content as posts %}

{% for post in posts %}
{% for post in posts %}

{% include "djpress/snippets/content_summary.html" %}
<article>
<header>
<h1><a href="{% url 'djpress:content_detail' post.slug %}">{{ post.title }}</a></h1>
<p>By <span rel="author">{{ post.author.first_name }}</span></p>
<p><time datetime="2023-05-01">{{ post.date }}</time></p>
</header>
<section>
{{ post.truncated_content_markdown|safe }}

{% empty %}
{% if post.is_truncated %}
<p><a href="{% url 'djpress:content_detail' post.slug %}">Read more</a></p>
{% endif %}
</section>
<footer>
<p>Categories:</p>
<ul>
{% for category in post.categories.all %}
<li><a href="{% url 'djpress:category_posts' category.slug %}">{{ category.name }}</a></li>
{% endfor %}
</ul>
</footer>
</article>

<p>No posts available.</p>
{% empty %}

{% endfor %}
<p>No posts available.</p>

{% endif %}
{% endfor %}

{% endblock %}
{% endif %}

</main>

<footer>
<p>Powered by
<a href="https://www.djangoproject.com/" title="The web framework for perfectionists with deadlines">Django</a>
and
<a href="#">DJPress</a>
</p>
</footer>
</body>
</html>
7 changes: 7 additions & 0 deletions djpress/templatetags/djpress_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django import template
from django.db import models

from config.settings import BLOG_TITLE
from djpress.models import Category, Content

register = template.Library()
Expand All @@ -24,3 +25,9 @@ def get_recent_published_content() -> models.QuerySet[Category] | None:
def get_single_published_content(slug: str) -> Content | None:
"""Return a single published post by slug."""
return Content.post_objects.get_published_post_by_slug(slug)


@register.simple_tag
def get_blog_title() -> str:
"""Return the blog title."""
return BLOG_TITLE
2 changes: 1 addition & 1 deletion templates/_base.html → templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<script async src="https://u.amanzi.nz/script.js" data-website-id="d5f479d8-65fb-4f80-9823-5fe5ca2e17aa"></script>
</head>
<body>
{% include "snippets/navbar.html" %}
{% include "djpress/snippets/navbar.html" %}
<div class="container my-4">
{% block content %}
{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends '_base.html' %}
{% extends 'base.html' %}

{% block title %}{{ category.name }}{% endblock %}

Expand Down
32 changes: 32 additions & 0 deletions templates/djpress/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% extends 'base.html' %}
{% load djpress_tags %}

{% block title %}Home{% endblock %}

{% block content %}

{% if slug %}
{% comment %} If there's a slug, we only display a single post. {% endcomment %}

{% get_single_published_content slug as post %}

{% include "djpress/snippets/content_detail.html" %}

{% else %}
{% comment %} If there's no slug, we loop through recent published content. {% endcomment %}

{% get_recent_published_content as posts %}

{% for post in posts %}

{% include "djpress/snippets/content_summary.html" %}

{% empty %}

<p>No posts available.</p>

{% endfor %}

{% endif %}

{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends '_base.html' %}
{% extends 'base.html' %}

{% block title %}{{ post.title }}{% endblock %}

Expand Down
File renamed without changes.

0 comments on commit 5c15faf

Please sign in to comment.