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

Deduplicate logic for creating content list html #100

Merged
merged 2 commits into from
Oct 4, 2024
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
2 changes: 2 additions & 0 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ def create_image_client(url, timeout):
app.ext.environment.globals["format_npf"] = ext_npf_renderer.format_npf
app.ext.environment.globals["create_poll_callback"] = helpers.create_poll_callback

app.ext.environment.tests["a_post"] = lambda element : isinstance(element, priviblur_extractor.models.timeline.TimelinePost)


@app.listener("main_process_start")
async def main_startup_listener(app):
Expand Down
9 changes: 2 additions & 7 deletions src/templates/components/blog_contents.jinja
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
<div class="blog-posts" id="m">
{%- for element in blog.posts -%}
{%- if not element.is_advertisement -%}
{%- include 'components/post.jinja' -%}
{%- endif -%}
{%- endfor -%}
</div>
{% from 'macros/insert_content_list.jinja' import insert_content_list with context %}
{{-insert_content_list("blog-posts", blog.posts)}}
11 changes: 11 additions & 0 deletions src/templates/macros/insert_content_list.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{%- macro insert_content_list(content_list_cls, raw_content_list) -%}
<div class="{{content_list_cls}}" id="m">
{%- for element in raw_content_list -%}
{% if element is a_post %}
{%- if not element.is_advertisement -%}
{%- include 'components/post.jinja' -%}
{%- endif -%}
{% endif %}
{%- endfor -%}
</div>
{%-endmacro-%}
9 changes: 2 additions & 7 deletions src/templates/timeline.jinja
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends "base.jinja" %}
{% from 'macros/insert_content_list.jinja' import insert_content_list with context %}
{% block title %}{{title}}{% endblock%}

{% block center %}
Expand All @@ -7,13 +8,7 @@
{% endblock %}
</ul>

<div class="timeline" id="m">
{%- for element in timeline.elements -%}
{%- if not element.is_advertisement -%}
{%- include 'components/post.jinja' -%}
{%- endif -%}
{%- endfor -%}
</div>
{{insert_content_list("timeline", timeline.elements)}}

{%- if timeline.next %}
<div class="paging">
Expand Down