Skip to content

Commit d77aaaf

Browse files
committed
migrate changelogs
1 parent 203a984 commit d77aaaf

Some content is hidden

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

61 files changed

+675
-734
lines changed

astro.config.ts

Lines changed: 3 additions & 2 deletions
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-
import { readdir } from "fs/promises";
11+
12+
import { readdir } from "node:fs/promises";
13+
import { fileURLToPath } from "node: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 = (

bin/migrate-changelogs.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import dedent from "dedent";
2+
import {
3+
readFile,
4+
readdir,
5+
mkdir,
6+
writeFile,
7+
access,
8+
constants,
9+
} from "fs/promises";
10+
import { parse, stringify } from "yaml";
11+
import { slug } from "github-slugger";
12+
13+
const files = await readdir("./src/content/changelogs/", {
14+
withFileTypes: true,
15+
});
16+
17+
for (const file of files) {
18+
const withoutExt = file.name.split(".")[0];
19+
20+
const content = await readFile(file.parentPath.concat(file.name), {
21+
encoding: "utf-8",
22+
});
23+
24+
const { productName, productLink, productArea, entries } = parse(content);
25+
26+
const productFile = "./src/content/products/".concat(file.name);
27+
try {
28+
await access(productFile, constants.F_OK);
29+
} catch {
30+
const productYaml = stringify({
31+
name: productName,
32+
product: {
33+
title: productName,
34+
url: productLink,
35+
group: productArea,
36+
},
37+
});
38+
39+
await writeFile(productFile, productYaml, { encoding: "utf-8" });
40+
}
41+
42+
for (const entry of entries) {
43+
if (!entry.description) {
44+
continue;
45+
}
46+
47+
const title = entry.title ?? `Changelog for ${entry.publish_date}`;
48+
const description =
49+
entry.title ?? ` ${productName} changelog for ${entry.publish_date}`;
50+
const date = new Date(entry.publish_date).toISOString();
51+
const products = [withoutExt];
52+
53+
const frontmatter = {
54+
title,
55+
description,
56+
date,
57+
products,
58+
};
59+
60+
const body = entry.description;
61+
62+
const content = dedent`
63+
---
64+
${stringify(frontmatter, { lineWidth: 0 }).trim()}
65+
---
66+
67+
${body}
68+
`;
69+
70+
const folder = `./src/content/changelogs-next/${withoutExt}/`;
71+
72+
await mkdir(folder, {
73+
recursive: true,
74+
});
75+
76+
let path = folder.concat(date.slice(0, 10));
77+
78+
if (entry.title) {
79+
path = path.concat(`-${slug(entry.title)}`);
80+
}
81+
82+
path = path.concat(".mdx");
83+
84+
await writeFile(path, content, { encoding: "utf-8" });
85+
}
86+
}

public/_redirects

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
/tutorials/ /search/?content_type%5B0%5D=Tutorial 301
66
/sitemap.xml /sitemap-index.xml
77

