mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-04-30 06:30:12 -05:00
f8e5f357d9
* feat: start reworking snippets * feat: start cleaning up gen script * fix: start updating refs everywhere * feat: start fixing broken snippet links * fix: more snippets * fix: more updates * chore: lint * fix: taskfile * fix: script * fix: escaping issue + mergent blog * fix: bunch more * chore: lint * fix: implement more of them * fix: retry * fix: the rest * chore: lint * fix: highlight * fix: ugh * fix: start removing dead code from old snippet method * fix: rest of the refs * fix: remove all of the rest of the <GithubSnippet uses * fix: couple more * fix: last few errors * fix: handle example writes * fix: delete to test update * fix: CI, attempt 1 * feat: helpful error on no snippet * fix: lint * chore: rm unused js file * feat: improve GHA * debug: run action on branch * fix: rm pnpm * fix: try to leave comment instead * fix: don't run on branch * fix: factor out GH info * fix: include code path * fix: ts
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import React from "react";
|
|
import { CodeBlock } from "./CodeBlock";
|
|
import { type Snippet as SnippetType } from "@/lib/snippet";
|
|
|
|
type Language = SnippetType["language"];
|
|
|
|
// See the list of supported languages for how to define these:
|
|
// https://highlightjs.readthedocs.io/en/latest/supported-languages.html
|
|
const languageToHighlightAbbreviation = (language: Language) => {
|
|
switch (language) {
|
|
case "python":
|
|
return "py";
|
|
case "typescript":
|
|
return "ts";
|
|
case "go":
|
|
return "go";
|
|
default:
|
|
const exhaustiveCheck: never = language;
|
|
throw new Error(`Unsupported language: ${exhaustiveCheck}`);
|
|
}
|
|
};
|
|
|
|
export const Snippet = ({ src }: { src: SnippetType }) => {
|
|
if (src === undefined) {
|
|
throw new Error(
|
|
"Snippet was undefined. You probably provided a path to a snippet that doesn't exist."
|
|
);
|
|
}
|
|
return (
|
|
<CodeBlock
|
|
source={{
|
|
githubUrl: src.githubUrl,
|
|
raw: src.content,
|
|
language: languageToHighlightAbbreviation(src.language),
|
|
codePath: src.codePath,
|
|
}}
|
|
/>
|
|
);
|
|
};
|