Skip to content

Commit f4097ff

Browse files
authored
[Docs Site] Refactor partials property validation and docs (#19887)
* [Docs Site] Refactor partials property validation and docs * update partial examples * fix partials that would fail validation * fix partial
1 parent 2505d02 commit f4097ff

File tree

42 files changed

+355
-147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+355
-147
lines changed

astro.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import starlightLinksValidator from "starlight-links-validator";
88
import icon from "astro-icon";
99
import sitemap from "@astrojs/sitemap";
1010
import react from "@astrojs/react";
11+
1112
import { readdir } from "fs/promises";
13+
import { fileURLToPath } from "url";
1214

1315
import rehypeTitleFigure from "rehype-title-figure";
1416
import rehypeMermaid from "./src/plugins/rehype/mermaid.ts";
1517
import rehypeAutolinkHeadings from "./src/plugins/rehype/autolink-headings.ts";
1618
import rehypeExternalLinks from "./src/plugins/rehype/external-links.ts";
1719
import rehypeHeadingSlugs from "./src/plugins/rehype/heading-slugs.ts";
18-
import { fileURLToPath } from "url";
1920

2021
async function autogenSections() {
2122
const sections = (

src/components/Render.astro

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,49 @@ const props = z.object({
1313
let { file, product, params } = props.parse(Astro.props);
1414
1515
if (!product) {
16-
product = Astro.params.slug?.split("/")[0];
17-
}
16+
const fromSlug = Astro.params.slug?.split("/")[0];
1817
19-
if (!product) {
20-
throw new Error(
21-
`[Render] Unable to infer which folder ${file} is in, please provide a "product" input with your "file" input.`,
22-
);
18+
if (!fromSlug) {
19+
throw new Error(
20+
`[Render] Unable to infer which folder ${file} is in, please provide a "product" input with your "file" input.`,
21+
);
22+
}
23+
24+
product = fromSlug;
2325
}
2426
25-
const partial = await getEntry("partials", `${product}/${file}`);
27+
const id = `${product}/${file}`;
28+
const partial = await getEntry("partials", id);
2629
2730
if (!partial) {
2831
throw new Error(
29-
`[Render] Couldn't find partial: ${file}. Included on ${Astro.params.slug}`,
32+
`[Render] Couldn't find "${id}" included on "${Astro.url.pathname}"`,
3033
);
3134
}
3235
36+
// We currently only enforce parameters if `params` is set in the frontmatter,
37+
// until we can migrate existing `inputParameters` frontmatter to `params`.
3338
if (partial.data.params) {
34-
const expected = partial.data.params;
35-
if (!params)
39+
const expected = partial.data.params.sort();
40+
const optional = expected.filter((p) => p.endsWith("?"));
41+
const received = Object.keys(params ?? {}).sort();
42+
43+
const maximum = expected.length;
44+
const minimum = maximum - optional.length;
45+
46+
if (
47+
received.length < minimum ||
48+
received.length > maximum ||
49+
expected.some((p: string) => {
50+
if (p.endsWith("?")) return false;
51+
52+
return !received.includes(p);
53+
})
54+
) {
3655
throw new Error(
37-
`${file} included on ${Astro.params.slug} expected parameters: ${expected}, got none`,
56+
`[Render] Expected parameters ${JSON.stringify(expected)} but received parameters ${JSON.stringify(received)} for "${file}" included on "${Astro.url.pathname}"`,
3857
);
58+
}
3959
}
4060
4161
const { Content } = await render(partial);

src/content.config.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { z, defineCollection } from "astro:content";
1+
import { defineCollection } from "astro:content";
22

33
import { docsLoader, i18nLoader } from "@astrojs/starlight/loaders";
44
import { docsSchema, i18nSchema } from "@astrojs/starlight/schema";
@@ -20,6 +20,7 @@ import {
2020
warpReleasesSchema,
2121
releaseNotesSchema,
2222
fieldsSchema,
23+
partialsSchema,
2324
} from "~/schemas";
2425

2526
function contentLoader(name: string) {
@@ -36,10 +37,6 @@ function dataLoader(name: string) {
3637
});
3738
}
3839

39-
const partialSchema = z.object({
40-
params: z.string().array().optional(),
41-
});
42-
4340
export const collections = {
4441
docs: defineCollection({
4542
loader: docsLoader(),
@@ -61,7 +58,7 @@ export const collections = {
6158
}),
6259
partials: defineCollection({
6360
loader: contentLoader("partials"),
64-
schema: partialSchema,
61+
schema: partialsSchema,
6562
}),
6663
glossary: defineCollection({
6764
loader: dataLoader("glossary"),

src/content/docs/cloudflare-one/applications/casb/casb-integrations/atlassian-confluence.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { Render } from "~/components";
99
<Render
1010
file="casb/integration-description"
1111
params={{
12-
one: "Atlassian Confluence",
13-
two: "Atlassian Confluence Cloud account",
12+
integrationName: "Atlassian Confluence",
13+
integrationAccountType: "Atlassian Confluence Cloud account",
1414
}}
1515
/>
1616

@@ -43,7 +43,7 @@ These permissions follow the principle of least privilege to ensure that only th
4343

4444
<Render
4545
file="casb/security-findings"
46-
params={{ one: "Atlassian Confluence", two: "atlassian-confluence" }}
46+
params={{ integrationName: "Atlassian Confluence", slugRelativePath: "atlassian-confluence" }}
4747
/>
4848

4949
### Access security

src/content/docs/cloudflare-one/applications/casb/casb-integrations/atlassian-jira.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Render } from "~/components";
88

99
<Render
1010
file="casb/integration-description"
11-
params={{ one: "Atlassian Jira", two: "Atlassian Jira Cloud account" }}
11+
params={{ integrationName: "Atlassian Jira", integrationAccountType: "Atlassian Jira Cloud account" }}
1212
/>
1313

1414
:::note
@@ -35,7 +35,7 @@ These permissions follow the principle of least privilege to ensure that only th
3535

3636
<Render
3737
file="casb/security-findings"
38-
params={{ one: "Jira Cloud", two: "atlassian-jira" }}
38+
params={{ integrationName: "Jira Cloud", slugRelativePath: "atlassian-jira" }}
3939
/>
4040

4141
### Access security

src/content/docs/cloudflare-one/applications/casb/casb-integrations/aws-s3.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Render } from "~/components";
88

99
<Render
1010
file="casb/integration-description"
11-
params={{ one: "Amazon Web Services (AWS) S3", two: "AWS account" }}
11+
params={{ integrationName: "Amazon Web Services (AWS) S3", integrationAccountType: "AWS account" }}
1212
/>
1313

1414
## Integration prerequisites
@@ -65,7 +65,7 @@ For more information, refer to [Content findings](/cloudflare-one/applications/c
6565

6666
<Render
6767
file="casb/security-findings"
68-
params={{ one: "AWS S3", two: "aws-s3" }}
68+
params={{ integrationName: "AWS S3", slugRelativePath: "aws-s3" }}
6969
/>
7070

7171
### S3 Bucket security

src/content/docs/cloudflare-one/applications/casb/casb-integrations/bitbucket-cloud.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Render } from "~/components";
88

99
<Render
1010
file="casb/integration-description"
11-
params={{ one: "Bitbucket Cloud", two: "Bitbucket Cloud Cloud account" }}
11+
params={{ integrationName: "Bitbucket Cloud", integrationAccountType: "Bitbucket Cloud Cloud account" }}
1212
/>
1313

1414
:::note
@@ -46,7 +46,7 @@ These permissions follow the principle of least privilege to ensure that only th
4646

4747
<Render
4848
file="casb/security-findings"
49-
params={{ one: "Bitbucket Cloud", two: "bitbucket-cloud" }}
49+
params={{ integrationName: "Bitbucket Cloud", slugRelativePath: "bitbucket-cloud" }}
5050
/>
5151

5252
### Repository security

src/content/docs/cloudflare-one/applications/casb/casb-integrations/box.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Render } from "~/components";
88

99
<Render
1010
file="casb/integration-description"
11-
params={{ one: "Box", two: "Box account" }}
11+
params={{ integrationName: "Box", integrationAccountType: "Box account" }}
1212
/>
1313

1414
## Integration prerequisites
@@ -27,7 +27,7 @@ These permissions follow the principle of least privilege to ensure that only th
2727

2828
## Security findings
2929

30-
<Render file="casb/security-findings" params={{ one: "Box", two: "box" }} />
30+
<Render file="casb/security-findings" params={{ integrationName: "Box", slugRelativePath: "box" }} />
3131

3232
### File sharing
3333

src/content/docs/cloudflare-one/applications/casb/casb-integrations/dropbox.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Render } from "~/components";
88

99
<Render
1010
file="casb/integration-description"
11-
params={{ one: "Dropbox", two: "Dropbox account" }}
11+
params={{ integrationName: "Dropbox", integrationAccountType: "Dropbox account" }}
1212
/>
1313

1414
## Integration prerequisites
@@ -39,7 +39,7 @@ These permissions follow the principle of least privilege to ensure that only th
3939

4040
<Render
4141
file="casb/security-findings"
42-
params={{ one: "Dropbox", two: "dropbox" }}
42+
params={{ integrationName: "Dropbox", slugRelativePath: "dropbox" }}
4343
/>
4444

4545
### File and folder sharing

src/content/docs/cloudflare-one/applications/casb/casb-integrations/github.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Render } from "~/components";
1111

1212
<Render
1313
file="casb/integration-description"
14-
params={{ one: "GitHub", two: "GitHub Organization" }}
14+
params={{ integrationName: "GitHub", integrationAccountType: "GitHub Organization" }}
1515
/>
1616

1717
## Integration prerequisites
@@ -36,7 +36,7 @@ These permissions follow the principle of least privilege to ensure that only th
3636

3737
<Render
3838
file="casb/security-findings"
39-
params={{ one: "GitHub", two: "github" }}
39+
params={{ integrationName: "GitHub", slugRelativePath: "github" }}
4040
/>
4141

4242
### Branches and merges

0 commit comments

Comments
 (0)