Blog and category archives now show a numbered page list (first, last, current +/-1, collapsing gaps into an ellipsis) instead of only previous/next — see shared/utils/pagination.ts's paginationRange(). Renders page links via NuxtLink's custom/v-slot API rather than letting it render its own <a>: RouterLink's built-in active-class/aria-current detection compares only the route's path, not its query string, so every ?page=N link was incorrectly marked as the current page. The language switch now shows both "Italiano / English" at all times, with the current one as plain non-interactive text and the other as a link, moved to the header's top-right corner instead of stacked under the logo.
54 lines
1.5 KiB
Vue
54 lines
1.5 KiB
Vue
<script setup lang="ts">
|
|
import type { ArticleSummary, Paginated } from '#shared/types/blog'
|
|
import type { Locale } from '#shared/utils/locale'
|
|
import { STRINGS, interpolate } from '#shared/utils/i18n'
|
|
|
|
const props = defineProps<{ locale: Locale }>()
|
|
|
|
const strings = computed(() => STRINGS[props.locale])
|
|
|
|
const route = useRoute()
|
|
|
|
const page = computed(() => {
|
|
const value = Number(route.query.page)
|
|
return Number.isInteger(value) && value > 0 ? value : 1
|
|
})
|
|
|
|
const { data, error, status } = await useFetch<Paginated<ArticleSummary>>('/content/articles', {
|
|
key: () => `blog-${props.locale}-${page.value}`,
|
|
query: { page, lang: props.locale },
|
|
})
|
|
|
|
useSeo({
|
|
locale: props.locale,
|
|
path: '/blog',
|
|
title: page.value > 1 ? interpolate(strings.value.blog.titlePage, { page: page.value }) : strings.value.blog.title,
|
|
description: strings.value.blog.metaDescription,
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<header class="page-header">
|
|
<p class="kicker">{{ strings.blog.archiveKicker }}</p>
|
|
<h1>{{ strings.blog.title }}</h1>
|
|
</header>
|
|
|
|
<p v-if="error">{{ strings.blog.loadError }}</p>
|
|
|
|
<p v-else-if="status === 'pending'">{{ strings.blog.loading }}</p>
|
|
|
|
<p v-else-if="!data?.items.length">{{ strings.blog.empty }}</p>
|
|
|
|
<template v-else>
|
|
<ul class="card-grid">
|
|
<li v-for="article in data.items" :key="article.slug">
|
|
<ArticleCard :article="article" :locale="locale" />
|
|
</li>
|
|
</ul>
|
|
|
|
<PaginationNav :page="data.page" :page-count="data.pageCount" :locale="locale" />
|
|
</template>
|
|
</div>
|
|
</template>
|