summaryrefslogtreecommitdiff
path: root/examples/blog/src/pages/index.astro
blob: b278c5510001496e7a6c89f0ea1ffba4d031b42b (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
---
// Component Imports
import BaseHead from "../components/BaseHead.astro";
import BlogHeader from "../components/BlogHeader.astro";
import BlogPostPreview from "../components/BlogPostPreview.astro";

// Component Script:
// You can write any JavaScript/TypeScript that you'd like here.
// It will run during the build, but never in the browser.
// All variables are available to use in the HTML template below.
let title = "Example Blog";
let description = "The perfect starter for your perfect blog.";
let permalink = "https://example.com/";

// Data Fetching: List all Markdown posts in the repo.

let allPosts = await Astro.glob("./posts/*.md");
allPosts = allPosts.sort(
	(a, b) =>
		new Date(b.frontmatter.publishDate).valueOf() - new Date(a.frontmatter.publishDate).valueOf()
);

// Full Astro Component Syntax:
// https://docs.astro.build/core-concepts/astro-components/
---

<html lang="en">
	<head>
		<BaseHead {title} {description} {permalink} />

		<style>
			header {
				width: 100%;
				height: 100%;
				background-color: var(--theme-bg-offset);
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.content {
				margin-top: 4rem;
				margin-bottom: 8rem;
			}

			.content :global(main > * + *) {
				margin-top: 1rem;
			}

			.intro {
				padding-bottom: 4rem;
				margin-bottom: 2rem;
				border-bottom: 4px solid var(--theme-divider);
			}

			.intro > * {
				margin: 0;
			}

			.latest {
				font-size: 2.5rem;
				font-weight: 700;
			}
		</style>
	</head>

	<body>
		<BlogHeader />
		<div class="wrapper">
			<main class="content">
				<section class="intro">
					<h1 class="latest">{title}</h1>
					<p>{description}</p>
				</section>
				<section aria-label="Blog post list">
					{allPosts.map((p) => <BlogPostPreview post={p} />)}
				</section>
			</main>
		</div>
	</body>
</html>