Add recent posts section to index
This commit is contained in:
39
web/src/components/index/recentPosts.astro
Normal file
39
web/src/components/index/recentPosts.astro
Normal file
@@ -0,0 +1,39 @@
|
||||
---
|
||||
import SummaryCard from "./summaryCard.astro";
|
||||
import { authPB } from "@utils/pocketbase";
|
||||
import { getFormattedDate } from "@utils/date";
|
||||
|
||||
const pb = await authPB()
|
||||
|
||||
const posts = await pb.collection('posts').getList(1, 3, {
|
||||
sort: '-publishDate',
|
||||
filter: 'published=true',
|
||||
})
|
||||
|
||||
const postImages = await Promise.all( posts.items.map(p => pb.files.getURL(p, p.headerImage)) )
|
||||
|
||||
---
|
||||
<SummaryCard
|
||||
title="Recent Posts",
|
||||
titleLink="/posts"
|
||||
>
|
||||
<div class="flex flex-col md:flex-row gap-4 md:gap-4">
|
||||
{
|
||||
posts.items.map((p, i) => (
|
||||
<div class="flex md:flex-col flex-row gap-3 md:gap-2 flex-1">
|
||||
<time class="hidden md:block text-sm text-gray-500" datetime={p.publishDate}>{getFormattedDate(p.publishDate)}</time>
|
||||
<a href={`/posts/${p.slug}`} class="shrink-0">
|
||||
<img class="w-24 h-24 md:w-full md:h-48 object-cover rounded-lg" src={postImages[i]} alt={p.title}/>
|
||||
</a>
|
||||
|
||||
<div class="flex flex-col justify-start md:justify-start">
|
||||
<a href={`/posts/${p.slug}`} class="b1-no-underline line-clamp-2 md:line-clamp-none">
|
||||
{p.title}
|
||||
</a>
|
||||
<time class="md:hidden text-sm text-gray-500" datetime={p.publishDate}>{getFormattedDate(p.publishDate)}</time>
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
</SummaryCard>
|
||||
14
web/src/components/index/summaryCard.astro
Normal file
14
web/src/components/index/summaryCard.astro
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
|
||||
const { title, titleLink } = Astro.props
|
||||
|
||||
---
|
||||
|
||||
<div>
|
||||
<a href={titleLink} rel="prefetch" class="b1-no-underline">
|
||||
<h2 class="text-xl">{title}</h2>
|
||||
</a>
|
||||
<div class="flex flex-row gap-2">
|
||||
<slot/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,13 +1,21 @@
|
||||
---
|
||||
import Base from "src/layout/Base.astro"
|
||||
import RecentPosts from "@components/index/recentPosts"
|
||||
|
||||
export const prerender = false
|
||||
|
||||
---
|
||||
|
||||
<Base>
|
||||
<div slot="sidebar">
|
||||
sidebar stuff
|
||||
<div slot="sidebar" class="text-left">
|
||||
<p>New website new me!</p> <br>
|
||||
<p>Check out some of the photos and posts I've added recently, as well as the new design.</p><br>
|
||||
|
||||
<!-- todo: write this post lmfao -->
|
||||
<p>If you're interested, I actually wrote a post about the new design and all that went into it.</p>
|
||||
</div>
|
||||
|
||||
<div slot="content">
|
||||
ya
|
||||
<div slot="content" class="md:py-10">
|
||||
<RecentPosts/>
|
||||
</div>
|
||||
</Base>
|
||||
|
||||
Reference in New Issue
Block a user