summaryrefslogtreecommitdiff
path: root/examples/with-content/src/pages/blog/index.astro
blob: e4f769f8a2425413592c142410838b86433e001b (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
---
import BaseHead from '../../components/BaseHead.astro';
import Header from '../../components/Header.astro';
import Footer from '../../components/Footer.astro';
import { SITE_TITLE, SITE_DESCRIPTION } from '../../consts';
import { getCollection } from 'astro:content';

const posts = (await getCollection('blog')).sort(
	(a, b) => a.data.pubDate.valueOf() - b.data.pubDate.valueOf()
)
---

<!DOCTYPE html>
<html lang="en">
	<head>
		<BaseHead title={SITE_TITLE} description={SITE_DESCRIPTION} />
		<style>
			ul {
				list-style-type: none;
				padding: unset;
			}
			ul li {
				display: flex;
			}
			ul li time {
				flex: 0 0 130px;
				font-style: italic;
				color: #595959;
			}
			ul li a:visited {
				color: #8e32dc;
			}
		</style>
	</head>
	<body>
		<Header />
		<main>
			<section>
				<ul>
					{posts.map((post) => (
						<li>
							<time datetime={post.data.pubDate.toISOString()}>
								{post.data.pubDate.toLocaleDateString('en-us', {
									year: 'numeric',
									month: 'short',
									day: 'numeric',
								})}
							</time>
							<a href={'/blog/' + post.slug}>{post.data.title}</a>
						</li>
					))}
				</ul>
			</section>
		</main>
		<Footer />
	</body>
</html>