<!doctype html>
<html lang="{{ current_locale() }}" class="h-100">
    {% set current_theme = current_theme() %} {% set config = config() %}

    <head>
        {{ current_theme.headertags() }} {{ current_theme.local_style() }}
        <title>Blog - {{ config.titulo }}</title>
    </head>

    <body>
        {{ current_theme.navbar() }}

        <main>
            {{ current_theme.notify() }}

            <div class="container">
                <div class="row">
                    <div class="col-md-8">
                        <h1>{{ config.titulo }} - Blog</h1>

                        {% if posts %} {% for post in posts %}
                        <article class="mb-4 border-bottom pb-3">
                            <h2>
                                <a href="{{ url_for('blog.blog_post', slug=post.slug) }}" class="text-decoration-none">
                                    {{ post.title }}
                                </a>
                            </h2>
                            <div class="text-muted mb-2">
                                {{ _('Por') }} {{ post.author.nombre }} {{ post.author.apellido or '' }} {% if
                                post.published_at %} {{ _('el') }} {{ post.published_at.strftime('%d/%m/%Y') }} {% else %} {{
                                _('el') }} {{ post.timestamp.strftime('%d/%m/%Y') }} {% endif %} {% if post.comment_count > 0
                                %} - {{ post.comment_count }} {{ _('comentarios') if post.comment_count != 1 else
                                _('comentario') }} {% endif %} {% if post.view_count is defined and post.view_count is not none
                                %} - {{ post.view_count }} {{ _('vistas') if post.view_count != 1 else _('vista') }} {% endif
                                %}
                            </div>

                            {% if post.tags %}
                            <div class="mb-2">
                                {% for tag in post.tags %}
                                <a
                                    href="{{ url_for('blog.blog_index', tag=tag.slug) }}"
                                    class="badge bg-secondary text-decoration-none me-1"
                                >
                                    {{ tag.name }}
                                </a>
                                {% endfor %}
                            </div>
                            {% endif %}

                            <div class="mb-2">
                                {{ limpiar_html(mkdown2html(post.content[:300])) }} {% if post.content|length > 300 %}...{%
                                endif %}
                            </div>

                            <a href="{{ url_for('blog.blog_post', slug=post.slug) }}" class="btn btn-outline-primary btn-sm">
                                {{ _('Leer más') }}
                            </a>
                        </article>
                        {% endfor %}

                        <!-- Pagination -->
                        {% if pagination.pages > 1 %}
                        <nav>
                            <ul class="pagination">
                                {% if pagination.has_prev %}
                                <li class="page-item">
                                    <a
                                        class="page-link"
                                        href="{{ url_for('blog.blog_index', page=pagination.prev_num, tag=current_tag, author=current_author) }}"
                                    >
                                        {{ _('Anterior') }}
                                    </a>
                                </li>
                                {% endif %} {% for page_num in pagination.iter_pages() %} {% if page_num %} {% if page_num !=
                                pagination.page %}
                                <li class="page-item">
                                    <a
                                        class="page-link"
                                        href="{{ url_for('blog.blog_index', page=page_num, tag=current_tag, author=current_author) }}"
                                    >
                                        {{ page_num }}
                                    </a>
                                </li>
                                {% else %}
                                <li class="page-item active">
                                    <span class="page-link">{{ page_num }}</span>
                                </li>
                                {% endif %} {% else %}
                                <li class="page-item disabled">
                                    <span class="page-link">...</span>
                                </li>
                                {% endif %} {% endfor %} {% if pagination.has_next %}
                                <li class="page-item">
                                    <a
                                        class="page-link"
                                        href="{{ url_for('blog.blog_index', page=pagination.next_num, tag=current_tag, author=current_author) }}"
                                    >
                                        {{ _('Siguiente') }}
                                    </a>
                                </li>
                                {% endif %}
                            </ul>
                        </nav>
                        {% endif %} {% else %}
                        <div class="alert alert-info">{{ _('No hay entradas de blog publicadas en este momento.') }}</div>
                        {% endif %}
                    </div>

                    <!-- Sidebar -->
                    <div class="col-md-4">
                        <div class="card">
                            <div class="card-header">
                                <h5>{{ _('Filtrar por etiqueta') }}</h5>
                            </div>
                            <div class="card-body">
                                <div class="d-grid gap-2">
                                    <a
                                        href="{{ url_for('blog.blog_index') }}"
                                        class="btn btn-outline-secondary btn-sm{% if not current_tag %} active{% endif %}"
                                    >
                                        {{ _('Todas las entradas') }}
                                    </a>
                                    {% for tag in tags %}
                                    <a
                                        href="{{ url_for('blog.blog_index', tag=tag.slug) }}"
                                        class="btn btn-outline-secondary btn-sm{% if current_tag == tag.slug %} active{% endif %}"
                                    >
                                        {{ tag.name }}
                                    </a>
                                    {% endfor %}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
    </body>
</html>
