REFACTOR Moving the injectIdToNativeTitles to dedicated sommaire file
This commit is contained in:
parent
27e2506d4c
commit
2d272daefb
|
|
@ -4,3 +4,16 @@ export function handleSmoothScrollToTitle(targetId: string): void {
|
||||||
|
|
||||||
targetElement.scrollIntoView({ behavior: 'smooth' });
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user