1
0
mirror of https://github.com/actix/actix-website synced 2025-06-30 08:44:27 +02:00

TypeScript compatibility (#379)

* Update file extensions and exports for TypeScript compatibility

* docs: fix typo in getting-started.md

* chore: add no-trailing-punctuation rule to VS Code settings

* feat: add @docusaurus/theme-mermaid for mermaid diagram support

* Update import paths for MermaidDiagram component

* remove redudndant check, use effect only runs after the component is mounted

* Update docusaurus.config.ts to fix syntax error

* bring back check because it's not possible to properly cancel a dynamic import

* feat: optimize dynamic import in CodeBlock component

* chore: update VS Code extensions.json with eslint recommendation

* Update docusaurus.config.ts to add GitHub repository link in header
This commit is contained in:
Hichem Fantar
2024-05-28 20:23:34 +01:00
committed by GitHub
parent a0a2da114d
commit ad4aeac34f
23 changed files with 4597 additions and 73 deletions

View File

@ -1,31 +1,38 @@
import React, { useState, useEffect } from "react";
import RenderCodeBlock from "@theme/CodeBlock";
import { useIsMounted } from "usehooks-ts";
const CodeBlock = ({ example, file, section, language }) => {
type Props = {
example: string;
file?: string;
section: string;
language?: string;
};
const CodeBlock = ({ example, file, section, language }: Props) => {
const isMounted = useIsMounted();
const [code, setCode] = useState("");
useEffect(() => {
let isMounted = true;
const path =
file === "manifest" ? "Cargo.toml" : `src/${file ?? "main.rs"}`;
import(`!!raw-loader!@site/examples/${example}/${path}`)
.then((source) => {
if (!isMounted()) {
return;
}
source = source.default.match(
new RegExp(
`(?:\/\/|#) <${section}>\n([\\s\\S]*)(?:\/\/|#) <\/${section}>`,
),
`(?:\/\/|#) <${section}>\n([\\s\\S]*)(?:\/\/|#) <\/${section}>`
)
)[1];
if (isMounted) setCode(source);
setCode(source);
})
.catch((err) => console.log(err));
return () => {
isMounted = false;
};
}, []);
}, [isMounted]);
return (
<RenderCodeBlock className={`language-${language ?? "rust"}`}>

View File

@ -0,0 +1,12 @@
import Mermaid from "@theme/Mermaid";
import React from "react";
type Props = {
value: string;
};
const MermaidDiagram = ({ value }: Props) => {
return <Mermaid value={value} />;
};
export default MermaidDiagram;

View File

@ -1,11 +0,0 @@
import RenderCodeBlock from "@theme/CodeBlock";
const ShellBlock = ({ children }) => {
return (
<RenderCodeBlock className={`language-console`}>
{children}
</RenderCodeBlock>
);
};
export default ShellBlock;

View File

@ -0,0 +1,14 @@
import RenderCodeBlock from "@theme/CodeBlock";
import React from "react";
type Props = {
children: React.ReactNode;
};
const ShellBlock = ({ children }: Props) => {
return (
<RenderCodeBlock className={`language-console`}>{children}</RenderCodeBlock>
);
};
export default ShellBlock;