REFACTOR Moving the injectIdToNativeTitles to dedicated sommaire file

This commit is contained in:
Nonimart 2025-06-24 14:49:17 +02:00
parent 27e2506d4c
commit 2d272daefb

View File

@ -4,3 +4,16 @@ export function handleSmoothScrollToTitle(targetId: string): void {
targetElement.scrollIntoView({ behavior: 'smooth' });
}
export function injectIdToNativeTitles(): void {
const titles = document.querySelectorAll('.content-area h2, .content-area h3');
titles.forEach((title) => {
const titleText = title.textContent || '';
const slug = titleText
.toLowerCase()
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.replace(/\s+/g, '-')
.replace(/[^\w-]+/g, '');
title.setAttribute('id', slug);
});
}