Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions src/.vitepress/theme/Pagination.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { withBase, useRoute } from 'vitepress'
import { ref, onMounted } from 'vue'
import { ref, onMounted, computed } from 'vue'
import type { Ref } from 'vue'
import { getCurrentCategory } from './utils/categoryUtils.client.js'

Expand All @@ -26,20 +26,40 @@ function getPageLink(pageNum: number) {

return withBase(basePath)
}

const pages = computed(() => {
if (numPages <= 7) {
return Array.from({ length: numPages }, (_, i) => i + 1)
}

if (pageIndex <= 4) {
return [1, 2, 3, 4, 5, '...', numPages]
}

if (pageIndex >= numPages - 3) {
return [1, '...', numPages - 4, numPages - 3, numPages - 2, numPages - 1, numPages]
Comment on lines +39 to +40
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When numPages is exactly 8 and pageIndex is 5 (which satisfies pageIndex >= numPages - 3), the returned array is [1, '...', 4, 5, 6, 7, 8]. This means the ellipsis hides only pages 2 and 3. However, the general best practice for pagination is to only use an ellipsis when hiding at least 2 or more pages. Consider adjusting the threshold conditions to ensure ellipses are only shown when they actually save space (hiding 2+ pages), otherwise the ellipsis doesn't provide value and can confuse users.

Copilot uses AI. Check for mistakes.
}

return [1, '...', pageIndex - 1, pageIndex, pageIndex + 1, '...', numPages]
})
</script>

<template>
<div class="flex justify-center space-x-2 py-4">
<a
class="px-3 py-2 rounded-md font-bold hover:outline outline-green-700"
:class="{
'bg-green-200 dark:bg-green-700': pageIndex === i,
'text-green-700 dark:text-green-300': pageIndex !== i,
}"
v-for="i in numPages"
:key="i"
:href="getPageLink(i)"
>{{ i }}</a
>
<template v-for="(item, index) in pages" :key="index">
<a
v-if="typeof item === 'number'"
class="px-3 py-2 rounded-md font-bold hover:outline outline-green-700"
:class="{
'bg-green-200 dark:bg-green-700': pageIndex === item,
'text-green-700 dark:text-green-300': pageIndex !== item,
}"
:href="getPageLink(item)"
>{{ item }}</a
>
<span v-else class="px-3 py-2 rounded-md font-bold text-green-700 dark:text-green-300">
...
</span>
</template>
</div>
</template>