Skip to content

Commit 5b469f5

Browse files
committed
update script + run over tutorial files
1 parent 54e1de8 commit 5b469f5

File tree

140 files changed

+323
-81
lines changed

Some content is hidden

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

140 files changed

+323
-81
lines changed

bin/generate-descriptions.ts

Lines changed: 45 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* This script generates descriptions for MDX files in the docs directory
55
* that don't have a description field in their frontmatter.
66
*
7-
* It uses the rendered HTML from the dist directory to generate descriptions
8-
* using the generateDescription function from src/util/props.ts.
7+
* It uses the rendered markdown from the distmd directory to generate descriptions
8+
* by sending the content to a localhost:8788 application.
99
*
1010
* Usage:
1111
* npm run generate-descriptions [-- --pcx-content-type <type>]
@@ -17,57 +17,57 @@
1717
import fs from "fs/promises";
1818
import path from "path";
1919
import globby from "fast-glob";
20-
import { parse as parseHTML } from "node-html-parser";
21-
import { generateDescription } from "../src/util/props";
2220
import matter from "gray-matter";
2321

2422
const DOCS_DIR = path.join(process.cwd(), "src/content/docs");
25-
const DIST_DIR = path.join(process.cwd(), "dist");
23+
const DISTMD_DIR = path.join(process.cwd(), "distmd");
2624

27-
// Maximum length for descriptions
28-
const MAX_DESCRIPTION_LENGTH = 160;
25+
// Localhost application URL
26+
const LOCALHOST_URL = "http://localhost:8787";
2927

