mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-04-28 21:49:55 -05:00
Fe overhaul docs (#1640)
* api changes * doc changes * move docs * generated * generate * pkg * backmerge main * revert to main * revert main * race? * remove go tests
This commit is contained in:
@@ -23,9 +23,12 @@ export const CodeBlock = ({ source, target }: CodeRendererProps) => {
|
||||
|
||||
const parsed = parseDocComments(source.raw, target, collapsed);
|
||||
|
||||
const canCollapse = source.raw.includes("// ...") || source.raw.includes("# ...")
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="sticky top-0 z-10 bg-background flex flex-row gap-4 justify-between items-center pl-2 mb-2">
|
||||
<div className="z-10 bg-background flex flex-row gap-4 justify-between items-center pl-2 mb-2">
|
||||
<div className="flex flex-row gap-2">
|
||||
{source.githubUrl && (
|
||||
<a
|
||||
href={source.githubUrl}
|
||||
@@ -36,8 +39,9 @@ export const CodeBlock = ({ source, target }: CodeRendererProps) => {
|
||||
{source.props?.path}
|
||||
</a>
|
||||
)}
|
||||
<div className="flex gap-2 w-full justify-end">
|
||||
{source.githubUrl && (
|
||||
</div>
|
||||
<div className="flex gap-2 justify-end">
|
||||
{canCollapse && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import React, { useMemo } from "react";
|
||||
import { CodeBlock } from "./CodeBlock";
|
||||
import { Snippet as SnippetType } from "@/lib/snips";
|
||||
|
||||
interface SnippetProps {
|
||||
src: SnippetType;
|
||||
block?: keyof SnippetType['blocks'] | 'ALL';
|
||||
}
|
||||
|
||||
const languageMap = {
|
||||
typescript: 'ts',
|
||||
python: 'py',
|
||||
go: 'go',
|
||||
unknown: 'txt',
|
||||
};
|
||||
|
||||
// This is a server component that will be rendered at build time
|
||||
export const Snippet = ({ src, block }: SnippetProps) => {
|
||||
if (!src.content) {
|
||||
throw new Error(`src content is required: ${src.source}`);
|
||||
}
|
||||
|
||||
const language = useMemo(() => {
|
||||
const normalizedLanguage = src.language?.toLowerCase().trim();
|
||||
if (normalizedLanguage && normalizedLanguage in languageMap) {
|
||||
return languageMap[normalizedLanguage as keyof typeof languageMap];
|
||||
}
|
||||
return 'txt';
|
||||
}, [src.language]);
|
||||
|
||||
let content = src.content;
|
||||
|
||||
if (block && block !== 'ALL' && src.blocks) {
|
||||
if (!(block in src.blocks)) {
|
||||
throw new Error(
|
||||
`Block ${block} not found in ${src.source} ${JSON.stringify(src.blocks, null, 2)}`,
|
||||
);
|
||||
}
|
||||
|
||||
const lines = src.content.split('\n');
|
||||
content = lines
|
||||
.slice(src.blocks[block].start - 1, src.blocks[block].stop)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
const fixedSource = src.source.replace('out/', 'examples/');
|
||||
|
||||
return (
|
||||
<>
|
||||
<CodeBlock
|
||||
source={{
|
||||
githubUrl: `https://github.com/hatchet-dev/hatchet/blob/main/${fixedSource}`,
|
||||
raw: content || '',
|
||||
language: language,
|
||||
props: {
|
||||
path: fixedSource,
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -13,7 +13,7 @@ const startsWithPrefixAndChar = (line: string, specialChar: string) => {
|
||||
};
|
||||
|
||||
const isTargetLine = (line: string, target: string) => {
|
||||
const split = line.split(/[❓?]/);
|
||||
const split = line.split(/[>?]/);
|
||||
return split[1].trim() === target.trim();
|
||||
};
|
||||
|
||||
@@ -34,10 +34,10 @@ export const parseDocComments = (
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i];
|
||||
|
||||
// Start collecting at ❓ or ?
|
||||
// Start collecting at > or ?
|
||||
if (
|
||||
isCommentLine(line) &&
|
||||
(startsWithPrefixAndChar(line, "❓") ||
|
||||
(startsWithPrefixAndChar(line, ">") ||
|
||||
startsWithPrefixAndChar(line, "?")) &&
|
||||
isTargetLine(line, target)
|
||||
) {
|
||||
@@ -65,9 +65,9 @@ export const parseDocComments = (
|
||||
continue;
|
||||
}
|
||||
|
||||
// Stop at ‼️ or !!
|
||||
// Stop at !! or !!
|
||||
if (
|
||||
startsWithPrefixAndChar(line, "‼️") ||
|
||||
startsWithPrefixAndChar(line, "!!") ||
|
||||
startsWithPrefixAndChar(line, "!!")
|
||||
) {
|
||||
break;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export * from './GithubSnippet'
|
||||
export * from './Snippet'
|
||||
export * from './CodeBlock'
|
||||
export * from './codeData'
|
||||
export * from './codeParser'
|
||||
|
||||
Reference in New Issue
Block a user