1
0
mirror of https://github.com/actix/actix-website synced 2025-06-29 16:24:58 +02:00

Add hosting instructions for Shuttle (#334)

* Add hosting instructions for Shuttle

* move shuttle sample code to examples dir

---------

Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
Orhun Parmaksız
2023-11-01 16:08:40 +01:00
committed by GitHub
parent 411a64afd3
commit e72b12218a
7 changed files with 107 additions and 21 deletions

View File

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