summaryrefslogtreecommitdiff
path: root/examples/blog/src/pages/index.astro
blob: 2af3a1a03d95c2a3a73ff5fd5eebaedf56f315a5 (plain) (blame)
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
---
import MainHead from '../components/MainHead.astro';
import Nav from '../components/Nav.astro';
import PostPreview from '../components/PostPreview.astro';
import Pagination from '../components/Pagination.astro';

// page
let title = 'Muppet Blog: Home';
let description = 'An example blog on Astro';

// collection
// note: we want to show first 3 posts here, but we don’t want to paginate at /1, /2, /3, etc.
// so we show a preview of posts here, but actually paginate from $posts.astro
import authorData from '../data/authors.json';

let allPosts = Astro.fetchContent('./post/*.md');
allPosts.sort((a, b) => new Date(b.date) - new Date(a.date));
let firstThree = allPosts.slice(0, 3);
---

<html>
  <head>
    <title>{title}</title>
    <MainHead title={title} description={description} />
  </head>

  <body>
    <Nav />

    <main class="wrapper">
      <h1>Recent posts</h1>
      {firstThree.map((post) => <PostPreview post={post} author={authorData[post.author]} />)}
    </main>

    <footer>
      <Pagination nextUrl="/posts/2" />
    </footer>
  </body>
</html>