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:
parent
642e15656e
commit
944b553e73
9 changed files with 258 additions and 83 deletions
|
|
@ -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 });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue