Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/content/docs/style-guide/fixtures/markdown.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sidebar:

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

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

<Tabs>
<TabItem label="mdx">
Expand Down
21 changes: 13 additions & 8 deletions src/util/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { parse } from "node-html-parser";
import { process } from "../util/rehype";

import YAML from "yaml";

import rehypeParse from "rehype-parse";
import rehypeBaseUrl from "../plugins/rehype/base-url";
import rehypeFilterElements from "../plugins/rehype/filter-elements";
Expand Down Expand Up @@ -39,14 +41,17 @@ export async function htmlToMarkdown(

const withFrontmatter = [
"---",
`title: ${title}`,
description ? `description: ${description}` : [],
lastUpdated ? `lastUpdated: ${lastUpdated}` : [],
chatbotDeprioritize ? `chatbotDeprioritize: ${chatbotDeprioritize}` : [],
tags ? `tags: ${tags}` : [],
`source_url:`,
` html: ${url.replace("index.md", "")}`,
` md: ${url}`,
YAML.stringify({
title,
description,
lastUpdated,
chatbotDeprioritize: Boolean(chatbotDeprioritize),
tags,
source_url: {
html: url.replace("index.md", ""),
md: url,
},
}).trim(),
"---\n",
markdown,
]
Expand Down
2 changes: 1 addition & 1 deletion vitest.workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const workspace = defineWorkspace([
optimizer: {
ssr: {
enabled: true,
include: ["node-html-parser"],
include: ["node-html-parser", "yaml"],
},
},
},
Expand Down
9 changes: 5 additions & 4 deletions worker/index.worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,16 @@ describe("Cloudflare Docs", () => {
expect(text).toMatchInlineSnapshot(`
"---
title: Markdown · Cloudflare Style Guide
description: The HTML generated by this file is used as a test fixture for our Markdown generation.
description: "The HTML generated by this file is used as a test fixture for our
Markdown generation:"
lastUpdated: 2025-01-01T00:00:00.000Z
chatbotDeprioritize: true
source_url:
html: http://fakehost/style-guide/fixtures/markdown/
md: http://fakehost/style-guide/fixtures/markdown/index.md
---

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

* mdx

Expand Down Expand Up @@ -353,10 +354,10 @@ describe("Cloudflare Docs", () => {
?.attributes.content;

expect(desc).toMatchInlineSnapshot(
`"The HTML generated by this file is used as a test fixture for our Markdown generation."`,
`"The HTML generated by this file is used as a test fixture for our Markdown generation:"`,
);
expect(og).toMatchInlineSnapshot(
`"The HTML generated by this file is used as a test fixture for our Markdown generation."`,
`"The HTML generated by this file is used as a test fixture for our Markdown generation:"`,
);
});
});
Expand Down