yufan.me/src/components/sidebar/RandomPosts.astro

31 lines
627 B
Plaintext

---
import _ from 'lodash';
import type { Post } from '@/helpers/schema';
import options from '@/options';
interface Props {
posts: Post[];
}
const { posts } = Astro.props;
const randomSize = options.settings.sidebar.post;
---
{
randomSize > 0 && (
<div id="recent_posts" class="widget widget-recent-entries">
<div class="widget-title">随机文章</div>
<ul class="line">
{_.sampleSize(posts, randomSize).map((post) => (
<li>
<a href={post.permalink} title={post.title}>
{post.title}
</a>
</li>
))}
</ul>
</div>
)
}