Skip to content
This repository was archived by the owner on Feb 25, 2024. It is now read-only.

Commit 15c6ecb

Browse files
Custom blog archive page
1 parent d7b6c47 commit 15c6ecb

2 files changed

Lines changed: 83 additions & 2 deletions

File tree

i18n/ko/code.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@
8080
"description": "The ARIA label for the back to top button"
8181
},
8282
"theme.blog.archive.title": {
83-
"message": "게시물 목록",
83+
"message": "",
8484
"description": "The page & hero title of the blog archive page"
8585
},
8686
"theme.blog.archive.description": {
87-
"message": "게시물 목록",
87+
"message": "",
8888
"description": "The page & hero description of the blog archive page"
8989
},
9090
"theme.blog.paginator.navAriaLabel": {

src/theme/BlogArchivePage/index.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import React from 'react';
2+
import Link from '@docusaurus/Link';
3+
import {translate} from '@docusaurus/Translate';
4+
import {PageMetadata} from '@docusaurus/theme-common';
5+
import Layout from '@theme/Layout';
6+
function Year({year, posts}) {
7+
return (
8+
<>
9+
<h3>{year} ({posts.length})</h3>
10+
<ul>
11+
{posts.map((post) => (
12+
<li key={post.metadata.date}>
13+
<Link to={post.metadata.permalink}>
14+
{post.metadata.formattedDate} - {post.metadata.title}
15+
</Link>
16+
</li>
17+
))}
18+
</ul>
19+
</>
20+
);
21+
}
22+
function YearsSection({years}) {
23+
return (
24+
<section className="margin-vert--lg">
25+
<div className="container">
26+
<div className="row">
27+
{years.map((_props, idx) => (
28+
<div key={idx} className="col col--4 margin-vert--lg">
29+
<Year {..._props} />
30+
</div>
31+
))}
32+
</div>
33+
</div>
34+
</section>
35+
);
36+
}
37+
function listPostsByYears(blogPosts) {
38+
const postsByYear = blogPosts.reduceRight((posts, post) => {
39+
const year = post.metadata.date.split('-')[0];
40+
const yearPosts = posts.get(year) ?? [];
41+
return posts.set(year, [post, ...yearPosts]);
42+
}, new Map());
43+
return Array.from(postsByYear, ([year, posts]) => ({
44+
year,
45+
posts,
46+
}));
47+
}
48+
export default function BlogArchive({archive}) {
49+
const title = translate({
50+
id: 'theme.blog.archive.title',
51+
message: 'Archive',
52+
description: 'The page & hero title of the blog archive page',
53+
});
54+
const description = translate({
55+
id: 'theme.blog.archive.description',
56+
message: 'Archive',
57+
description: 'The page & hero description of the blog archive page',
58+
});
59+
const years = listPostsByYears(archive.blogPosts);
60+
return (
61+
<>
62+
<PageMetadata title={title} description={description} />
63+
<Layout>
64+
<header
65+
className="hero hero--primary"
66+
style={{
67+
background: "url('https://images.unsplash.com/photo-1571607073129-606b83b78f02?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2070&q=80')",
68+
backgroundRepeat: "no-repeat",
69+
backgroundPosition: "center",
70+
width: "100%"
71+
}}
72+
>
73+
<div className="container">
74+
<h1 className="hero__title">{title}</h1>
75+
</div>
76+
</header>
77+
<main>{years.length > 0 && <YearsSection years={years} />}</main>
78+
</Layout>
79+
</>
80+
);
81+
}

0 commit comments

Comments
 (0)