{% extends "base.html" %}
{% block title %}Blog admin{% endblock %}
{% block head %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/admin_page.css') }}">
{% endblock %}
{% block content %}
<div class="admin-wrap">
<div class="admin-top">
<h1 class="admin-title">Blog admin</h1>
<div class="admin-row">
<a class="btn" href="{{ url_for('admin_new_post') }}">New post</a>
<a class="btn" href="{{ url_for('admin_logout') }}">Logout</a>
</div>
</div>
<table class="admin-table">
<thead>
<tr>
<th>Title</th>
<th>Status</th>
<th>Slug</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for p in posts %}
<tr>
<td>
<strong>{{ p.title }}</strong><br>
<span class="page-desc" style="margin:0; font-size:12.5px;">
Created {{ p.created_at.strftime('%d %b %Y') }}
{% if p.published_at %} · Published {{ p.published_at.strftime('%d %b %Y') }}{% endif %}
</span>
</td>
<td>{{ 'Published' if p.is_published else 'Draft' }}</td>
<td>{{ p.slug }}</td>
<td>
<div class="admin-row">
<a class="btn" href="{{ url_for('admin_edit_post', post_id=p.id) }}">Edit</a>
{% if p.is_published %}
<a class="btn" href="{{ url_for('blog_post', slug=p.slug) }}" target="_blank" rel="noopener">View</a>
{% endif %}
<form method="post" action="{{ url_for('admin_delete_post', post_id=p.id) }}" onsubmit="return confirm('Delete this post?');">
<button class="btn" type="submit">Delete</button>
</form>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}