Votre blog post est maintenant entièrement interactif avec :
📄 Post Content Sidebar (lg+)
───────────────────────────────────────────────────────
📑 On this page
├─ Introduction
├─ Main Section 1
│ ├─ Subsection 1.1
│ └─ Subsection 1.2
├─ Main Section 2
└─ Conclusion
👥 Written by
├─ 👤 Tegra Kmd
└─ 👤 Méschac Irung
MDX File (Frontmatter + Content)
│
├─ Frontmatter → authors: [tegra_kmd, ...]
│ ↓
│ AUTHORS DB (authors.ts)
│ ↓
│ AuthorsSection Component
│
└─ Content → extractHeadings()
↓
Heading[] array
↓
TableOfContents Component
↓
Active highlight on scroll
app/
├── BlP/posts/[slug]/
│ └── page.tsx ← Page server du post
│ ├── getPost(slug) ← Récupère le post
│ ├── extractHeadings() ← Extrait la ToC
│ ├── getAuthorsBySlug() ← Récupère les auteurs
│ └── Rendu des composants
│
└── content/
├── 001-vlog.mdx ← Post avec authors config
└── 002-async-work.mdx ← Post d'exemple complet
src/
├── lib/
│ ├── mdx-utils.ts ← Logique extraction en-têtes
│ └── post.ts ← Schéma post + authors field
│
├── components/
│ ├── TableOfContents.tsx ← ToC interactive (client)
│ └── AuthorsSection.tsx ← Affichage auteurs (client)
│
├── data/
│ └── authors.ts ← DB centralisée auteurs
│
└── features/mdx/
├── mdx-components.tsx ← Config MDX + h2/h3
└── mdx-heading-wrapper.tsx ← Wrapper heading → ID auto
// ✓ Récupère le post avec son contenu MDX
const post = await getPost(slug);
// ✓ Extrait les en-têtes automatiquement
const headings = extractHeadings(post.content);
// ✓ Récupère les auteurs depuis le frontmatter
const authors = getAuthorsBySlug(post.authors || []);
// ✓ Passe les données aux composants
<TableOfContents headings={headings} />
<AuthorsSection authors={authors} />export function TableOfContents({ headings }) {
// ✓ Track heading actif avec Intersection Observer
const [activeId, setActiveId] = useState("");
// ✓ Affiche la liste avec styling actif
// ✓ Smooth scroll au clic
// ✓ Met à jour activeId lors du scroll
}export function AuthorsSection({ authors }) {
// ✓ Affiche chaque auteur avec son image et nom
// ✓ Responsive et stylisé
}export function extractHeadings(content: string): Heading[] {
// ✓ Parse le contenu MDX brut
// ✓ Trouve tous les ## et ###
// ✓ Génère les IDs automatiquement (slugify)
// ✓ Retourne un array de Heading
}// Headings extraits automatiquement
const headings = [
{ id: "introduction", text: "Introduction", level: 2 },
{
id: "les-avantages-de-lasynchrone",
text: "Les Avantages de l'Asynchrone",
level: 2,
},
{ id: "flexibilite-maximale", text: "Flexibilité Maximale", level: 3 },
{ id: "meilleure-documentation", text: "Meilleure Documentation", level: 3 },
{ id: "inclusivite-mondiale", text: "Inclusivité Mondiale", level: 3 },
// ... plus d'en-têtes
];
// Auteurs du frontmatter
const post = {
title: "L'Avenir du Travail Asynchrone",
authors: ["tegra_kmd"],
content: "...",
};
// Auteurs résolus
const authors = [
{
name: "Tegra Kmd",
image: "/avat.webp",
bio: "Developer & Content Creator",
},
];❌ En-têtes sont hardcodés
❌ Navigation manuelle
❌ Auteurs en dur
❌ Pas de suivi actif
✅ En-têtes générés du contenu
✅ Navigation fluide et interactive
✅ Auteurs configurables
✅ Suivi actif au scroll
✅ Design responsive
✅ Sticky sidebar
// ❌ AVANT - Hardcodé dans chaque page
const authors = [
{ name: "Tegra Kmd", image: "/avat.webp" },
{ name: "Méschac Irung", image: "https://..." },
];
// ✅ APRÈS - Centralisé et réutilisable
export const AUTHORS = {
tegra_kmd: {
/* ... */
},
meschac_irung: {
/* ... */
},
};
// Utilisation simple
const authors = getAuthorsBySlug(["tegra_kmd"]);---
title: "Mon Article"
authors:
- tegra_kmd
- meschac_irung
---
## Section 1
...
## Section 2
...→ ToC et Auteurs sont automatiquement générés ! 🎉
// Dans authors.ts
export const AUTHORS = {
// ...
nouveau_auteur: {
name: "Nouveau Auteur",
image: "/new-avatar.jpg",
},
};→ Disponible immédiatement dans tous les posts ! ✨
authors:
- meschac_irung # Maintenant en premier
- tegra_kmd→ L'ordre s'affiche correctement ! 🔄
✓ Extraction en-têtes : O(n) avec regex
✓ Lookup auteurs : O(1) avec object keys
✓ Component rendering : Memoized
✓ Scroll tracking : Intersection Observer (efficace)
✓ Aucune requête supplémentaire
Mobile (< 768px) Tablet (768px - 1024px) Desktop (1024px+)
─────────────── ────────────────────── ──────────────────
Article Article | Sidebar Article | Sidebar
(pas de sidebar) (réduire) (full size)
✓ Toujours lisible
✓ Pas de reflow
✓ Navigation intact
- Ajouter plus d'auteurs → Éditer
authors.ts - Publier les posts → Mettre
published: true - Personnaliser styles → Tailwind classes
- Ajouter CMS → Sanity/Contentful integration
- Extraction automatique des en-têtes
- Table des matières interactive
- Suivi actif au scroll
- Navigation fluide
- Auteurs configurables
- Base de données centralisée
- Components réutilisables
- TypeScript strict
- Responsive design
- Pas d'erreurs de compilation
- Documentation complète
- Exemples fonctionnels
🎉 Vous êtes prêt à utiliser le système !
Pour plus de détails, consultez :
/GUIDE_TOC_AUTHORS.md- Guide détaillé/README_TOC_INTERACTIVE.md- Documentation complète