techtalk/templates/posts_partial.html

45 lines
2.8 KiB
HTML
Raw Permalink Normal View History

2024-09-20 17:13:50 +02:00
{% for post in posts %}
<div class="card mb-3">
<div class="card-body">
<p class="card-text">{{ post.content|safe }}</p>
{% if post.image_url %}
<img src="{{ url_for('static', filename='uploads/' + post.image_url) }}" class="img-fluid mb-2 post-image" alt="Post image" data-bs-toggle="modal" data-bs-target="#imageModal{{ post.id }}">
{% endif %}
<div class="d-flex align-items-center mt-2">
{% if post.author %}
{% if post.author.profile_picture %}
<img src="{{ url_for('static', filename='uploads/' + post.author.profile_picture) }}" class="rounded-circle me-2" alt="Profile Picture" style="width: 30px; height: 30px; object-fit: cover;">
{% else %}
<div class="rounded-circle me-2 d-flex justify-content-center align-items-center bg-primary" style="width: 30px; height: 30px;">
<span class="text-white" style="font-size: 0.8rem;">{{ post.author.username[0].upper() }}</span>
</div>
{% endif %}
<small class="text-muted">
<a href="{{ url_for('profile', username=post.author.username) }}" class="text-decoration-none">{{ post.author.username }}</a>
</small>
{% else %}
<small class="text-muted">{{ post.anonymous_username }}</small>
{% endif %}
</div>
<p class="card-text"><small class="text-muted">{{ post.timestamp.strftime('%Y-%m-%d %H:%M:%S') }}</small></p>
<button class="btn btn-primary btn-sm like-btn" data-post-id="{{ post.id }}">
<i class="bi bi-heart-fill"></i> Like (<span class="like-count">{{ post.likes|length }}</span>)
</button>
<button class="btn btn-secondary btn-sm comment-btn" data-post-id="{{ post.id }}">
<i class="bi bi-chat-fill"></i> Comment ({{ post.comments|length }})
</button>
<a href="{{ url_for('post_detail', post_id=post.id) }}" class="btn btn-info btn-sm" target="_blank">
<i class="bi bi-box-arrow-up-right"></i> Open in new tab
</a>
<button class="btn btn-info btn-sm copy-link-btn" data-post-url="{{ url_for('post_detail', post_id=post.id, _external=True, _scheme='https') }}">
<i class="bi bi-link-45deg"></i> Copy Link
</button>
{% if (current_user.is_authenticated and post.author and current_user.id == post.author.id) or (not current_user.is_authenticated and post.user_id == session['user_id']) %}
<a href="{{ url_for('edit_post', post_id=post.id) }}" class="btn btn-warning btn-sm">
<i class="bi bi-pencil-fill"></i> Edit
</a>
{% endif %}
</div>
<!-- ... (comment section remains the same) ... -->
</div>
{% endfor %}