-
Notifications
You must be signed in to change notification settings - Fork 0
/
blog.astro
91 lines (82 loc) · 2.46 KB
/
blog.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
---
import BaseHead from "../components/BaseHead.astro";
import Header from "../components/Header.astro";
import Footer from "../components/Footer.astro";
import { SITE_TITLE, SITE_DESCRIPTION } from "../config";
//microCMS呼び出し
// import { getBlogs } from "../library/microcms";
import { cmsBlog } from "../library/microcms";
// import { createClient } from "microcms-js-sdk";
// import type { MicroCMSQueries } from "microcms-js-sdk";
// import type { Blog, BlogResponse } from "../library/microcms";
// const client = createClient({
// serviceDomain: "import.meta.env.MICROCMS_SERVICE_DOMAIN",
// apiKey: "import.meta.env.MICROCMS_API_KEY",
// });
// export const getBlogs = async (queries?: MicroCMSQueries) => {
// const data = await client.get<BlogResponse>({ endpoint: "blogs", queries });
// if (data.offset + data.limit < data.totalCount) {
// queries ? (queries.offset = data.offset + data.limit) : "";
// const result: BlogResponse = await getBlogs(queries);
// return {
// offset: result.offset,
// limit: result.limit,
// contents: [...data.contents, ...result.contents],
// totalCount: result.totalCount,
// };
// }
// return data;
// };
const runtime = Astro.locals.runtime;
const { contents: posts, totalCount } = await cmsBlog.getBlogs(runtime,{
orders: "-publishedAt",
});
// // Use Astro.glob() to fetch all posts, and then sort them by date.
// const posts = (await Astro.glob('./blog/*.{md,mdx}')).sort(
// (a, b) => new Date(b.frontmatter.pubDate).valueOf() - new Date(a.frontmatter.pubDate).valueOf()
// );
---
<!DOCTYPE html>
<html lang="ja">
<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>
<h1>{totalCount}</h1>
<section>
<ul>
{
posts.map((post) => (
<li>
<time datetime={post.publishedAt}>
{new Date(post.publishedAt).toLocaleDateString("ja-JP")}
</time>
<a href={`/blog/${post.id}`}>{post.title}</a>
</li>
))
}
</ul>
</section>
</main>
<Footer />
</body>
</html>