3028
/**
31-
* Extracts the first paragraph from HTML content
29+
* Sends text content to localhost application and receives description back
3230
*/
33-
function extractFirstParagraph(html: string): string | undefined {
34-
const dom = parseHTML(html);
35-
const paragraph = dom.querySelector("p");
36-
37-
if (paragraph) {
38-
return paragraph.textContent.trim();
39-
}
40-
41-
return undefined;
42-
}
43-
44-
/**
45-
* Truncates a description to a reasonable length
46-
*/
47-
function truncateDescription(description: string): string {
48-
if (description.length <= MAX_DESCRIPTION_LENGTH) {
49-
return description;
50-
}
31+
async function generateDescriptionFromAPI(
32+
content: string,
33+
): Promise<string | undefined> {
34+
try {
35+
const response = await fetch(LOCALHOST_URL, {
36+
method: "POST",
37+
headers: {
38+
"Content-Type": "text/plain",
39+
},
40+
body: content,
41+
});
5142

52-
// Truncate at the last space before MAX_DESCRIPTION_LENGTH
53-
const truncated = description.substring(0, MAX_DESCRIPTION_LENGTH);
54-
const lastSpace = truncated.lastIndexOf(" ");
43+
if (!response.ok) {
44+
throw new Error(`HTTP error! status: ${response.status}`);
45+
}
5546

56-
if (lastSpace > 0) {
57-
return truncated.substring(0, lastSpace) + "...";
47+
const description = await response.text();
48+
// Remove surrounding quotes if they exist
49+
const trimmed = description.trim();
50+
if ((trimmed.startsWith('"') && trimmed.endsWith('"')) ||
51+
(trimmed.startsWith("'") && trimmed.endsWith("'"))) {
52+
return trimmed.slice(1, -1);
53+
}
54+
return trimmed;
55+
} catch (error) {
56+
console.error("Error calling localhost API:", error);
57+
return undefined;
5858
}
59-
60-
return truncated + "...";
6159
}
6260

6361
/**
64-
* Gets the rendered HTML path for a docs file
62+
* Gets the rendered markdown path for a docs file
6563
*/
6664
function getRenderedPath(docPath: string): string {
67-
// Convert /src/content/docs/product/path/file.mdx to /dist/product/path/file/index.html
65+
// Convert /src/content/docs/product/path/file.mdx to /distmd/product/path/file/index.md
6866
const relativePath = path.relative(DOCS_DIR, docPath);
6967
const pathWithoutExt = relativePath.replace(/\.mdx$/, "");
70-
return path.join(DIST_DIR, pathWithoutExt, "index.html");
68+
const filename = path.basename(pathWithoutExt);
69+
const dirPath = path.dirname(pathWithoutExt);
70+
return path.join(DISTMD_DIR, dirPath, filename, "index.md");
7171
}
7272

7373
/**
@@ -224,43 +224,33 @@ async function main() {
224224
continue;
225225
}
226226

227-
// Get the rendered HTML path
227+
// Get the rendered markdown path
228228
const renderedPath = getRenderedPath(mdxFile);
229229

230-
// Check if rendered HTML exists
230+
// Check if rendered markdown exists
231231
try {
232232
await fs.access(renderedPath);
233233
} catch (error) {
234-
console.log(error);
235234
console.warn(
236-
`⚠️ Rendered HTML not found for ${path.relative(process.cwd(), mdxFile)}`,
235+
`⚠️ Rendered markdown not found for ${path.relative(process.cwd(), mdxFile)}`,
237236
);
238237
errorCount++;
239238
continue;
240239
}
241240

242-
// Read rendered HTML
243-
const html = await fs.readFile(renderedPath, "utf-8");
244-
245-
// Extract main content from HTML
246-
const dom = parseHTML(html);
247-
const mainContent = dom.querySelector("main")?.innerHTML || "";
241+
// Read rendered markdown content
242+
const markdownContent = await fs.readFile(renderedPath, "utf-8");
248243

249-
if (!mainContent) {
244+
if (!markdownContent.trim()) {
250245
console.warn(
251-
`⚠️ No main content found in rendered HTML for ${path.relative(process.cwd(), mdxFile)}`,
246+
`⚠️ Empty markdown content found for ${path.relative(process.cwd(), mdxFile)}`,
252247
);
253248
errorCount++;
254249
continue;
255250
}
256251

257-
// Generate description
258-
let description = await generateDescription({ html: mainContent });
259-
260-
// If no description was generated, try extracting the first paragraph
261-
if (!description) {
262-
description = extractFirstParagraph(mainContent);
263-
}
252+
// Generate description using localhost API
253+
const description = await generateDescriptionFromAPI(markdownContent);
264254

265255
// Skip if no description could be generated
266256
if (!description) {
@@ -271,9 +261,6 @@ async function main() {
271261
continue;
272262
}
273263

274-
// Truncate description if needed
275-
description = truncateDescription(description);
276-
277264
// Update frontmatter
278265
const wasUpdated = await updateFrontmatter(mdxFile, description);
279266
if (wasUpdated) {

src/content/docs/1.1.1.1/additional-options/dns-in-google-sheets.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
pcx_content_type: tutorial
33
title: DNS in Google Sheets
44
slug: 1.1.1.1/additional-options/dns-in-google-sheets
5-
5+
description: >-
6+
Cloudflare 1.1.1 works directly inside Google Sheets. To get started, create a Google Function with the following code.
67
---
78

89
import { Details } from "~/components"

src/content/docs/1.1.1.1/additional-options/dns-over-discord.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
pcx_content_type: tutorial
33
title: DNS over Discord
44
slug: 1.1.1.1/additional-options/dns-over-discord
5-
5+
description: >-
6+
1.1. 1.1 works from a Discord server. Invite the bot to your Discord server to start using DNS over Discord. Or, add it to your account to use it anywhere in Discord.
67
---
78

89
import { Details } from "~/components"

src/content/docs/1.1.1.1/additional-options/dns-over-tor.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
pcx_content_type: tutorial
33
title: DNS over Tor
44
slug: 1.1.1.1/additional-options/dns-over-tor
5+
description: >-
6+
If you do not want to disclose your IP address to the resolver, you can use our Tor onion service. Resolving DNS queries through the Tor network guarantees a significantly higher level of anonymity. The hidden resolver is set up to listen on TCP ports 53 and 8 for HTTPS.
57
---
68

79
:::caution

src/content/docs/ai-gateway/integrations/aig-workers-ai-binding.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
title: Workers AI
33
pcx_content_type: tutorial
44
reviewed: 2024-10-17
5+
description: >-
6+
This guide will walk you through setting up and deploying a Workers AI project. You will use Workers, an AI Gateway binding, and a large language model (LLM) to deploy your first AI-powered application on the Cloudflare global network.
57
---
68

79
import { Render, PackageManagers, WranglerConfig } from "~/components";

src/content/docs/ai-gateway/integrations/worker-binding-methods.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ pcx_content_type: tutorial
44
tags:
55
- Bindings
66
reviewed: 2025-04-01
7+
description: >-
8+
This guide provides an overview of how to use the latest Cloudflare Workers AI Gateway binding methods. You will learn how to set up an AI. Gateway binding, access new methods, and integrate them into your Workers.
79
---
810

911
import { Render, PackageManagers } from "~/components";

src/content/docs/ai-gateway/tutorials/create-first-aig-workers.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ pcx_content_type: tutorial
33
difficulty: Beginner
44
reviewed: 2024-08-01
55
title: Create your first AI Gateway using Workers AI
6+
description: >-
7+
This tutorial guides you through creating your first AI Gateway using Workers AI on the Cloudflare dashboard. The intended audience is beginners who are new to AI Gateway and Workers AI. An AI Gateway enables the user to efficiently manage and secure AI requests.
68
---
79

810
import { Render } from "~/components";

src/content/docs/analytics/analytics-integrations/datadog.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ pcx_content_type: tutorial
33
title: Datadog
44
sidebar:
55
order: 98
6+
description: >-
7+
This tutorial explains how to analyze Cloudflare metrics using the [Cloudflare Integration tile for Datadog]
68
---
79

810
This tutorial explains how to analyze Cloudflare metrics using the [Cloudflare Integration tile for Datadog](https://docs.datadoghq.com/integrations/cloudflare/).

src/content/docs/analytics/analytics-integrations/graylog.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ pcx_content_type: tutorial
33
title: Graylog
44
sidebar:
55
order: 102
6-
6+
description: >-
7+
This tutorial explains how to analyze [Cloudflare Logs] using Graylog. The Graylog integration is available on GitHub.
78
---
89

910
This tutorial explains how to analyze [Cloudflare Logs](https://www.cloudflare.com/products/cloudflare-logs/) using [Graylog](https://github.com/Graylog2/graylog-s3-lambda/blob/master/content-packs/cloudflare/cloudflare-logpush-content-pack.json).

src/content/docs/analytics/analytics-integrations/new-relic.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ pcx_content_type: tutorial
33
title: New Relic
44
sidebar:
55
order: 103
6+
description: >-
7+
This tutorial explains how to analyze Cloudflare metrics using the New Relic One Cloudflar Quickstart.
68
---
79

810
This tutorial explains how to analyze Cloudflare metrics using the [New Relic One Cloudflare Quickstart](https://newrelic.com/instant-observability/cloudflare/fc2bb0ac-6622-43c6-8c1f-6a4c26ab5434).

0 commit comments

Comments
 (0)