Merge branch 'no-abstract'
This commit is contained in:
commit
00ec56fef6
8 changed files with 44 additions and 24 deletions
|
@ -10,7 +10,7 @@ IGNORED_PATHS = [
|
||||||
def pages(request):
|
def pages(request):
|
||||||
if request.path in IGNORED_PATHS:
|
if request.path in IGNORED_PATHS:
|
||||||
return {}
|
return {}
|
||||||
return {"pages": Page.objects.filter(status=Article.PUBLISHED)}
|
return {"pages": Page.objects.filter(status=Article.PUBLISHED).exclude(position=0)}
|
||||||
|
|
||||||
|
|
||||||
def drafts_count(request):
|
def drafts_count(request):
|
||||||
|
|
|
@ -48,6 +48,10 @@ a {
|
||||||
border-bottom: .3ex solid var(--accent);
|
border-bottom: .3ex solid var(--accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.index-page h2 {
|
||||||
|
margin-top: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
.article-list h2 a {
|
.article-list h2 a {
|
||||||
border-color: transparent;
|
border-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
{% extends 'articles/base.html' %}
|
{% extends 'articles/base.html' %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}{{ article.title }} | {% endblock %}
|
||||||
{{ article.title }}
|
|
||||||
{% endblock %}
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<article class="article-detail">
|
<article class="article-detail">
|
||||||
<h1>{{ article.title }}{% if article.status != article.PUBLISHED %}
|
<h1>{{ article.title }}{% if article.status != article.PUBLISHED %}
|
||||||
|
|
|
@ -1,21 +1,26 @@
|
||||||
{% extends 'articles/base.html' %}
|
{% extends 'articles/base.html' %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}{% endblock %}
|
||||||
{{ title_header }}
|
|
||||||
{% endblock %}
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{{ blog_title }}{% if title %} · {{ title }}{% endif %}</h1>
|
<h1>{{ blog_title }}{% if title %} · {{ title }}{% endif %}</h1>
|
||||||
<p class="metadata">{{ blog_description }}</p>
|
<p class="metadata">{{ blog_description }} {% include "articles/admin_link_snippet.html" %}</p>
|
||||||
{% for article in articles %}
|
<section class="blog-posts">
|
||||||
<article class="article-list">
|
<h2>Blog posts</h2>
|
||||||
<h2><a href="{% url 'article-detail' slug=article.slug %}">{{ article.title }}</a></h2>
|
<ul>
|
||||||
{% include "articles/metadata_snippet.html" %}
|
{% for article in articles %}
|
||||||
{{ article.get_abstract|safe }}
|
<li>
|
||||||
<p class="read-more"><a href="{% url 'article-detail' slug=article.slug %}">Read more...</a></p>
|
{% if article.published_at %}
|
||||||
</article>
|
<time datetime="{{ article.published_at|date:CUSTOM_ISO }}">{{ article.published_at|date }}</time>
|
||||||
{% empty %}
|
{% else %}
|
||||||
<p>No article here. Come back later 🙂</p>
|
<time datetime="{{ article.updated_at|date:CUSTOM_ISO }}">{{ article.updated_at|date }}</time>
|
||||||
{% endfor %}
|
{% endif %}
|
||||||
|
: <a href="{% url 'article-detail' slug=article.slug %}">{{ article.title }}</a>
|
||||||
|
</li>
|
||||||
|
{% empty %}
|
||||||
|
<li>No article here. Come back later 🙂</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
<nav class="pagination">
|
<nav class="pagination">
|
||||||
<div class="older">
|
<div class="older">
|
||||||
{% if page_obj.has_next %}
|
{% if page_obj.has_next %}
|
||||||
|
@ -28,4 +33,10 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
<section class="index-page">
|
||||||
|
<h2>{{ index_page.title }}</h2>
|
||||||
|
<div>
|
||||||
|
{{ index_page.get_formatted_content|safe }}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>{% block title %}Home{% endblock %} | Gab's Notes</title>
|
<title>{% block title %}Home | {% endblock %}Gab's Notes</title>
|
||||||
<link rel="stylesheet" id="code-light" href="{% static 'code-light.css' %}" type="text/css">
|
<link rel="stylesheet" id="code-light" href="{% static 'code-light.css' %}" type="text/css">
|
||||||
<link rel="stylesheet" id="code-dark" href="{% static 'code-dark.css' %}" type="text/css">
|
<link rel="stylesheet" id="code-dark" href="{% static 'code-dark.css' %}" type="text/css">
|
||||||
<link rel="stylesheet" href="{% static 'style.css' %}" type="text/css">
|
<link rel="stylesheet" href="{% static 'style.css' %}" type="text/css">
|
||||||
|
|
|
@ -33,4 +33,5 @@ def published_page(author: User) -> Page:
|
||||||
published_at=timezone.now(),
|
published_at=timezone.now(),
|
||||||
slug="some-page-slug",
|
slug="some-page-slug",
|
||||||
content="## some page markdown\n\n[a page link](https://page.com)",
|
content="## some page markdown\n\n[a page link](https://page.com)",
|
||||||
|
position=2,
|
||||||
)
|
)
|
||||||
|
|
|
@ -15,23 +15,26 @@ def test_can_access_list(
|
||||||
content = res.content.decode("utf-8")
|
content = res.content.decode("utf-8")
|
||||||
for art in [published_article, published_page]:
|
for art in [published_article, published_page]:
|
||||||
assert art.title in content
|
assert art.title in content
|
||||||
assert published_article.get_abstract() in content
|
assert published_article.get_abstract() not in content
|
||||||
assert published_page.get_formatted_content() not in content
|
assert published_page.get_formatted_content() not in content
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_abstract_shown_on_list(client: Client, author: User):
|
def test_only_title_shown_on_list(client: Client, author: User):
|
||||||
|
title = "This is a very long title mouahahaha"
|
||||||
abstract = "Some abstract"
|
abstract = "Some abstract"
|
||||||
after = "Some content after abstract"
|
after = "Some content after abstract"
|
||||||
baker.make(
|
baker.make(
|
||||||
Article,
|
Article,
|
||||||
|
title=title,
|
||||||
status=Article.PUBLISHED,
|
status=Article.PUBLISHED,
|
||||||
author=author,
|
author=author,
|
||||||
content=f"{abstract}\n<!--more-->\n{after}",
|
content=f"{abstract}\n<!--more-->\n{after}",
|
||||||
) # type: Article
|
) # type: Article
|
||||||
res = client.get(reverse("articles-list"))
|
res = client.get(reverse("articles-list"))
|
||||||
content = res.content.decode("utf-8")
|
content = res.content.decode("utf-8")
|
||||||
assert abstract in content
|
assert title in content
|
||||||
|
assert abstract not in content
|
||||||
assert after not in content
|
assert after not in content
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ from articles.models import Article, Page
|
||||||
|
|
||||||
|
|
||||||
class BaseArticleListView(generic.ListView):
|
class BaseArticleListView(generic.ListView):
|
||||||
paginate_by = 15
|
paginate_by = 10
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
@ -25,7 +25,10 @@ class ArticlesListView(BaseArticleListView):
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context["title_header"] = "Articles"
|
index_page = Page.objects.filter(
|
||||||
|
status=Article.PUBLISHED, position=0
|
||||||
|
).first() # type: Page
|
||||||
|
context["index_page"] = index_page
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue