Skip to content

Commit e3368f7

Browse files
Revert "[Docs Site] Add frontmatter to index.md output (#21980)"
This reverts commit 27aa5ce.
1 parent cd2ebca commit e3368f7

File tree

6 files changed

+16
-32
lines changed

6 files changed

+16
-32
lines changed

src/components/overrides/Head.astro

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { getEntry } from "astro:content";
77
import { getOgImage } from "~/util/og";
88
import type { CollectionEntry } from "astro:content";
99
10-
const DEFAULT_TITLE_DELIMITER = "|";
1110
const NOINDEX_PRODUCTS = ["email-security", "style-guide", "security"];
1211
1312
const currentSection = Astro.url.pathname.split("/")[1].replaceAll(".", "");
@@ -32,9 +31,7 @@ if (currentSection) {
3231
let title: string;
3332
3433
if (titleIdx !== -1) {
35-
const existingTitle = head[titleIdx].content?.split(
36-
` ${DEFAULT_TITLE_DELIMITER} `,
37-
)[0];
34+
const existingTitle = head[titleIdx].content;
3835
title = `${existingTitle} · ${product.data.meta.title}`;
3936
4037
head[titleIdx] = {
@@ -83,26 +80,6 @@ if (shouldNoIndex) {
8380
});
8481
}
8582
86-
if (
87-
frontmatter.description &&
88-
head.findIndex(
89-
({ tag, attrs }) => tag === "meta" && attrs?.name === "description",
90-
) === -1
91-
) {
92-
const existingOpenGraphTag = head.findIndex(
93-
({ tag, attrs }) => tag === "meta" && attrs?.property === "og:description",
94-
);
95-
96-
if (existingOpenGraphTag !== -1) {
97-
head[existingOpenGraphTag].attrs!.content = frontmatter.description;
98-
}
99-
100-
metaTags.push({
101-
name: "description",
102-
content: frontmatter.description as string,
103-
});
104-
}
105-
10683
if (frontmatter.pcx_content_type) {
10784
["pcx_content_type", "algolia_content_type"].map((name) => {
10885
metaTags.push({

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
title: Markdown
33
noindex: true
4-
lastUpdated: 2025-01-01T00:00:00Z
54
sidebar:
65
hidden: true
76
---

src/middleware/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const onRequest = defineMiddleware(async (context, next) => {
1818
const htmlUrl = new URL(pathname.replace("index.md", ""), context.url);
1919
const html = await (await fetch(htmlUrl)).text();
2020

21-
const markdown = await htmlToMarkdown(html, context.url.toString());
21+
const markdown = await htmlToMarkdown(html);
2222

2323
if (!markdown) {
2424
return new Response("Not Found", { status: 404 });

src/util/markdown.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import remarkStringify from "remark-stringify";
1010

1111
export async function htmlToMarkdown(
1212
html: string,
13-
url: string,
1413
): Promise<string | undefined> {
15-
const dom = parse(html);
16-
const content = dom.querySelector(".sl-markdown-content");
14+
const content = parse(html).querySelector(".sl-markdown-content");
1715

1816
if (!content) {
1917
return;
@@ -28,6 +26,7 @@ export async function htmlToMarkdown(
2826
remarkStringify,
2927
]);
3028

29+
<<<<<<< HEAD
3130
const title = dom.querySelector("title")?.textContent;
3231
const description = dom.querySelector("meta[name='description']")?.attributes
3332
.content;
@@ -48,4 +47,7 @@ export async function htmlToMarkdown(
4847
.join("\n");
4948

5049
return withFrontmatter;
50+
=======
51+
return markdown;
52+
>>>>>>> parent of 27aa5ce724 ([Docs Site] Add frontmatter to index.md output (#21980))
5153
}

worker/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ export default class extends WorkerEntrypoint<Env> {
2323
}
2424

2525
if (request.url.endsWith("/index.md")) {
26-
const htmlUrl = request.url.replace("index.md", "");
27-
const res = await this.env.ASSETS.fetch(htmlUrl, request);
26+
const res = await this.env.ASSETS.fetch(
27+
request.url.replace("index.md", ""),
28+
request,
29+
);
2830

2931
if (res.status === 404) {
3032
return res;
@@ -36,7 +38,7 @@ export default class extends WorkerEntrypoint<Env> {
3638
) {
3739
const html = await res.text();
3840

39-
const markdown = await htmlToMarkdown(html, request.url);
41+
const markdown = await htmlToMarkdown(html);
4042

4143
if (!markdown) {
4244
return new Response("Not Found", { status: 404 });

worker/index.worker.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ describe("Cloudflare Docs", () => {
268268

269269
const text = await response.text();
270270
expect(text).toMatchInlineSnapshot(`
271+
<<<<<<< HEAD
271272
"---
272273
title: Markdown · Cloudflare Style Guide
273274
description: The HTML generated by this file is used as a test fixture for our Markdown generation.
@@ -278,6 +279,9 @@ describe("Cloudflare Docs", () => {
278279
---
279280
280281
The HTML generated by this file is used as a test fixture for our Markdown generation.
282+
=======
283+
"The HTML generated by this file is used as a test fixture for our Markdown generation.
284+
>>>>>>> parent of 27aa5ce724 ([Docs Site] Add frontmatter to index.md output (#21980))
281285
282286
* mdx
283287

0 commit comments

Comments
 (0)