Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(theme): optimize blog layout #198

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
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
26 changes: 19 additions & 7 deletions theme/src/client/components/Blog/VPPostItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,18 @@ const coverStyles = computed(() => {
.blog-post-item-content h3 {
display: flex;
align-items: center;
margin: 0;
font-size: 18px;
font-weight: 600;
color: var(--vp-c-text-1);
transition: color var(--t-color);
}

.blog-post-item-content h3 a {
color: inherit;
text-decoration: none;
}

.blog-post-item-content h3:hover {
color: var(--vp-c-brand-1);
}
Expand Down Expand Up @@ -271,7 +277,7 @@ const coverStyles = computed(() => {
}
}

.post-meta {
.blog-post-item-content .post-meta {
display: flex;
flex-wrap: wrap;
align-items: center;
Expand All @@ -282,23 +288,23 @@ const coverStyles = computed(() => {
transition: color var(--t-color);
}

.post-meta > div {
.blog-post-item-content .post-meta > div {
display: flex;
align-items: center;
justify-content: flex-start;
margin-right: 1rem;
}

.post-meta > div:last-of-type {
.blog-post-item-content .post-meta > div:last-of-type {
margin-right: 0;
}

.post-meta .tag-list {
.blog-post-item-content .post-meta .tag-list {
display: flex;
align-items: center;
}

.post-meta .tag-list .tag {
.blog-post-item-content .post-meta .tag-list .tag {
display: inline-block;
padding: 3px 5px;
margin-right: 6px;
Expand All @@ -310,18 +316,24 @@ const coverStyles = computed(() => {
transition: color var(--t-color), background-color var(--t-color);
}

.post-meta .tag-list .tag:last-of-type {
.blog-post-item-content .post-meta .tag-list .tag:last-of-type {
margin-right: 0;
}

.post-meta .icon {
.blog-post-item-content .post-meta .icon {
width: 14px;
height: 14px;
margin: 0.3rem;
color: var(--vp-c-text-3);
transition: color var(--t-color);
}

.blog-post-item-content .post-meta a {
font-weight: normal;
color: inherit;
text-decoration: none;
}

.excerpt.vp-doc :deep(p) {
margin: 0.5rem 0;
}
Expand Down
18 changes: 12 additions & 6 deletions theme/src/client/composables/blog-post-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ export function usePostListControl(homePage: Ref<boolean>) {
},
})

const perPage = computed(() => {
if (blog.value.pagination === false)
return 0
if (typeof blog.value.pagination === 'number')
return blog.value.pagination
return blog.value.pagination?.perPage || DEFAULT_PER_PAGE
})

const totalPage = computed(() => {
if (blog.value.pagination === false)
return 0
const perPage = blog.value.pagination?.perPage || DEFAULT_PER_PAGE
return Math.ceil(postList.value.length / perPage)
return Math.ceil(postList.value.length / perPage.value)
})
const isLastPage = computed(() => page.value >= totalPage.value)
const isFirstPage = computed(() => page.value <= 1)
Expand All @@ -56,13 +63,12 @@ export function usePostListControl(homePage: Ref<boolean>) {
if (blog.value.pagination === false)
return postList.value

const perPage = blog.value.pagination?.perPage || DEFAULT_PER_PAGE
if (postList.value.length <= perPage)
if (postList.value.length <= perPage.value)
return postList.value

return postList.value.slice(
(page.value - 1) * perPage,
page.value * perPage,
(page.value - 1) * perPage.value,
page.value * perPage.value,
)
})

Expand Down
2 changes: 1 addition & 1 deletion theme/src/node/config/resolveLocaleOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const FALLBACK_OPTIONS: PlumeThemeLocaleData = {
appearance: true,

blog: {
pagination: { perPage: 15 },
pagination: 15,
postList: true,
tags: true,
archives: true,
Expand Down
4 changes: 2 additions & 2 deletions theme/src/shared/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export interface PlumeThemeBlog {
/**
* 分页
*/
pagination?: false | {
pagination?: false | number | {
/**
* 每页显示的文章数量
* @default 20
* @default 15
*/
perPage?: number
}
Expand Down