Skip to content

Commit 775e8e7

Browse files
committed
Add optional showLastUpdated property
1 parent 62f8e6a commit 775e8e7

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/components/ResourcesBySelector.astro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const props = z.object({
1818
filterables: z.custom<ResourcesData>().array().optional(),
1919
columns: z.union([z.literal(2), z.literal(3)]).default(2),
2020
showDescriptions: z.boolean().default(true),
21+
showLastUpdated: z.boolean().default(false),
2122
});
2223
2324
const {
@@ -28,6 +29,7 @@ const {
2829
filterables,
2930
columns,
3031
showDescriptions,
32+
showLastUpdated,
3133
} = props.parse(Astro.props);
3234
3335
const docs = await getCollection("docs");
@@ -78,6 +80,7 @@ const facets = resources.reduce(
7880
filters={filterables}
7981
columns={columns}
8082
showDescriptions={showDescriptions}
83+
showLastUpdated={showLastUpdated}
8184
client:load
8285
/>
8386
</div>

src/components/ResourcesBySelector.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useEffect, useState } from "react";
22
import ReactSelect from "./ReactSelect";
33
import type { CollectionEntry } from "astro:content";
4+
import { formatDistance } from "date-fns";
45

56
type DocsData = keyof CollectionEntry<"docs">["data"];
67
type VideosData = keyof CollectionEntry<"stream">["data"];
@@ -13,6 +14,7 @@ interface Props {
1314
filters?: ResourcesData[];
1415
columns: number;
1516
showDescriptions: boolean;
17+
showLastUpdated: boolean;
1618
}
1719

1820
export default function ResourcesBySelector({
@@ -21,9 +23,15 @@ export default function ResourcesBySelector({
2123
filters,
2224
columns,
2325
showDescriptions,
26+
showLastUpdated,
2427
}: Props) {
2528
const [selectedFilter, setSelectedFilter] = useState<string | null>(null);
2629

30+
const timeAgo = (date?: Date) => {
31+
if (!date) return undefined;
32+
return formatDistance(date, new Date(), { addSuffix: true });
33+
};
34+
2735
const handleFilterChange = (option: any) => {
2836
setSelectedFilter(option?.value || null);
2937
};
@@ -116,6 +124,11 @@ export default function ResourcesBySelector({
116124
{page.data.description}
117125
</span>
118126
)}
127+
{showLastUpdated && (
128+
<span className="line-clamp-3" title={page.data.description}>
129+
Updated {timeAgo(page.data.updated)}
130+
</span>
131+
)}
119132
</a>
120133
);
121134
})}

src/content/docs/r2/tutorials/index.mdx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@ sidebar:
66
order: 9
77
---
88

9-
import { GlossaryTooltip, ListTutorials, YouTubeVideos } from "~/components";
9+
import {
10+
GlossaryTooltip,
11+
ResourcesBySelector,
12+
YouTubeVideos,
13+
} from "~/components";
1014

1115
View <GlossaryTooltip term="tutorial">tutorials</GlossaryTooltip> to help you get started with R2.
1216

1317
## Docs
1418

15-
<ListTutorials />
19+
<ResourcesBySelector
20+
directory="r2"
21+
types={["tutorial"]}
22+
showLastUpdated={true}
23+
/>
1624

1725
## Videos
1826

0 commit comments

Comments
 (0)