Skip to content

Commit

Permalink
[Docs Site] Fix ExternalResources cloudflareOnly prop (#17367)
Browse files Browse the repository at this point in the history
* [Docs Site] Fix ExternalResources cloudflareOnly prop

* Apply suggestions from code review
  • Loading branch information
KianNH authored Oct 7, 2024
1 parent f931f3f commit 54af015
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/components/ExternalResources.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ const props = z.object({
type: z.enum(["apps", "videos"]),
tags: z.string().array().optional(),
products: z.string().array().optional(),
cloudflare: z.boolean().default(true),
cloudflareOnly: z.boolean().default(true),
});
const { type, tags, products, cloudflare } = props.parse(Astro.props);
const { type, tags, products, cloudflareOnly } = props.parse(Astro.props);
const resources = await getEntry(type, "index");
const filtered = resources.data.entries.filter((entry) => {
return (
(cloudflare ? entry.cloudflare : false) &&
(cloudflareOnly ? entry.cloudflare : true) &&
(tags ? entry.tags?.some((v: string) => tags.includes(v)) : true) &&
(products
? entry.products?.some((v: string) => products.includes(v))
Expand All @@ -35,8 +35,8 @@ filtered.sort((a, b) => Number(b.updated) - Number(a.updated));
return (
<li>
<>
<a href={entry.link}>{title}</a>
<span>: {entry.description}</span>
<a href={entry.link}>{title}:</a>
<span>{entry.description}</span>
</>
</li>
);
Expand Down
42 changes: 41 additions & 1 deletion src/content/docs/style-guide/components/external-resources.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
title: External resources
---

The `ExternalResources` component pulls from a central list of [apps](https://github.com/cloudflare/cloudflare-docs/blob/production/src/content/apps/index.yaml) and [videos](https://github.com/cloudflare/cloudflare-docs/blob/production/src/content/videos/index.yaml).

## Import

```mdx
import { ExternalResources } from "~/components";
```

## Preview

```mdx live
import { ExternalResources } from "~/components";

Expand All @@ -10,4 +20,34 @@ import { ExternalResources } from "~/components";

## Videos
<ExternalResources type="videos" tags={["AI"]} />
```
```

## Props

### `type`

**required**

**type:** `"apps" | "videos"`

The type of resources to show, apps or videos.

### `tags`

**type:** `string[]`

Filter resources down to those where the `tags` property contains any of these strings.

### `products`

**type:** `string[]`

Filter resources down to those where the `products` property contains any of these strings.

### `cloudflareOnly`

**type:** `boolean`

**default:** `true`

Filter resources down to those with `cloudflare: true`.

0 comments on commit 54af015

Please sign in to comment.