-
-
Notifications
You must be signed in to change notification settings - Fork 169
/
Copy pathindex.astro
61 lines (58 loc) · 1.77 KB
/
index.astro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---
import { type CollectionEntry, getCollection } from "astro:content";
import SocialList from "@/components/SocialList.astro";
import PostPreview from "@/components/blog/PostPreview.astro";
import Note from "@/components/note/Note.astro";
import { getAllPosts } from "@/data/post";
import PageLayout from "@/layouts/Base.astro";
import { collectionDateSort } from "@/utils/date";
// Posts
const MAX_POSTS = 10;
const allPosts = await getAllPosts();
const allPostsByDate = allPosts
.sort(collectionDateSort)
.slice(0, MAX_POSTS) as CollectionEntry<"post">[];
// Notes
const MAX_NOTES = 5;
const allNotes = await getCollection("note");
const latestNotes = allNotes.sort(collectionDateSort).slice(0, MAX_NOTES);
---
<PageLayout meta={{ title: "Home" }}>
<section>
<h1 class="title mb-6">Hello World!</h1>
<p class="mb-4">
Hi, I’m a theme for Astro, a simple starter that you can use to create your website or blog.
If you want to know more about how you can customise me, add more posts, and make it your own,
click on the GitHub icon link below and it will take you to my repo.
</p>
<SocialList />
</section>
<section aria-label="Blog post list" class="mt-16">
<h2 class="title mb-6 text-xl text-accent"><a href="/posts/">Posts</a></h2>
<ul class="space-y-4" role="list">
{
allPostsByDate.map((p) => (
<li class="grid gap-2 sm:grid-cols-[auto_1fr]">
<PostPreview post={p} />
</li>
))
}
</ul>
</section>
{
latestNotes.length > 0 && (
<section class="mt-16">
<h2 class="title mb-6 text-xl text-accent">
<a href="/notes/">Notes</a>
</h2>
<ul class="space-y-4" role="list">
{latestNotes.map((note) => (
<li>
<Note note={note} as="h3" isPreview />
</li>
))}
</ul>
</section>
)
}
</PageLayout>