Skip to content

Commit 30500aa

Browse files
committed
update instructions
1 parent 5b469f5 commit 30500aa

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

bin/generate-descriptions.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,31 @@
55
* that don't have a description field in their frontmatter.
66
*
77
* 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.
99
*
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.
1232
*
13-
* Options:
14-
* --pcx-content-type <type> Filter MDX files by pcx_content_type (e.g., overview, tutorial, navigation)
1533
*/
1634

1735
import fs from "fs/promises";
@@ -47,8 +65,10 @@ async function generateDescriptionFromAPI(
4765
const description = await response.text();
4866
// Remove surrounding quotes if they exist
4967
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+
) {
5272
return trimmed.slice(1, -1);
5373
}
5474
return trimmed;

0 commit comments

Comments
 (0)