Fix permalinks with trailing slash in paginations
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
---
|
---
|
||||||
import { Icon } from 'astro-icon';
|
import { Icon } from 'astro-icon';
|
||||||
|
import { getPermalink } from '~/utils/permalinks';
|
||||||
const { prevUrl, nextUrl, prevText = 'Newer posts', nextText = 'Older posts' } = Astro.props;
|
const { prevUrl, nextUrl, prevText = 'Newer posts', nextText = 'Older posts' } = Astro.props;
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -8,7 +9,7 @@ const { prevUrl, nextUrl, prevText = 'Newer posts', nextText = 'Older posts' } =
|
|||||||
<div class="container flex">
|
<div class="container flex">
|
||||||
<div class="flex flex-row mx-auto container justify-between">
|
<div class="flex flex-row mx-auto container justify-between">
|
||||||
<a
|
<a
|
||||||
href={prevUrl}
|
href={getPermalink(prevUrl, "raw")}
|
||||||
class={`btn px-2 font-medium text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white shadow-none mr-2
|
class={`btn px-2 font-medium text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white shadow-none mr-2
|
||||||
${!prevUrl ? 'invisible' : ''}`}
|
${!prevUrl ? 'invisible' : ''}`}
|
||||||
>
|
>
|
||||||
@ -18,7 +19,7 @@ const { prevUrl, nextUrl, prevText = 'Newer posts', nextText = 'Older posts' } =
|
|||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
<a
|
<a
|
||||||
href={nextUrl}
|
href={getPermalink(nextUrl, "raw")}
|
||||||
class={`btn px-2 font-medium text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white shadow-none ${
|
class={`btn px-2 font-medium text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white shadow-none ${
|
||||||
!nextUrl ? 'invisible' : ''
|
!nextUrl ? 'invisible' : ''
|
||||||
}`}
|
}`}
|
||||||
|
@ -42,6 +42,9 @@ export const getPermalink = (slug = '', type = 'page') => {
|
|||||||
case 'post':
|
case 'post':
|
||||||
return createPath(basePathname, POST_BASE, _slug);
|
return createPath(basePathname, POST_BASE, _slug);
|
||||||
|
|
||||||
|
case 'raw':
|
||||||
|
return createPath(basePathname, trimSlash(slug));
|
||||||
|
|
||||||
case 'page':
|
case 'page':
|
||||||
default:
|
default:
|
||||||
return createPath(basePathname, _slug);
|
return createPath(basePathname, _slug);
|
||||||
|
Reference in New Issue
Block a user