-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
185 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
--- | ||
import type { SupportedLocale } from '@/types'; | ||
import DefaultLayout from '../default'; | ||
import { resolvePosts } from './helper'; | ||
import FormattedDate from './FormattedDate.astro'; | ||
const locale = (Astro.currentLocale || 'en') as SupportedLocale; | ||
const posts = (await resolvePosts(locale)).sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf()); | ||
--- | ||
|
||
<DefaultLayout> | ||
<style slot="custom-style"> | ||
main { | ||
width: 960px; | ||
} | ||
ul { | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 2rem; | ||
list-style-type: none; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
ul li { | ||
width: calc(50% - 1rem); | ||
} | ||
ul li * { | ||
text-decoration: none; | ||
transition: 0.2s ease; | ||
} | ||
ul li:first-child { | ||
width: 100%; | ||
margin-bottom: 1rem; | ||
text-align: center; | ||
} | ||
ul li:first-child img { | ||
width: 100%; | ||
} | ||
ul li:first-child .title { | ||
font-size: 2.369rem; | ||
} | ||
ul li img { | ||
margin-bottom: 0.5rem; | ||
border-radius: 12px; | ||
} | ||
ul li a { | ||
display: block; | ||
} | ||
.title { | ||
margin: 0; | ||
color: rgb(var(--black)); | ||
line-height: 1; | ||
} | ||
.date { | ||
margin: 0; | ||
color: rgb(var(--gray)); | ||
} | ||
ul li a:hover h4, | ||
ul li a:hover .date { | ||
color: rgb(var(--accent)); | ||
} | ||
ul a:hover img { | ||
box-shadow: var(--box-shadow); | ||
} | ||
@media (max-width: 720px) { | ||
ul { | ||
gap: 0.5em; | ||
} | ||
ul li { | ||
width: 100%; | ||
text-align: center; | ||
} | ||
ul li:first-child { | ||
margin-bottom: 0; | ||
} | ||
ul li:first-child .title { | ||
font-size: 1.563em; | ||
} | ||
} | ||
</style> | ||
<section> | ||
<ul> | ||
{ | ||
posts.map((post) => ( | ||
<li> | ||
<a href={`${locale !== 'en' ? '/' + locale : ''}/posts/${post.slug}/`}> | ||
<img width={720} height={360} src={post.data.heroImage} alt="" /> | ||
<h4 class="title">{post.data.title}</h4> | ||
<p class="date"> | ||
<FormattedDate date={post.data.pubDate} /> | ||
</p> | ||
</a> | ||
</li> | ||
)) | ||
} | ||
</ul> | ||
</section> | ||
</DefaultLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { getCollection } from 'astro:content'; | ||
|
||
import type { SupportedLocale } from '@/types'; | ||
|
||
async function resolvePosts(locale: SupportedLocale) { | ||
return (await getCollection('posts')) | ||
.filter(post => { | ||
const parts = post.slug.split('/'); | ||
|
||
return locale === 'en' ? parts.length === 1 : parts.length === 2 && parts[0] === locale; | ||
}) | ||
.map(({ slug, ...others }) => { | ||
const parts = slug.split('/'); | ||
|
||
if (parts.length > 1) { | ||
parts.shift(); | ||
} | ||
|
||
return { ...others, slug: parts.join('/') }; | ||
}); | ||
} | ||
|
||
export { resolvePosts }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export { resolvePosts } from './helper'; | ||
export { default } from './PostLayout.astro'; | ||
export { default as IndexLayout } from './IndexLayout.astro'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
import { type CollectionEntry, render } from 'astro:content'; | ||
import PostLayout, { resolvePosts } from '#/layouts/post'; | ||
export async function getStaticPaths() { | ||
return (await resolvePosts('en')).map(post => ({ | ||
params: { slug: post.slug }, | ||
props: post, | ||
})); | ||
} | ||
type Props = CollectionEntry<'posts'>; | ||
const post = Astro.props; | ||
const { Content } = await render(post); | ||
--- | ||
|
||
<PostLayout {...post.data}> | ||
<Content /> | ||
</PostLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
import { IndexLayout } from '#/layouts/post'; | ||
--- | ||
|
||
<IndexLayout /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
import { type CollectionEntry, render } from 'astro:content'; | ||
import PostLayout, { resolvePosts } from '#/layouts/post'; | ||
export async function getStaticPaths() { | ||
return (await resolvePosts('zh')).map(post => ({ | ||
params: { slug: post.slug }, | ||
props: post, | ||
})); | ||
} | ||
type Props = CollectionEntry<'posts'>; | ||
const post = Astro.props; | ||
const { Content } = await render(post); | ||
--- | ||
|
||
<PostLayout {...post.data}> | ||
<Content /> | ||
</PostLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
import { IndexLayout } from '#/layouts/post'; | ||
--- | ||
|
||
<IndexLayout /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters