|
5 | 5 | * that don't have a description field in their frontmatter. |
6 | 6 | * |
7 | 7 | * It uses the rendered markdown from the distmd directory to generate descriptions |
8 | | - * by sending the content to a localhost:8788 application. |
| 8 | + * by sending the content to a localhost:8787 application. |
9 | 9 | * |
10 | | - * Usage: |
11 | | - * npm run generate-descriptions [-- --pcx-content-type <type>] |
| 10 | + * To run, you'll need to do the following: |
| 11 | + * 1. Get your local build setup: |
| 12 | + * 1. Run `npm run build` to build the local docs. |
| 13 | + * 2. Run `npx tsx bin/generate-index-md.ts` to generate the index.md files (saves on tokens) + avoids extra HTML. |
| 14 | + * 2. Have a local Worker running on `localhost:8787` with the following code (also requires adding a binding in the Wrangler config file): |
| 15 | + * |
| 16 | + * ``` |
| 17 | + * export interface Env { |
| 18 | + * AI: Ai; |
| 19 | + * } |
| 20 | +
|
| 21 | + * export default { |
| 22 | + * async fetch(request, env): Promise<Response> { |
| 23 | + * const response = await env.AI.run("@cf/facebook/bart-large-cnn", { |
| 24 | + * input_text: await request.text(), |
| 25 | + * max_length: 160 |
| 26 | + * }); |
| 27 | + * return Response.json(response.summary); |
| 28 | + * }, |
| 29 | + * } satisfies ExportedHandler<Env>; |
| 30 | + * ``` |
| 31 | + * 3. Run `npx tsx bin/generate-descriptions.ts --pcx-content-type $TYPE` to generate the descriptions. |
12 | 32 | * |
13 | | - * Options: |
14 | | - * --pcx-content-type <type> Filter MDX files by pcx_content_type (e.g., overview, tutorial, navigation) |
15 | 33 | */ |
16 | 34 |
|
17 | 35 | import fs from "fs/promises"; |
@@ -47,8 +65,10 @@ async function generateDescriptionFromAPI( |
47 | 65 | const description = await response.text(); |
48 | 66 | // Remove surrounding quotes if they exist |
49 | 67 | const trimmed = description.trim(); |
50 | | - if ((trimmed.startsWith('"') && trimmed.endsWith('"')) || |
51 | | - (trimmed.startsWith("'") && trimmed.endsWith("'"))) { |
| 68 | + if ( |
| 69 | + (trimmed.startsWith('"') && trimmed.endsWith('"')) || |
| 70 | + (trimmed.startsWith("'") && trimmed.endsWith("'")) |
| 71 | + ) { |
52 | 72 | return trimmed.slice(1, -1); |
53 | 73 | } |
54 | 74 | return trimmed; |
|
0 commit comments