Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add classes to post elements #121

Merged
merged 3 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ablog/blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,11 @@ def to_html(self, pagename, fulltext=False, drop_h1=True):
else:
doctree.append(deepcopy)
else:
excerpt_container = nodes.container()
excerpt_container.attributes["classes"].append("ablog-post-excerpt")
for node in self.excerpt:
doctree.append(node.deepcopy())
excerpt_container.append(node.deepcopy())
doctree.append(excerpt_container)
app = self._blog.app
revise_pending_xrefs(doctree, pagename)
app.env.resolve_references(doctree, pagename, app.builder)
Expand Down
4 changes: 4 additions & 0 deletions ablog/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ def process_postlist(app, doctree, docname):
bl.attributes["classes"].append("postlist")
for post in posts:
bli = nodes.list_item()
bli.attributes["classes"].append("ablog-post")
bl.append(bli)
par = nodes.paragraph()
bli.append(par)
Expand Down Expand Up @@ -535,6 +536,7 @@ def process_postlist(app, doctree, docname):
ref["names"] = []
ref["internal"] = True
ref.append(nodes.Text(text_type(item)))
par.attributes["classes"].append("ablog-post-title")
else:
ref = _missing_reference(app, item.xref, docname)
par.append(ref)
Expand All @@ -543,13 +545,15 @@ def process_postlist(app, doctree, docname):
if excerpts and post.excerpt:
for enode in post.excerpt:
enode = enode.deepcopy()
enode.attributes["classes"].append("ablog-post-excerpt")
revise_pending_xrefs(enode, docname)
app.env.resolve_references(enode, docname, app.builder)
enode.parent = bli.parent
bli.append(enode)
if expand:
ref = app.builder.get_relative_uri(docname, post.docname)
enode = nodes.paragraph()
enode.attributes["classes"].append("ablog-post-expand")
refnode = nodes.reference("", "", internal=True, refuri=ref)
innernode = nodes.emphasis(text=expand)
refnode.append(innernode)
Expand Down
6 changes: 3 additions & 3 deletions ablog/templates/collection.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ <h1>
</div>
{% endfor %} {% else %} {% for post in collection %}

<div class="section">
<h2>
<div class="section ablog-post">
<h2 class="ablog-post-title">
<a href="{{ pathto(post.docname) }}{{ anchor(post) }}"
>{{ post.title }}</a
>
Expand All @@ -44,7 +44,7 @@ <h2>
{% include "postcard2.html" %}
</ul>
{{ post.to_html(collection.docname) }}
<p><a href="{{ pathto(post.docname) }}">{{ _("Read more ...") }}</a></p>
<p class="ablog-post-expand"><a href="{{ pathto(post.docname) }}"><em>{{ _("Read more ...") }}</em></a></p>
<hr />
</div>
{% endfor %} {% endif %}
Expand Down
10 changes: 8 additions & 2 deletions tests/test_postlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ def test_postlist(app, status, warning):

html = read_text(app.outdir / "postlist.html")
assert '<ul class="postlist-style-none postlist simple">' in html
assert '<li><p>01 December - <a class="reference internal" href="post.html">post</a></p></li>' in html
assert (
'<li class="ablog-post"><p class="ablog-post-title">01 December - <a class="reference internal" href="post.html">post</a></p></li>'
in html
)


@pytest.mark.sphinx("html", testroot="postlist", confoverrides={"post_date_format_short": "%Y-%m-%d"})
Expand All @@ -29,4 +32,7 @@ def test_postlist_date_format_conf(app, status, warning):
assert app.statuscode == 0

html = read_text(app.outdir / "postlist.html")
assert '<li><p>2020-12-01 - <a class="reference internal" href="post.html">post</a></p></li>' in html
assert (
'<li class="ablog-post"><p class="ablog-post-title">2020-12-01 - <a class="reference internal" href="post.html">post</a></p></li>'
in html
)