Skip to content

Commit 3eb1147

Browse files
Oxyjunkodster28
andauthored
[Docs Site] Using ResourceBySelector component where possible (#24389)
* Replacing ListExamples with ResourceBySelector. * Add optional showLastUpdated property * tweaks to schema * Ensuring example directory is always specified * Removing style guide page for ListExamples * Keeping ListTutorials for now * remove component and import * component def tweaks --------- Co-authored-by: kodster28 <[email protected]>
1 parent 526f39f commit 3eb1147

File tree

28 files changed

+76
-242
lines changed

28 files changed

+76
-242
lines changed

src/components/ListExamples.astro

Lines changed: 0 additions & 182 deletions
This file was deleted.

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: 14 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
};
@@ -91,6 +99,7 @@ export default function ResourcesBySelector({
9199
? `/videos/${page.data.url}/`
92100
: `/${page.id}/`;
93101

102+
// title can either be set directly in title or added as a meta.title property when we want something different for sidebar and SEO titles
94103
let title;
95104

96105
if (page.collection === "docs") {
@@ -116,6 +125,11 @@ export default function ResourcesBySelector({
116125
{page.data.description}
117126
</span>
118127
)}
128+
{showLastUpdated && (
129+
<span className="line-clamp-3" title={page.data.description}>
130+
Updated {timeAgo(page.data.updated)}
131+
</span>
132+
)}
119133
</a>
120134
);
121135
})}

src/components/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export { default as HomepageHero } from "./HomepageHero.astro";
2929
export { default as InlineBadge } from "./InlineBadge.astro";
3030
export { default as LastReviewed } from "./LastReviewed.astro";
3131
export { default as LinkTitleCard } from "./LinkTitleCard.astro";
32-
export { default as ListExamples } from "./ListExamples.astro";
3332
export { default as ListTutorials } from "./ListTutorials.astro";
3433
export { default as Markdown } from "./Markdown.astro";
3534
export { default as MetaInfo } from "./MetaInfo.astro";

src/content/docs/cloudflare-one/api-terraform/access-api-examples/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebar:
66
order: 1
77
---
88

9-
import { ListExamples } from "~/components";
9+
import { ResourcesBySelector } from "~/components";
1010

1111
You can use the Cloudflare Access API to create policies, including individual rule blocks inside of group or policy bodies. For example, this policy allows all Cloudflare email account users to reach the application with the exception of one account:
1212

@@ -34,4 +34,4 @@ You can use the Cloudflare Access API to create policies, including individual r
3434

3535
## Example rule configurations
3636

37-
<ListExamples directory="cloudflare-one/api-terraform/access-api-examples/" />
37+
<ResourcesBySelector directory="cloudflare-one/api-terraform/access-api-examples/" types={["example"]} />

src/content/docs/containers/examples/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ sidebar:
77
order: 3
88
---
99

10-
import { GlossaryTooltip, ListExamples } from "~/components";
10+
import { GlossaryTooltip, ResourcesBySelector } from "~/components";
1111

1212
Explore the following examples of Container functionality:
1313

14-
<ListExamples directory="containers/examples" />
14+
<ResourcesBySelector directory="containers/examples/" types={["example"]} />

src/content/docs/d1/examples/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ sidebar:
99
hideIndex: true
1010
---
1111

12-
import { GlossaryTooltip, ListExamples } from "~/components";
12+
import { GlossaryTooltip, ResourcesBySelector } from "~/components";
1313

1414
Explore the following <GlossaryTooltip term="code example">examples</GlossaryTooltip> for D1.
1515

16-
<ListExamples directory="d1/examples/" />
16+
<ResourcesBySelector directory="d1/examples/" types={["example"]} />

src/content/docs/durable-objects/examples/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ sidebar:
77
hideIndex: true
88
---
99

10-
import { ListExamples, GlossaryTooltip } from "~/components";
10+
import { ResourcesBySelector, GlossaryTooltip } from "~/components";
1111

1212
Explore the following <GlossaryTooltip term="code example">examples</GlossaryTooltip> for Durable Objects.
1313

14-
<ListExamples />
14+
<ResourcesBySelector types={["example"]} directory="durable-objects/examples/" />

src/content/docs/images/examples/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ sidebar:
77
order: 11
88
---
99

10-
import { ListExamples } from "~/components";
10+
import { ResourcesBySelector } from "~/components";
1111

12-
<ListExamples directory="images/examples/" />
12+
<ResourcesBySelector directory="images/examples/" types={["example"]} />

src/content/docs/kv/examples/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ sidebar:
99
hideIndex: true
1010
---
1111

12-
import { GlossaryTooltip, ListExamples } from "~/components";
12+
import { GlossaryTooltip, ResourcesBySelector } from "~/components";
1313

1414
Explore the following <GlossaryTooltip term="code example">examples</GlossaryTooltip> for KV.
1515

16-
<ListExamples directory="kv/examples/" />
16+
<ResourcesBySelector directory="kv/examples/" types={["example"]} />

0 commit comments

Comments
 (0)