Blog: Unify all post viewing in one template
During the years we went from site-wide blog, to project blog, to post view inside a project, to full one-page post view. This led to have multiple ways to see the same content. This commit brings all post related stuff to always use index.pug (or index_archive if we are looking blasts from the past).
This commit is contained in:
parent
232321cc2c
commit
78b186c8e4
@ -61,16 +61,10 @@ def posts_view(project_id=None, project_url=None, url=None, *, archive=False, pa
|
||||
post.picture = get_file(post.picture, api=api)
|
||||
post.url = url_for_node(node=post)
|
||||
|
||||
# Use the *_main_project.html template for the main blog
|
||||
is_main_project = project_id == current_app.config['MAIN_PROJECT_ID']
|
||||
main_project_template = '_main_project' if is_main_project else ''
|
||||
main_project_template = '_main_project'
|
||||
index_arch = 'archive' if archive else 'index'
|
||||
template_path = f'nodes/custom/blog/{index_arch}{main_project_template}.html',
|
||||
template_path = f'nodes/custom/blog/{index_arch}.html',
|
||||
|
||||
if url:
|
||||
template_path = f'nodes/custom/post/view{main_project_template}.html',
|
||||
|
||||
post = Node.find_one({
|
||||
'where': {'parent': blog._id, 'properties.url': url},
|
||||
'embedded': {'node_type': 1, 'user': 1},
|
||||
@ -95,6 +89,7 @@ def posts_view(project_id=None, project_url=None, url=None, *, archive=False, pa
|
||||
can_create_blog_posts = project.node_type_has_method('post', 'POST', api=api)
|
||||
|
||||
# Use functools.partial so we can later pass page=X.
|
||||
is_main_project = project_id == current_app.config['MAIN_PROJECT_ID']
|
||||
if is_main_project:
|
||||
url_func = functools.partial(url_for, 'main.main_blog_archive')
|
||||
else:
|
||||
@ -121,7 +116,7 @@ def posts_view(project_id=None, project_url=None, url=None, *, archive=False, pa
|
||||
return render_template(
|
||||
template_path,
|
||||
blog=blog,
|
||||
node=post,
|
||||
node=post, # node is used by the generic comments rendering (see custom/_scripts.pug)
|
||||
posts=posts._items,
|
||||
posts_meta=pmeta,
|
||||
more_posts_available=pmeta['total'] > pmeta['max_results'],
|
||||
|
@ -1,9 +0,0 @@
|
||||
| {% extends 'nodes/custom/blog/index_main_project.html' %}
|
||||
| {% import 'nodes/custom/blog/_macros.html' as blogmacros %}
|
||||
|
||||
| {% block body %}
|
||||
.container
|
||||
h3 Blog Archive
|
||||
|
||||
| {{ blogmacros.render_archive(project, posts, posts_meta) }}
|
||||
| {% endblock body %}
|
@ -1,50 +1,44 @@
|
||||
| {% extends 'projects/view.html' %}
|
||||
| {% extends 'layout.html' %}
|
||||
| {% import 'nodes/custom/blog/_macros.html' as blogmacros %}
|
||||
| {% from 'projects/_macros.html' import render_secondary_navigation %}
|
||||
|
||||
| {% set title = 'blog' %}
|
||||
|
||||
| {% block page_title %}Blog{% endblock%}
|
||||
|
||||
| {% block project_context %}
|
||||
| {{ blogmacros.render_blog_index(project, posts, can_create_blog_posts, api, more_posts_available, posts_meta) }}
|
||||
| {% endblock %}
|
||||
| {% block navigation_tabs %}
|
||||
| {{ render_secondary_navigation(project, navigation_links, title) }}
|
||||
| {% endblock navigation_tabs %}
|
||||
|
||||
| {% block project_tree %}
|
||||
#project_tree.jstree.jstree-default.blog
|
||||
ul.jstree-container-ul.jstree-children
|
||||
li.jstree-node(data-node-type="page")
|
||||
a.jstree-anchor(
|
||||
href="{{ url_for('projects.view', project_url=project.url) }}")
|
||||
| Browse Project
|
||||
|
||||
li.jstree-node(data-node-type="page")
|
||||
a.jstree-anchor.jstree-clicked(
|
||||
href="{{ url_for('main.project_blog', project_url=project.url) }}") Blog
|
||||
|
||||
| {% for post in posts %}
|
||||
li.jstree-node
|
||||
a.jstree-anchor.tree-item.post(
|
||||
href="{{ node.url }}")
|
||||
.tree-item-thumbnail
|
||||
| {% if post.picture %}
|
||||
img(src="{{ post.picture.thumbnail('s', api=api) }}")
|
||||
| {% else %}
|
||||
i.pi-document-text
|
||||
| {% endif %}
|
||||
span.tree-item-title {{ post.name }}
|
||||
span.tree-item-info {{ post._created | pretty_date }}
|
||||
| {% endfor %}
|
||||
| {% block body %}
|
||||
| {% if node %}
|
||||
| {{ blogmacros.render_blog_post(node, project=project) }}
|
||||
| {% else %}
|
||||
| {{ blogmacros.render_blog_index(project, posts, can_create_blog_posts, api, more_posts_available, posts_meta, pages=pages) }}
|
||||
| {% endif %}
|
||||
| {% endblock %}
|
||||
|
||||
| {% block footer_scripts %}
|
||||
|
||||
include ../_scripts
|
||||
script.
|
||||
/* UI Stuff */
|
||||
var project_container = document.getElementById('project-container');
|
||||
hopToTop(); // Display jump to top button
|
||||
|
||||
$(window).on("load resize",function(){
|
||||
containerResizeY($(window).height());
|
||||
/* Expand images when their link points to a jpg/png/gif */
|
||||
/* TODO: De-duplicate code from view post */
|
||||
var page_overlay = document.getElementById('page-overlay');
|
||||
$('.item-content a img').on('click', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
if ($(window).width() > 480) {
|
||||
project_container.style.height = (window.innerHeight - project_container.offsetTop) + "px";
|
||||
var href = $(this).parent().attr('href');
|
||||
var src = $(this).attr('src');
|
||||
|
||||
if (href.match("jpg$") || href.match("png$") || href.match("gif$")) {
|
||||
$(page_overlay)
|
||||
.addClass('active')
|
||||
.html('<img src="' + src + '"/>');
|
||||
} else {
|
||||
window.location.href = href;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1,35 +0,0 @@
|
||||
| {% extends 'layout.html' %}
|
||||
| {% import 'nodes/custom/blog/_macros.html' as blogmacros %}
|
||||
| {% set title = 'blog' %}
|
||||
|
||||
| {% block page_title %}Blog{% endblock%}
|
||||
|
||||
| {% block body %}
|
||||
| {{ blogmacros.render_blog_index(project, posts, can_create_blog_posts, api, more_posts_available, posts_meta, pages=pages) }}
|
||||
| {% endblock %}
|
||||
|
||||
| {% block footer_scripts %}
|
||||
|
||||
include ../_scripts
|
||||
script.
|
||||
hopToTop(); // Display jump to top button
|
||||
|
||||
/* Expand images when their link points to a jpg/png/gif */
|
||||
/* TODO: De-duplicate code from view post */
|
||||
var page_overlay = document.getElementById('page-overlay');
|
||||
$('.item-content a img').on('click', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
var href = $(this).parent().attr('href');
|
||||
var src = $(this).attr('src');
|
||||
|
||||
if (href.match("jpg$") || href.match("png$") || href.match("gif$")) {
|
||||
$(page_overlay)
|
||||
.addClass('active')
|
||||
.html('<img src="' + src + '"/>');
|
||||
} else {
|
||||
window.location.href = href;
|
||||
}
|
||||
});
|
||||
|
||||
| {% endblock %}
|
@ -1,68 +0,0 @@
|
||||
| {% extends 'projects/view.html' %}
|
||||
| {% set title = 'blog' %}
|
||||
|
||||
| {% block og %}
|
||||
meta(property="og:title", content="{{ node.name }}")
|
||||
meta(property="og:url", content="{{ url_for('main.project_blog', project_url=project.url, url=node.properties.url, _external=True)}}")
|
||||
meta(property="og:type", content="website")
|
||||
| {% if node.picture %}
|
||||
meta(property="og:image", content="{{ node.picture.thumbnail('l', api=api) }}")
|
||||
| {% endif %}
|
||||
meta(property="og:description", content="Blender Cloud is a web based service developed by Blender Institute that allows people to access the training videos and all the data from the open projects.")
|
||||
|
||||
meta(name="twitter:title", content="{{ node.name }}")
|
||||
meta(name="twitter:description", content="Blender Cloud is a web based service developed by Blender Institute that allows people to access the training videos and all the data from the open projects.")
|
||||
| {% if node.picture %}
|
||||
meta(property="og:image", content="{{ node.picture.thumbnail('l', api=api) }}")
|
||||
| {% endif %}
|
||||
| {% endblock %}
|
||||
|
||||
| {% block page_title %}{{node.name}} - Blog{% endblock%}
|
||||
|
||||
| {% block project_context %}
|
||||
| {% include 'nodes/custom/post/view_embed.html' %}
|
||||
| {% endblock %}
|
||||
|
||||
| {% block project_tree %}
|
||||
#project_tree.jstree.jstree-default.blog
|
||||
ul.jstree-container-ul.jstree-children
|
||||
li.jstree-node(data-node-type="page")
|
||||
a.jstree-anchor(
|
||||
href="{{ url_for('projects.view', project_url=project.url) }}")
|
||||
| Browse Project
|
||||
|
||||
li.jstree-node(data-node-type="page")
|
||||
a.jstree-anchor(
|
||||
href="{{ url_for('main.project_blog', project_url=project.url) }}") Blog
|
||||
|
||||
| {% for post in posts %}
|
||||
li.jstree-node
|
||||
a.jstree-anchor.tree-item.post(
|
||||
href="{{ url_for_node(node=post) }}",
|
||||
class="{% if post._id == node._id %}jstree-clicked{% endif %}")
|
||||
.tree-item-thumbnail
|
||||
| {% if post.picture %}
|
||||
img(src="{{ post.picture.thumbnail('s', api=api) }}")
|
||||
| {% else %}
|
||||
i.pi-document-text
|
||||
| {% endif %}
|
||||
span.tree-item-title {{ post.name }}
|
||||
span.tree-item-info {{ post._created | pretty_date }}
|
||||
| {% endfor %}
|
||||
| {% endblock %}
|
||||
|
||||
| {% block footer_scripts %}
|
||||
script.
|
||||
ProjectUtils.setProjectAttributes({projectId: "{{project._id}}", isProject: false, nodeId: '{{node._id}}'});
|
||||
|
||||
/* UI Stuff */
|
||||
var project_container = document.getElementById('project-container');
|
||||
$(window).on("load resize",function(){
|
||||
containerResizeY($(window).height());
|
||||
|
||||
if ($(window).width() > 480) {
|
||||
project_container.style.height = (window.innerHeight - project_container.offsetTop) + "px";
|
||||
}
|
||||
});
|
||||
|
||||
| {% endblock footer_scripts %}
|
@ -1,9 +0,0 @@
|
||||
| {% import 'nodes/custom/blog/_macros.html' as blogmacros %}
|
||||
|
||||
| {{ blogmacros.render_blog_post(node, project=project) }}
|
||||
|
||||
#comments-embed.comments-compact
|
||||
.comments-list-loading
|
||||
i.pi-spin
|
||||
|
||||
include ../_scripts
|
Loading…
x
Reference in New Issue
Block a user