feat(Components): Add pagination component

This component accept a Page<T> type from [astro](https://docs.astro.build/en/guides/routing/#complete-api-reference)
This commit is contained in:
Alexander Navarro 2024-03-19 20:43:04 -03:00
parent 642e15656e
commit 944b553e73
9 changed files with 258 additions and 83 deletions

View file

@ -52,25 +52,25 @@ const links = [
</div>
<script>
const normilizeUrl = (url: string): string => {
let newUrl = `${url}`;
if (newUrl.endsWith('/')) {
newUrl = newUrl.slice(0, -1);
}
return newUrl;
};
const setActiveLink = () => {
const links =
document.querySelectorAll<HTMLAnchorElement>(`#main-navbar a`);
links.forEach((link) =>
normilizeUrl(link.pathname) === normilizeUrl(location.pathname)
links.forEach((link) => {
if (link.pathname === '/' && location.pathname === '/') {
link.classList.add('active');
return;
}
if (link.pathname === '/' && location.pathname !== '/') {
link.classList.remove('active');
return;
}
location.pathname.startsWith(link.pathname)
? link.classList.add('active')
: link.classList.remove('active'),
);
: link.classList.remove('active');
});
};
// Add active class to the current link
document.addEventListener('astro:page-load', setActiveLink, { once: true });