Deduplicated blog templates by using macros.
This commit is contained in:
parent
bd93625119
commit
2603c4f44f
@ -88,6 +88,8 @@ def posts_view(project_id=None, project_url=None, url=None):
|
||||
post['properties']['content'] = pillar.web.nodes.attachments.render_attachments(
|
||||
post, post_contents)
|
||||
|
||||
can_create_blog_posts = project.node_type_has_method('post', 'POST', api=api)
|
||||
|
||||
return render_template(
|
||||
template_path,
|
||||
blog=blog,
|
||||
@ -98,6 +100,7 @@ def posts_view(project_id=None, project_url=None, url=None):
|
||||
project=project,
|
||||
title='blog',
|
||||
node_type_post=project.get_node_type('post'),
|
||||
can_create_blog_posts=can_create_blog_posts,
|
||||
api=api)
|
||||
|
||||
|
||||
|
81
src/templates/nodes/custom/blog/_macros.pug
Normal file
81
src/templates/nodes/custom/blog/_macros.pug
Normal file
@ -0,0 +1,81 @@
|
||||
//- ******************************************************* -//
|
||||
| {% macro render_blog_post(node) %}
|
||||
| {% if node.picture %}
|
||||
.blog_index-header
|
||||
img(src="{{ node.picture.thumbnail('l', api=api) }}")
|
||||
| {% endif %}
|
||||
.blog_index-item
|
||||
a.item-title(
|
||||
href="{{ url_for_node(node=node) }}")
|
||||
| {{node.name}}
|
||||
|
||||
.item-info.
|
||||
<span title="{{node._created}}">{{node._created | pretty_date }}</span>
|
||||
{% if node._created != node._updated %}
|
||||
<span title="{{node._updated}}">(updated {{node._updated | pretty_date }})</span>
|
||||
{% endif %}
|
||||
{% if node.properties.category %}| {{node.properties.category}}{% endif %}
|
||||
| by {{node.user.full_name}}
|
||||
| <a href="{{ url_for_node(node=node) }}#comments">Leave a comment</a>
|
||||
{% if node.properties.status != 'published' %} | {{ node.properties.status}} {% endif %}
|
||||
|
||||
.item-content
|
||||
| {{node.properties.content}}
|
||||
|
||||
.item-meta
|
||||
a(href="{{ url_for_node(node=node) }}#comments") Leave a comment
|
||||
| {% endmacro %}
|
||||
|
||||
//- ******************************************************* -//
|
||||
| {% macro render_blog_index(project, posts, can_create_blog_posts, api) %}
|
||||
| {% if can_create_blog_posts %}
|
||||
a.btn.btn-default.button-create(href="{{url_for('nodes.posts_create', project_id=project._id)}}")
|
||||
i.pi-plus
|
||||
| Create New Post
|
||||
| {% endif %}
|
||||
|
||||
| {% if posts %}
|
||||
|
||||
| {% for node in posts %}
|
||||
|
||||
| {% if loop.first %}
|
||||
| {{ render_blog_post(node) }}
|
||||
|
||||
| {% else %}
|
||||
|
||||
| {% if loop.index == 2 %}
|
||||
h4.blog_index-title Blasts from the past
|
||||
| {% endif %}
|
||||
|
||||
.blog_index-item.list
|
||||
| {% if node.picture %}
|
||||
.item-header
|
||||
img.image(src="{{ node.picture.thumbnail('s', api=api) }}")
|
||||
| {% else %}
|
||||
.item-header.nothumb
|
||||
i.pi-document-text
|
||||
| {% endif %}
|
||||
a.item-title(
|
||||
href="{{ url_for_node(node=node) }}")
|
||||
| {{node.name}}
|
||||
|
||||
.item-info.
|
||||
<span title="{{node._created}}">{{node._created | pretty_date }}</span>
|
||||
{% if node._created != node._updated %}
|
||||
<span title="{{node._updated}}">(updated {{node._updated | pretty_date }})</span>
|
||||
{% endif %}
|
||||
{% if node.properties.category %}| {{node.properties.category}}{% endif %}
|
||||
| by {{node.user.full_name}}
|
||||
{% if node.properties.status != 'published' %} | {{ node.properties.status}} {% endif %}
|
||||
|
||||
| {% endif %} {# loop #}
|
||||
|
||||
| {% endfor %} {# posts #}
|
||||
|
||||
| {% else %}
|
||||
|
||||
.blog_index-item
|
||||
.item-content No posts yet.
|
||||
|
||||
| {% endif %} {# posts #}
|
||||
| {% endmacro %}
|
@ -1,4 +1,5 @@
|
||||
| {% extends 'projects/view.html' %}
|
||||
| {% import 'nodes/custom/blog/_macros.html' as blogmacros %}
|
||||
| {% set title = 'blog' %}
|
||||
| {% block page_title %}Blog{% endblock%}
|
||||
|
||||
@ -8,85 +9,9 @@ link(href="{{ url_for('static_pillar', filename='assets/css/blog.css', v=1732017
|
||||
| {% endblock %}
|
||||
|
||||
| {% block project_context %}
|
||||
|
||||
#blog_container
|
||||
|
||||
#blog_index-container
|
||||
|
||||
| {% if project.node_type_has_method('post', 'POST', api=api) %}
|
||||
a.btn.btn-default.button-create(href="{{url_for('nodes.posts_create', project_id=project._id)}}")
|
||||
i.pi-plus
|
||||
| Create New Post
|
||||
| {% endif %}
|
||||
|
||||
| {% if posts %}
|
||||
|
||||
| {% for node in posts %}
|
||||
|
||||
| {% if loop.first %}
|
||||
| {% if node.picture %}
|
||||
.blog_index-header
|
||||
img(src="{{ node.picture.thumbnail('l', api=api) }}")
|
||||
| {% endif %}
|
||||
.blog_index-item
|
||||
a.item-title(
|
||||
href="{{ url_for_node(node=node) }}")
|
||||
| {{node.name}}
|
||||
|
||||
.item-info.
|
||||
<span title="{{node._created}}">{{node._created | pretty_date }}</span>
|
||||
{% if node._created != node._updated %}
|
||||
<span title="{{node._updated}}">(updated {{node._updated | pretty_date }})</span>
|
||||
{% endif %}
|
||||
{% if node.properties.category %}| {{node.properties.category}}{% endif %}
|
||||
| by {{node.user.full_name}}
|
||||
| <a href="{{ url_for_node(node=node) }}#comments">Leave a comment</a>
|
||||
{% if node.properties.status != 'published' %} | {{ node.properties.status}} {% endif %}
|
||||
|
||||
.item-content
|
||||
| {{node.properties.content}}
|
||||
|
||||
.item-meta
|
||||
a(href="{{ url_for_node(node=node) }}#comments") Leave a comment
|
||||
|
||||
| {% else %}
|
||||
|
||||
| {% if loop.index == 2 %}
|
||||
h4.blog_index-title Blasts from the past
|
||||
| {% endif %}
|
||||
|
||||
.blog_index-item.list
|
||||
| {% if node.picture %}
|
||||
.item-header
|
||||
img.image(src="{{ node.picture.thumbnail('s', api=api) }}")
|
||||
| {% else %}
|
||||
.item-header.nothumb
|
||||
i.pi-document-text
|
||||
| {% endif %}
|
||||
a.item-title(
|
||||
href="{{ url_for_node(node=node) }}")
|
||||
| {{node.name}}
|
||||
|
||||
.item-info.
|
||||
<span title="{{node._created}}">{{node._created | pretty_date }}</span>
|
||||
{% if node._created != node._updated %}
|
||||
<span title="{{node._updated}}">(updated {{node._updated | pretty_date }})</span>
|
||||
{% endif %}
|
||||
{% if node.properties.category %}| {{node.properties.category}}{% endif %}
|
||||
| by {{node.user.full_name}}
|
||||
{% if node.properties.status != 'published' %} | {{ node.properties.status}} {% endif %}
|
||||
|
||||
| {% endif %} {# loop #}
|
||||
|
||||
| {% endfor %} {# posts #}
|
||||
|
||||
| {% else %}
|
||||
|
||||
.blog_index-item
|
||||
.item-content No posts yet.
|
||||
|
||||
| {% endif %} {# posts #}
|
||||
|
||||
| {{ blogmacros.render_blog_index(project, posts, can_create_blog_posts, api) }}
|
||||
| {% endblock %}
|
||||
|
||||
| {% block project_tree %}
|
||||
|
@ -1,90 +1,14 @@
|
||||
| {% extends 'layout.html' %}
|
||||
|
||||
| {% import 'nodes/custom/blog/_macros.html' as blogmacros %}
|
||||
| {% set title = 'blog' %}
|
||||
|
||||
| {% block page_title %}Blog{% endblock%}
|
||||
|
||||
| {% block body %}
|
||||
|
||||
.container
|
||||
#blog_container.cloud-blog
|
||||
|
||||
#blog_index-container
|
||||
|
||||
| {% if project.node_type_has_method('post', 'POST', api=api) %}
|
||||
a.btn.btn-default.button-create(href="{{url_for('nodes.posts_create', project_id=project._id)}}")
|
||||
i.pi-plus
|
||||
| Create New Post
|
||||
| {% endif %}
|
||||
|
||||
| {% if posts %}
|
||||
|
||||
| {% for node in posts %}
|
||||
|
||||
| {% if loop.first %}
|
||||
| {% if node.picture %}
|
||||
.blog_index-header
|
||||
img(src="{{ node.picture.thumbnail('l', api=api) }}")
|
||||
| {% endif %}
|
||||
.blog_index-item
|
||||
a.item-title(
|
||||
href="{{ url_for_node(node=node) }}")
|
||||
| {{node.name}}
|
||||
|
||||
.item-info.
|
||||
<span title="{{node._created}}">{{node._created | pretty_date }}</span>
|
||||
{% if node._created != node._updated %}
|
||||
<span title="{{node._updated}}">(updated {{node._updated | pretty_date }})</span>
|
||||
{% endif %}
|
||||
{% if node.properties.category %}| {{node.properties.category}}{% endif %}
|
||||
| by {{node.user.full_name}}
|
||||
| <a href="{{ url_for_node(node=node) }}#comments">Leave a comment</a>
|
||||
{% if node.properties.status != 'published' %} | {{ node.properties.status}} {% endif %}
|
||||
|
||||
.item-content
|
||||
| {{node.properties.content}}
|
||||
|
||||
.item-meta
|
||||
a(href="{{ url_for_node(node=node) }}#comments") Leave a comment
|
||||
|
||||
| {% else %}
|
||||
|
||||
| {% if loop.index == 2 %}
|
||||
h4.blog_index-title Blasts from the past
|
||||
| {% endif %}
|
||||
|
||||
.blog_index-item.list
|
||||
| {% if node.picture %}
|
||||
.item-header
|
||||
img.image(src="{{ node.picture.thumbnail('s', api=api) }}")
|
||||
| {% else %}
|
||||
.item-header.nothumb
|
||||
i.pi-document-text
|
||||
| {% endif %}
|
||||
a.item-title(
|
||||
href="{{ url_for_node(node=node) }}")
|
||||
| {{node.name}}
|
||||
|
||||
.item-info.
|
||||
<span title="{{node._created}}">{{node._created | pretty_date }}</span>
|
||||
{% if node._created != node._updated %}
|
||||
<span title="{{node._updated}}">(updated {{node._updated | pretty_date }})</span>
|
||||
{% endif %}
|
||||
{% if node.properties.category %}| {{node.properties.category}}{% endif %}
|
||||
| by {{node.user.full_name}}
|
||||
{% if node.properties.status != 'published' %} | {{ node.properties.status}} {% endif %}
|
||||
|
||||
| {% endif %} {# loop #}
|
||||
|
||||
| {% endfor %} {# posts #}
|
||||
|
||||
| {% else %}
|
||||
|
||||
.blog_index-item
|
||||
.item-content No posts yet.
|
||||
|
||||
| {% endif %} {# posts #}
|
||||
|
||||
| {{ blogmacros.render_blog_index(project, posts, can_create_blog_posts, api) }}
|
||||
| {% endblock %}
|
||||
|
||||
| {% block footer_scripts %}
|
||||
|
@ -1,3 +1,4 @@
|
||||
| {% import 'nodes/custom/blog/_macros.html' as blogmacros %}
|
||||
|
||||
#blog_container(class="{% if project and project._id == config.MAIN_PROJECT_ID %}cloud-blog{% endif %}")
|
||||
|
||||
@ -15,26 +16,7 @@
|
||||
.clearfix
|
||||
| {% endif %}
|
||||
|
||||
| {% if node.picture %}
|
||||
.blog_index-header
|
||||
img(src="{{ node.picture.thumbnail('l', api=api) }}")
|
||||
| {% endif %}
|
||||
.blog_index-item
|
||||
|
||||
.item-title
|
||||
| {{node.name}}
|
||||
|
||||
.item-info.
|
||||
<span title="{{node._created}}">{{node._created | pretty_date }}</span>
|
||||
{% if node._created != node._updated %}
|
||||
<span title="{{node._updated}}">(updated {{node._updated | pretty_date }})</span>
|
||||
{% endif %}
|
||||
{% if node.properties.category %}| {{node.properties.category}}{% endif %}
|
||||
| by {{node.user.full_name}}
|
||||
|
||||
.item-content
|
||||
| {{ node.properties.content }}
|
||||
|
||||
| {{ blogmacros.render_blog_post(node) }}
|
||||
|
||||
#comments-embed
|
||||
.comments-list-loading
|
||||
|
@ -21,10 +21,8 @@ meta(property="og:image", content="{{ node.picture.thumbnail('l', api=api) }}")
|
||||
| {% set title = 'blog' %}
|
||||
|
||||
| {% block body %}
|
||||
|
||||
.container
|
||||
| {% include 'nodes/custom/post/view_embed.html' %}
|
||||
|
||||
| {% endblock %}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user