feat: dynamic feature posts.
This commit is contained in:
parent
c1b3f54161
commit
09b59e7acb
@ -46,7 +46,7 @@ const Options = z
|
||||
.readonly(),
|
||||
post: z.object({
|
||||
sort: z.enum(['asc', 'desc']),
|
||||
feature: z.array(z.string()).optional(),
|
||||
feature: z.array(z.string()).min(3).optional(),
|
||||
category: z.array(z.string()).optional(),
|
||||
}),
|
||||
pagination: z.object({
|
||||
@ -163,7 +163,6 @@ const options: z.input<typeof Options> = {
|
||||
assetPrefix: 'https://cat.yufan.me',
|
||||
post: {
|
||||
sort: 'desc',
|
||||
feature: ['we-are-stranger', 'secret-of-boys-mind', 'my-darling'],
|
||||
category: ['article', 'think', 'gossip', 'coding'],
|
||||
},
|
||||
pagination: {
|
||||
|
@ -8,29 +8,50 @@ interface Props {
|
||||
}
|
||||
|
||||
const { posts } = Astro.props;
|
||||
const historicalPosts = (): Post[] => {
|
||||
// Skip the first 6 pages.
|
||||
const offset = options.settings.pagination.posts * 6;
|
||||
if (posts.length - offset < 43 * 3 + 2) {
|
||||
// Can't generate historical posts.
|
||||
return [];
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const radical = now.getMonth() + now.getDate();
|
||||
|
||||
return [posts[offset + radical - 1], posts[offset + radical + 43 - 1], posts[offset + radical + 43 * 2 - 1]];
|
||||
};
|
||||
const featurePosts = options.settings.post.feature ?? [];
|
||||
const metas: Post[] = featurePosts
|
||||
.map((slug) => posts.find((post) => post.slug === slug))
|
||||
.flatMap((post) => (post == null ? [] : [post]))
|
||||
.slice(0, 3);
|
||||
|
||||
const metas: Post[] =
|
||||
featurePosts.length < 3
|
||||
? historicalPosts()
|
||||
: featurePosts
|
||||
.map((slug) => posts.find((post) => post.slug === slug))
|
||||
.flatMap((post) => (post == null ? [] : [post]))
|
||||
.slice(0, 3);
|
||||
---
|
||||
|
||||
<div class="list-top-pushes mb-3 mb-md-4 mb-lg-5">
|
||||
<div class="container">
|
||||
<div class="row gx-2 gx-md-3 list-grouped">
|
||||
<div class="col-lg-8">
|
||||
<FeaturePost post={metas[0]} />
|
||||
</div>
|
||||
<div class="col-lg-4 d-flex flex-column mt-2 mt-md-3 mt-lg-0">
|
||||
<div class="row g-2 g-md-3">
|
||||
<div class="col-6 col-lg-12">
|
||||
<FeaturePost post={metas[1]} />
|
||||
{
|
||||
metas.length === 3 && (
|
||||
<div class="list-top-pushes mb-3 mb-md-4 mb-lg-5">
|
||||
<div class="container">
|
||||
<div class="row gx-2 gx-md-3 list-grouped">
|
||||
<div class="col-lg-8">
|
||||
<FeaturePost post={metas[0]} />
|
||||
</div>
|
||||
<div class="col-6 col-lg-12">
|
||||
<FeaturePost post={metas[2]} />
|
||||
<div class="col-lg-4 d-flex flex-column mt-2 mt-md-3 mt-lg-0">
|
||||
<div class="row g-2 g-md-3">
|
||||
<div class="col-6 col-lg-12">
|
||||
<FeaturePost post={metas[1]} />
|
||||
</div>
|
||||
<div class="col-6 col-lg-12">
|
||||
<FeaturePost post={metas[2]} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user