Skip to content

Commit

Permalink
tweak: Reduce size of page cache
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Mar 18, 2024
1 parent 4ac4e0c commit 34d0fb8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/.vuepress/components/PostList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<script lang="ts">
import {} from 'vue'
import {useRouter} from 'vue-router'
import { PageCacheEntry } from '../utils/pageCache';
export default {
props: {
Expand All @@ -29,7 +30,7 @@ export default {
},
setup(props) {
return {
posts: props.posts,
posts: props.posts as PageCacheEntry[],
router: useRouter()
}
}
Expand Down Expand Up @@ -62,10 +63,6 @@ export default {
color: var(--c-text);
}
.posts-list .post__metadata {
}
.posts-list .post__excerpt .header-anchor {
display: none;
}
Expand Down
21 changes: 20 additions & 1 deletion src/.vuepress/utils/pageCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ interface BuildPageCacheOptions {
requireExcerpt?: boolean
}

export interface PageCacheEntry {
title: string
path: string
permalink: string
filePathRelative: string
frontmatter: Record<string, any>
slug: string
date: string

excerpt: string | null
}

const defaultBuildPageCacheOptions: BuildPageCacheOptions = {
reverse: false,
includeReadme: false,
Expand All @@ -22,7 +34,14 @@ export async function buildPageCache(app: App, name: string, prefix: string, opt
.filter(page => page.filePathRelative?.startsWith(prefix))
.filter(page => options.includeReadme || page.filePathRelative !== `${prefix}/README.md`)
.map(page => ({
...page,
title: page.title,
path: page.path,
permalink: page.permalink,
filePathRelative: page.filePathRelative,
frontmatter: page.frontmatter,
slug: page.slug,
date: page.date,

excerpt: page.contentRendered.includes("<!-- more -->") ? page.contentRendered.split("<!-- more -->")[0] : null
}))
.filter(page => !options.requireExcerpt || !!page.excerpt)
Expand Down

0 comments on commit 34d0fb8

Please sign in to comment.