Skip to content

Commit

Permalink
[Docs Site] Remove docs-tag lines from rendered output in GitHubCode (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
KianNH authored Dec 12, 2024
1 parent 21069dc commit 19d1e26
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
17 changes: 9 additions & 8 deletions src/components/GitHubCode.astro
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,20 @@ if (!res.ok) {
throw new Error(`[GitHubCode] Received ${res.status} from Worker.`);
}
let content = await res.text();
const content = await res.text();
let contentLines = content.split("\n");
if (lines) {
const [start, end] = lines;
const contentLines = content.split("\n");
if (contentLines.length < end - 1) {
throw new Error(
`[GitHubCode] End line requested is beyond content length (${contentLines.length}).`,
);
}
content = contentLines.slice(start - 1, end).join("\n");
contentLines = contentLines.slice(start - 1, end);
} else if (tag) {
const contentLines = content.split("\n");
const startTag = contentLines.findIndex((x) =>
x.includes(`<docs-tag name="${tag}">`),
);
Expand All @@ -61,8 +58,12 @@ if (lines) {
throw new Error(`[GitHubCode] Unable to find a region using tag "${tag}".`);
}
content = contentLines.slice(startTag + 1, endTag).join("\n");
contentLines = contentLines.slice(startTag + 1, endTag);
}
contentLines = contentLines.filter(
(line) => !/<[\/]?docs-tag name=".*">/.test(line),
);
---

<Code code={content} lang={lang} />
<Code code={contentLines.join("\n")} lang={lang} />
8 changes: 4 additions & 4 deletions src/content/docs/style-guide/components/github-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import { GitHubCode } from "~/components";
import { GitHubCode } from "~/components";

<GitHubCode
repo="cloudflare/workers-rs"
file="templates/hello-world/src/lib.rs"
commit="ab3951b5c95329a600a7baa9f9bb1a7a95f1aeaa"
lang="rs"
repo="cloudflare/workflows-starter"
file="src/index.ts"
commit="a844e629ec80968118d4b116d4b26f5dcb107137"
lang="ts"
/>
```

Expand Down

0 comments on commit 19d1e26

Please sign in to comment.