Skip to content

Commit d5a19de

Browse files
authored
[Docs Site] Stringify vendored Markdown frontmatter as proper YAML (#23670)
1 parent 748d973 commit d5a19de

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

src/content/docs/style-guide/fixtures/markdown.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sidebar:
88

99
import { Tabs, TabItem } from "~/components";
1010

11-
The HTML generated by this file is used as a test fixture for our Markdown generation.
11+
The HTML generated by this file is used as a test fixture for our Markdown generation:
1212

1313
<Tabs>
1414
<TabItem label="mdx">

src/util/markdown.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { parse } from "node-html-parser";
22
import { process } from "../util/rehype";
33

4+
import YAML from "yaml";
5+
46
import rehypeParse from "rehype-parse";
57
import rehypeBaseUrl from "../plugins/rehype/base-url";
68
import rehypeFilterElements from "../plugins/rehype/filter-elements";
@@ -39,14 +41,17 @@ export async function htmlToMarkdown(
3941

4042
const withFrontmatter = [
4143
"---",
42-
`title: ${title}`,
43-
description ? `description: ${description}` : [],
44-
lastUpdated ? `lastUpdated: ${lastUpdated}` : [],
45-
chatbotDeprioritize ? `chatbotDeprioritize: ${chatbotDeprioritize}` : [],
46-
tags ? `tags: ${tags}` : [],
47-
`source_url:`,
48-
` html: ${url.replace("index.md", "")}`,
49-
` md: ${url}`,
44+
YAML.stringify({
45+
title,
46+
description,
47+
lastUpdated,
48+
chatbotDeprioritize: Boolean(chatbotDeprioritize),
49+
tags,
50+
source_url: {
51+
html: url.replace("index.md", ""),
52+
md: url,
53+
},
54+
}).trim(),
5055
"---\n",
5156
markdown,
5257
]

vitest.workspace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const workspace = defineWorkspace([
1212
optimizer: {
1313
ssr: {
1414
enabled: true,
15-
include: ["node-html-parser"],
15+
include: ["node-html-parser", "yaml"],
1616
},
1717
},
1818
},

worker/index.worker.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,16 @@ describe("Cloudflare Docs", () => {
254254
expect(text).toMatchInlineSnapshot(`
255255
"---
256256
title: Markdown · Cloudflare Style Guide
257-
description: The HTML generated by this file is used as a test fixture for our Markdown generation.
257+
description: "The HTML generated by this file is used as a test fixture for our
258+
Markdown generation:"
258259
lastUpdated: 2025-01-01T00:00:00.000Z
259260
chatbotDeprioritize: true
260261
source_url:
261262
html: http://fakehost/style-guide/fixtures/markdown/
262263
md: http://fakehost/style-guide/fixtures/markdown/index.md
263264
---
264265
265-
The HTML generated by this file is used as a test fixture for our Markdown generation.
266+
The HTML generated by this file is used as a test fixture for our Markdown generation:
266267
267268
* mdx
268269
@@ -353,10 +354,10 @@ describe("Cloudflare Docs", () => {
353354
?.attributes.content;
354355

355356
expect(desc).toMatchInlineSnapshot(
356-
`"The HTML generated by this file is used as a test fixture for our Markdown generation."`,
357+
`"The HTML generated by this file is used as a test fixture for our Markdown generation:"`,
357358
);
358359
expect(og).toMatchInlineSnapshot(
359-
`"The HTML generated by this file is used as a test fixture for our Markdown generation."`,
360+
`"The HTML generated by this file is used as a test fixture for our Markdown generation:"`,
360361
);
361362
});
362363
});

0 commit comments

Comments
 (0)