Skip to content

Commit c20b900

Browse files
committed
Create created updated time component and refactor
1 parent 02f68a9 commit c20b900

3 files changed

Lines changed: 25 additions & 11 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
import Time from "@components/time.astro";
3+
4+
type Props = { created: Date; updated: Date; class?: string };
5+
const { created, updated, class: className } = Astro.props;
6+
---
7+
8+
<p class={className}>
9+
Created: <Time date={created} /> | Updated: <Time date={updated} />
10+
</p>

src/components/post-item.astro

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
import Time from "@components/time.astro";
2+
import CreatedUpdatedTime from "./created-updated-time.astro";
33
44
type Props = {
55
title: string;
@@ -12,9 +12,11 @@ const { title, link, dateCreated, dateUpdated } = Astro.props;
1212

1313
<li>
1414
<p><a href={link}>{title}</a></p>
15-
<p class="small-text">
16-
Created: <Time date={dateCreated} /> | Updated: <Time date={dateUpdated} />
17-
</p>
15+
<CreatedUpdatedTime
16+
class="small-text"
17+
created={dateCreated}
18+
updated={dateUpdated}
19+
/>
1820
</li>
1921

2022
<style lang="scss">

src/pages/notes/[slug].astro

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { CollectionEntry } from "astro:content";
33
44
import { getCollection } from "astro:content";
55
6-
import Time from "@components/time.astro";
6+
import CreatedUpdatedTime from "@components/created-updated-time.astro";
77
import Article from "@layout/article.astro";
88
import Page from "@layout/page.astro";
99
@@ -17,15 +17,17 @@ export async function getStaticPaths() {
1717
type Props = { note: CollectionEntry<"notes"> };
1818
const { note } = Astro.props;
1919
const { Content } = await note.render();
20+
const { title, dateCreated, dateUpdated } = note.data;
2021
---
2122

22-
<Page title={note.data.title}>
23+
<Page title={title}>
2324
<Article>
24-
<h1 class="smaller-spacing">{note.data.title}</h1>
25-
<p class="small-text larger-spacing">
26-
Created: <Time date={note.data.dateCreated} /> | Updated:
27-
<Time date={note.data.dateUpdated} />
28-
</p>
25+
<h1 class="smaller-spacing">{title}</h1>
26+
<CreatedUpdatedTime
27+
class="small-text larger-spacing"
28+
created={dateCreated}
29+
updated={dateUpdated}
30+
/>
2931
<Content />
3032
</Article>
3133
</Page>

0 commit comments

Comments
 (0)