Ajout d'un champ description au modèle Post avec migration associée, mise à jour des templates pour utiliser ce champ, et amélioration du formatage des commentaires Markdown avec gestion des titres typographiques.
This commit is contained in:
parent
43af8bd0d8
commit
4a48425374
6 changed files with 38 additions and 4 deletions
18
blog/migrations/0003_post_description.py
Normal file
18
blog/migrations/0003_post_description.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 6.0 on 2025-12-15 20:13
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('blog', '0002_post_enable'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='post',
|
||||
name='description',
|
||||
field=models.TextField(default='Courte description'),
|
||||
),
|
||||
]
|
||||
|
|
@ -4,6 +4,7 @@ class Post(models.Model):
|
|||
name = models.CharField(max_length=200)
|
||||
tags = models.CharField(max_length=200)
|
||||
slug = models.SlugField()
|
||||
description = models.TextField(default="Courte description")
|
||||
content = models.TextField()
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
|
|
|||
|
|
@ -27,6 +27,19 @@ def _format_inline(text: str) -> str:
|
|||
lambda m: f"<code class=\"comment-code\">{m.group(1)}</code>",
|
||||
text,
|
||||
)
|
||||
# H1
|
||||
text = re.sub(r"^# (.+)$", r"<h1>\1</h1>", text, flags=re.MULTILINE)
|
||||
# H2
|
||||
text = re.sub(r"^## (.+)$", r"<h2>\1</h2>", text, flags=re.MULTILINE)
|
||||
# H3
|
||||
text = re.sub(r"^### (.+)$", r"<h3>\1</h3>", text, flags=re.MULTILINE)
|
||||
# H4
|
||||
text = re.sub(r"^#### (.+)$", r"<h4>\1</h4>", text, flags=re.MULTILINE)
|
||||
# H5
|
||||
text = re.sub(r"^##### (.+)$", r"<h5>\1</h5>", text, flags=re.MULTILINE)
|
||||
# H6
|
||||
text = re.sub(r"^###### (.+)$", r"<h6>\1</h6>", text, flags=re.MULTILINE)
|
||||
|
||||
# bold **text**
|
||||
text = re.sub(
|
||||
r"\*\*([^*]+)\*\*",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from django.contrib import sitemaps
|
||||
from django.urls import reverse
|
||||
|
||||
# --- IMPORTS DEPUIS TES DIFFÉRENTES FEATURES ---
|
||||
# --- FEATURES ---
|
||||
from courses.models import Course
|
||||
from users.models import Profile
|
||||
from blog.models import Post
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% load comment_format %}
|
||||
{% block title %} | Blog : {{ post.name }}{% endblock %}
|
||||
{% block og_title %}Blog de Partir De Zéro : {{ post.name }}{% endblock %}
|
||||
{% block description %}{{ post.content|striptags|truncatewords:20 }}{% endblock %}
|
||||
|
|
@ -18,7 +19,7 @@
|
|||
</header>
|
||||
|
||||
<article class="post-content prose">
|
||||
{{ post.content|safe }}
|
||||
{{ post.content|comment_markdown }}
|
||||
</article>
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
{% load comment_format %}
|
||||
<div class="post-list">
|
||||
{% for post in posts %}
|
||||
<article class="post-card">
|
||||
<h3 class="post-card-title"><a href="{% url 'blog:post_detail' post.slug %}">{{ post.name }}</a></h3>
|
||||
<h3 class="post-card-title"><a href="{% url 'blog:post_detail' post.slug %}">{{ post.name|truncatewords:6 }}</a></h3>
|
||||
<div class="post-meta">
|
||||
<span class="post-date"><i class="fa-regular fa-calendar"></i> {{ post.created_at|date:"d F Y" }}</span>
|
||||
{% if post.tags %}
|
||||
|
|
@ -9,7 +10,7 @@
|
|||
<span class="post-tags"><i class="fa-solid fa-tag"></i> {{ post.tags }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<p class="post-excerpt">{{ post.content|striptags|truncatewords:26 }}</p>
|
||||
<p class="post-excerpt">{{ post.description|comment_markdown|truncatewords:26 }}</p>
|
||||
<div class="post-actions">
|
||||
<a class="button button-secondary" href="{% url 'blog:post_detail' post.slug %}">Lire l'article →</a>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue