Mostly port the individual entry template to Jinja2 - the actual entry content isn't being rendered, and there's no breadcrumbs yet, but otherwise it's spot-on

This commit is contained in:
Danielle McLean 2018-06-19 15:47:10 +10:00
parent 741c2eb234
commit ee12c15d1c
Signed by untrusted user: 00dani
GPG key ID: 8EB789DDF3ABD240
5 changed files with 93 additions and 2 deletions

View file

@ -0,0 +1,16 @@
{% extends 'lemoncurry/layout.html' %}
{% block head %}
<link rel="shortlink" href="{{ entry.short_url }}" />
<link rel="alternate" type="application/json+oembed" href="https://wirres.net/oembed/oembed/php?url={{ entry.absolute_url | urlencode }}" />
{% endblock %}
{% block styles %}
<link rel="stylesheet" type="text/stylus" href="{{ static('entries/css/h-entry.styl') }}" />
{% endblock %}
{% import 'entries/h-entry.html' as h %}
{% block main %}
<div class="entry">
{{ h.hEntry(entry, indent_width=8) }}
</div>
{% endblock %}

View file

@ -0,0 +1,64 @@
{% macro hEntry(entry, indent_width) -%}
{%- set i = ' ' * indent_width -%}
<article class="card h-entry">
{% if entry.photo %}
{{i}}<img class="card-img-top u-photo" src="{{ entry.photo.url }}" />
{% endif %}
{{i}}<div class="card-body">
{% if entry.name %}
{{i}}<h4 class="card-title p-name">{{ entry.name }}</h4>
{% endif %}
{{i}}<div class="e-content">
{{i}}{{ entry.content | indent(indent_width + 6) }}
{{i}}</div>
{{i}}</div>
{{i}}<div class="card-footer">
{{i}}<a class="p-author h-card" href="{{ entry.author.url }}">
{{i}}<img class="u-photo" src="{{ entry.author.avatar.url }}" />
{{i}}{{ entry.author.name }}
{{i}}</a>
{{i}}<a class="u-uid u-url" href="{{ entry.url }}">
{{i}}<time class="dt-published" datetime="{{ entry.published.isoformat() }}">
{{i}}<i class="fas fa-calendar" aria-hidden="true"></i>
{{i}}{{ entry.published | naturaltime }}
{{i}}</time>
{{i}}</a>
{% if entry.updated != entry.published %}
{{i}}<time class="dt-updated" datetime="{{ entry.updated.isoformat() }}">
{{i}}<i class="fas fa-pencil-alt" aria-hidden="true"></i>
{{i}}{{ entry.updated | naturaltime }}
{{i}}</time>
{% endif %}
{{i}}<a class="u-url" href="{{ entry.short_url }}">
{{i}}<i class="fas fa-link" aria-hidden="true"></i>
{{i}}{{ entry.short_url | friendly_url }}
{{i}}</a>
{{i}}</div>
{% if entry.cats.exists() %}
{{i}}<div class="card-footer">
{% for c in entry.cats.all() %}
{{i}}<a class="p-category" href="{{ c.url }}">
{{i}}<i class="fas fa-paw" aria-hidden="true"></i>
{{i}}{{ c.name }}
{{i}}</a>
{% endfor %}
{{i}}</div>
{% endif %}
{% if entry.syndications.exists() %}
{{i}}<div class="card-footer">
{% for s in entry.syndications.all() %}
{{i}}<a class="u-syndication" href="{{ s.url }}">
{{i}}<i class="{{ s.profile.site.icon }}" aria-hidden="true"></i>
{{i}}{{ s.profile }}
{{i}}</a>
{% endfor %}
{{i}}</div>
{% endif %}
{{i}}<script class="p-json-ld" type="application/ld+json">{{ entry.json_ld | tojson }}</script>
{{i}}</article>
{%- endmacro %}

View file

@ -1,3 +1,4 @@
from django.contrib.humanize.templatetags.humanize import naturaltime
from django.contrib.staticfiles.storage import staticfiles_storage
from django.urls import reverse
from jinja2 import Environment
@ -6,7 +7,7 @@ from compressor.contrib.jinja2ext import CompressorExtension
from django_activeurl.ext.django_jinja import ActiveUrl
from entries.kinds import all as entry_kinds
from .utils import load_package_json
from .utils import friendly_url, load_package_json
def environment(**options):
@ -16,6 +17,10 @@ def environment(**options):
lstrip_blocks=True,
**options
)
env.filters.update({
'friendly_url': friendly_url,
'naturaltime': naturaltime,
})
env.globals.update({
'entry_kinds': entry_kinds,
'package': load_package_json(),

View file

@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title class="p-name">{% if title %}{{ title }} ~ {% endif %}{{ request.site.name }}</title>
{% block head %}{% endblock %}
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css"
integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">

View file

@ -7,13 +7,18 @@ from django.http import HttpResponseForbidden, HttpResponseBadRequest
from django.utils.html import strip_tags
from os.path import join
from types import SimpleNamespace
from urllib.parse import urlencode, urljoin
from urllib.parse import urlencode, urljoin, urlparse
from .templatetags.markdown import markdown
cache = SimpleNamespace(package_json=None)
def friendly_url(url):
(scheme, netloc, path, params, q, fragment) = urlparse(url)
return netloc + path
def load_package_json():
if cache.package_json:
return cache.package_json