8+
# changelogs
9+
10+
## areas
11+
/cloudflare-one/changelog/index.xml /changelog-next/rss/index.xml 301
12+
/fundamentals/reference/changelog/performance/index.xml changelog-next/rss/index.xml 301
13+
/fundamentals/reference/changelog/platform/index.xml changelog-next/rss/index.xml 301
14+
/fundamentals/reference/changelog/security/index.xml changelog-next/rss/index.xml 301
15+
/workers/platform/changelog/platform/index.xml /changelog-next/rss/index.xml 301
16+
17+
## products
18+
/cloudflare-one/changelog/access/index.xml /changelog-next/rss/access.xml 301
19+
820
# 1dot1_redirect
921
/1.1.1.1/1.1.1.1-for-families/ /1.1.1.1/setup/ 301
1022
/1.1.1.1/1.1.1.1-for-families/android/ /1.1.1.1/setup/android/ 301
Lines changed: 18 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,36 @@
1-
---
2-
import { getEntry, type CollectionEntry } from "astro:content";
3-
import { marked } from "marked";
1+
<!-- ---
42
import { getChangelogs } from "~/util/changelogs";
5-
import AnchorHeading from "~/components/AnchorHeading.astro";
6-
import { entryToString } from "~/util/container";
3+
import { getEntry } from "astro:content";
74
85
const page = await getEntry("docs", Astro.params.slug!);
96
107
if (!page) {
118
throw new Error(
12-
`[ProductChangelog] Failed to find entry for ${Astro.params.slug}.`,
9+
`[ProductChangelog] Unable to find entry for ${Astro.params.slug}`,
1310
);
1411
}
1512
16-
if (!page.data.changelog_file_name && !page.data.changelog_product_area_name) {
17-
throw new Error(
18-
`[ProductChangelog] ${Astro.params.slug} does not have a 'changelog_file_name' or 'changaelog_product_area_name' frontmatter property.`,
19-
);
20-
}
13+
const { changelog } = page.data;
2114
22-
if (page.data.changelog_file_name && page.data.changelog_file_name.length > 1) {
15+
if (!changelog || !changelog.products) {
2316
throw new Error(
24-
`[ProductChangelog] This component cannot be used on files that have more than 1 entry in their 'changelog_file_name' frontmatter property.`,
17+
`[ProductChangelog] ${Astro.params.slug} must have a "changelog" entry in frontmatter`,
2518
);
2619
}
2720
28-
const name =
29-
page.data.changelog_product_area_name ?? page.data.changelog_file_name?.[0];
30-
31-
let changelogs;
32-
33-
if (page.data.changelog_product_area_name) {
34-
const opts = {
35-
filter: (entry: CollectionEntry<"changelogs">) => {
36-
return entry.data.productArea === name;
37-
},
38-
};
39-
({ changelogs } = await getChangelogs(opts));
40-
} else {
41-
if (name === "wrangler") {
42-
const opts = {
43-
wranglerOnly: true,
44-
};
45-
({ changelogs } = await getChangelogs(opts));
46-
} else if (name === "api-deprecations") {
47-
const opts = {
48-
deprecationsOnly: true,
49-
};
50-
({ changelogs } = await getChangelogs(opts));
51-
} else {
52-
const opts = {
53-
filter: (entry: CollectionEntry<"changelogs">) => {
54-
return entry.id === name;
55-
},
56-
};
57-
({ changelogs } = await getChangelogs(opts));
58-
}
59-
}
60-
61-
if (!changelogs) {
62-
throw new Error(
63-
`[ProductChangelog] Failed to find changelog called ${name}.`,
64-
);
65-
}
21+
const changelogs = await getChangelogs({
22+
filter: (e) => {
23+
return e.data.products.some((p) =>
24+
changelog.products?.some((v) => v.id === p.id),
25+
);
26+
},
27+
});
6628
---
6729
6830
{
69-
page.data.pcx_content_type === "changelog" && (
70-
<p>
71-
<a href={`/${page.id}/index.xml`} target="_blank">
72-
Subscribe to RSS
73-
</a>
74-
</p>
75-
)
76-
}
77-
{
78-
changelogs.map(([date, entries]) => (
79-
<div data-date={date}>
80-
{(entries ?? []).map(async (entry) => {
81-
let description;
82-
if (entry.individual_page) {
83-
const link = entry.individual_page;
84-
85-
if (!link)
86-
throw new Error(
87-
`Changelog entry points to individual page but no link is provided`,
88-
);
89-
90-
const page = await getEntry("docs", link.slice(1, -1));
91-
92-
if (!page)
93-
throw new Error(
94-
`Changelog entry points to ${link.slice(1, -1)} but unable to find entry with that slug`,
95-
);
96-
97-
description = (await entryToString(page, Astro.locals)) ?? page.body;
98-
99-
return (
100-
<div data-product={entry.product.toLowerCase()}>
101-
<a href={entry.individual_page} class="no-underline">
102-
<AnchorHeading depth={2} title={page.data.title} />
103-
</a>
104-
<p class="text-xs">{entry.date}</p>
105-
{page.data.changelog_product_area_name && (
106-
<h3 class="!mt-4">
107-
<a href={entry.productLink}>{entry.product}</a>
108-
</h3>
109-
)}
110-
{<Fragment set:html={description} />}
111-
</div>
112-
);
113-
} else {
114-
description = marked.parse(entry.description as string);
115-
return (
116-
<>
117-
<AnchorHeading depth={2} title={date} />
118-
<div data-product={entry.product.toLowerCase()}>
119-
{page.data.changelog_product_area_name && (
120-
<h3 class="!mt-4">
121-
<a href={entry.productLink}>{entry.product}</a>
122-
</h3>
123-
)}
124-
{entry.title && <strong>{entry.title}</strong>}
125-
{<Fragment set:html={description} />}
126-
</div>
127-
</>
128-
);
129-
}
130-
})}
131-
</div>
31+
changelogs.map((entry) => (
32+
<h3>{entry.data.date.toISOString().slice(0, 10)}</h3>
33+
<h4>{entry.data.description}</h4>
34+
<p>For more information, refer to the <a href={entry.data.link}>dedicated changelog post</a>.</p>
13235
))
133-
}
36+
} -->

src/content.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function contentLoader(name: string) {
3131

3232
function dataLoader(name: string) {
3333
return glob({
34-
pattern: "**/*.(json|yml|yaml)",
34+
pattern: "**/*.(json|yaml)",
3535
base: "./src/content/" + name,
3636
});
3737
}

src/content/docs/ai-gateway/changelog.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
---
22
pcx_content_type: changelog
33
title: Changelog
4-
changelog_file_name:
5-
- ai-gateway
64
sidebar:
75
order: 9
6+
changelog:
7+
products:
8+
- changelog_file_name
89
---
910

1011
import { ProductChangelog } from "~/components";

src/content/docs/ddos-protection/change-log/http/scheduled-changes.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ sidebar:
66
head:
77
- tag: title
88
content: Scheduled changes — HTTP DDoS
9-
9+
changelog:
10+
date: 2024-04-29
1011
---
1112

1213
import { RuleID } from "~/components"

src/content/docs/ddos-protection/change-log/network/scheduled-changes.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ sidebar:
66
head:
77
- tag: title
88
content: Scheduled changes — Network-layer DDoS
9-
9+
changelog:
10+
date: 2024-10-10
1011
---
1112

1213

src/content/docs/waf/change-log/historical-2018.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ head: []
77
description: Changes to WAF managed rulesets done in 2018, before the public
88
changelog was available.
99
tableOfContents: false
10+
changelog:
11+
date: 2018-12-31
1012
---
1113

1214
<table style="width: 100%">

src/content/docs/waf/change-log/historical-2019.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ sidebar:
66
head: []
77
description: Changes to WAF managed rulesets done in 2019.
88
tableOfContents: false
9+
changelog:
10+
date: 2019-12-31
911
---
1012

1113
<table style="width: 100%">

0 commit comments

Comments
 (0)