{% extends "eventum_admin.html" %}
{% import "eventum_macros.html" as macros %}

{% block css %}
{{ super() }}
<link rel="stylesheet" href="{{url_for('eventum.static', filename='css/lib/epiceditor/preview/github-highlighted.css')}}">
{% endblock %}

{% block title %}Blog Posts{% endblock %}
{% block pagetitle %}Blog Posts{% endblock %}

{% block js %}
{{ super() }}
<script type="text/javascript" src="{{ url_for('eventum.static', filename='js/posts/posts.js') }}"></script>
<script src="//yandex.st/highlightjs/8.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
{% endblock %}

{% block barright %}
<a href="{{ url_for('posts.new') }}"><i class="fa fa-plus fa-2x"></i></a>
{% endblock %}
{% set active_page="Blog" %}

{% macro render_posts(posts) %}
<table class="posts click table">
    <thead>
        <tr>
            <th>Title</th>
            <th>Snippet</th>
            <th>Author</th>
            <th>Date</th>
        </tr>
    </thead>
    <tbody>
{% for post in posts %}
<tr class="post">
    <td class="post-title">
        <span class="post-status {{ post.status() }}"></span>
        <a class="tr-link" href="{{ url_for('posts.edit', post_id=post.id)}}"></a>
            <p>{{post.title}}</p>
    </td>
    <td class="post-snippet overflowing-text">
        <small class="text">
            {{post.snippet(length=40, newlines=False, tags=False) | safe}}
        </small>
    </td>
    <td class="post-author with-image">
        <div class="image-wrapper">
            <i class="post-author-image"
               style="background-image:url({{ post.author.get_profile_picture() }})"></i>
        </div>
        <p class="post-author-name">{{ post.author.name }}</p>
    </td>
    <td class="post-date">
        <small>{{ post.pretty_date()}}</small>
    </td>
</tr>
{% endfor %}
</tbody>
</table>
{% endmacro%}


{% block content %}
{% if posts %}
{{ render_posts(posts) }}
{% else %}
<p style="text-align: center;">No posts!</p>
{% endif %}

{% endblock %}
