diff options
| author | houston[bot] <astrobot-houston@users.noreply.github.com> | 2023-07-22 12:57:20 -0700 |
|---|---|---|
| committer | Pinapelz <donaldshan1@outlook.com> | 2023-07-22 12:57:20 -0700 |
| commit | 338bcf12e0b7bbd6e587ec992e62860642856e80 (patch) | |
| tree | 280c106666221697a40c13603a91ee4c696e0bfb /src/pages/blog | |
Initial commit from Astro
Diffstat (limited to 'src/pages/blog')
| -rw-r--r-- | src/pages/blog/[...slug].astro | 21 | ||||
| -rw-r--r-- | src/pages/blog/index.astro | 54 |
2 files changed, 75 insertions, 0 deletions
diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro new file mode 100644 index 0000000..0d656a1 --- /dev/null +++ b/src/pages/blog/[...slug].astro @@ -0,0 +1,21 @@ +--- +import { CollectionEntry, getCollection } from 'astro:content'; +import BlogPost from '../../layouts/BlogPost.astro'; + +export async function getStaticPaths() { + const posts = await getCollection('blog'); + return posts.map((post) => ({ + params: { slug: post.slug }, + props: post, + })); +} +type Props = CollectionEntry<'blog'>; + +const post = Astro.props; +const { Content } = await post.render(); +--- + +<BlogPost {...post.data}> + <h1>{post.data.title}</h1> + <Content /> +</BlogPost> diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro new file mode 100644 index 0000000..47126e7 --- /dev/null +++ b/src/pages/blog/index.astro @@ -0,0 +1,54 @@ +--- +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'; +import FormattedDate from '../../components/FormattedDate.astro'; + +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 :global(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> + <FormattedDate date={post.data.pubDate} /> + <a href={`/blog/${post.slug}/`}>{post.data.title}</a> + </li> + )) + } + </ul> + </section> + </main> + <Footer /> + </body> +</html> |
