11<script lang="ts" setup>
2- import { type Ref } from " vue" ;
2+ import { computed , ref , type Ref } from " vue" ;
33import PageFooter from " ./PageFooter.vue" ;
4+ import Pagination from " ./Pagination.vue" ;
45import { RouteLink , type SiteData , useSiteData } from " vuepress/client" ;
5- import { getTagPathByTag } from " ../composables/useComponentUtils" ;
6- import { type PagesMap , defaultConstants } from " ../../shared" ;
6+ import { usePaginationChanges } from " ../composables/useComponentUtils" ;
7+ import { type PagesMap , PaginationPages , defaultConstants } from " ../../shared" ;
78
89const siteData: Ref <SiteData & { pagesMap: PagesMap }> = useSiteData () as any ;
910
@@ -13,26 +14,32 @@ const trimArticles = articles.filter((article) => {
1314 return ! exceptHomeListSlug .includes (article .slug );
1415});
1516
16- console .log (trimArticles );
17+ const pageSet = ref <PaginationPages >({
18+ total: trimArticles .length ,
19+ offset: 0 ,
20+ limit: 1 ,
21+ });
22+ const pageChanges = usePaginationChanges (pageSet );
23+ const slicedArticles = computed (() =>
24+ trimArticles .slice (
25+ pageSet .value .offset ,
26+ pageSet .value .offset + pageSet .value .limit
27+ )
28+ );
1729 </script >
1830
1931<template >
2032 <div class =" v-nc-theme-home" >
2133 <div class =" page-main" >
2234 <div class =" home-article-list" >
23- <div class =" article" v-for =" article in trimArticles" >
24- <RouteLink class =" home-link" :to =" article.pathInferred!" >
25- <span class =" title" >{{ article.data.title }}</span >
26- <span class =" tags" >
27- <RouteLink
28- class =" tag"
29- v-for =" tag in article.routeMeta?._blog?.tags"
30- :to =" getTagPathByTag(tag)"
31- >{{ tag }}</RouteLink
32- >
33- </span >
34- </RouteLink >
35+ <div class =" articles" >
36+ <div class =" article" v-for =" article in slicedArticles" >
37+ <RouteLink class =" home-link" :to =" article.pathInferred!" >
38+ <span class =" title" >{{ article.data.title }}</span >
39+ </RouteLink >
40+ </div >
3541 </div >
42+ <Pagination :pages =" pageSet" :changes =" pageChanges" />
3643 </div >
3744 <PageFooter />
3845 </div >
@@ -44,26 +51,25 @@ console.log(trimArticles);
4451 @apply flex flex-col justify-center items-center;
4552}
4653.home-article-list {
47- @apply w-1/ 2 h-fit flex flex-wrap items-center gap-2 my-24;
54+ @apply w-1/ 2 h-fit min-h-60 flex flex-col items-center justify-between my-24;
4855}
4956
57+ .articles {
58+ @apply flex flex-wrap gap-2;
59+ }
5060.article {
5161 @apply w-fit h-fit;
5262}
5363.article .home-link {
54- @apply inline-flex flex-col justify-center max-w-60 h-full px-1
64+ @apply inline-flex flex-col justify-center max-w-60 h-full
5565 rounded border-2 border-transparent bg-zinc-100 dark :bg-zinc-600
5666 hover :bg-green-100 hover:border-green-300 dark:hover:bg-green-700 dark:hover:border-green-500
67+ hover :text-green-500
5768 select-none cursor-pointer transition-all ease-in-out duration-300;
5869}
5970.home-link .title {
60- @apply inline-block max-w-60
61- text-xl
71+ @apply inline-block max-w-60 py-0 .5 px-1 .5
72+ text-xl shadow
6273 truncate;
6374}
64- .home-link .tags {
65- @apply inline-flex max-w-60 gap-0.5
66- flex-wrap
67- text-sm;
68- }
6975 </style >
0 commit comments