Fix checklist in markdown

* Add strip-markdown
* Add CopyButton component
* Fix copy code
* Add about page
* Use async function with get all markdown content
* Add shortcut icon
* Remove useless code
This commit is contained in:
DefectingCat
2021-11-20 11:34:21 +08:00
parent f19f817ad1
commit 1d48411138
12 changed files with 189 additions and 157 deletions

View File

@ -0,0 +1,39 @@
import { Button, useClipboard } from '@chakra-ui/react';
import { FC, MouseEventHandler, useEffect, useState } from 'react';
const CopyButton: FC = ({ children }) => {
// Copy code
const [codeContent, setCodeContent] = useState('');
const { hasCopied, onCopy } = useClipboard(codeContent);
const copyCode: MouseEventHandler<HTMLButtonElement> = (e) => {
const target = e.target as HTMLButtonElement;
// Button is sibling with Code tag
const codeToCopy = target.nextElementSibling?.textContent;
codeToCopy && setCodeContent(codeToCopy);
};
useEffect(() => {
codeContent && onCopy();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [codeContent]);
return (
<>
<pre>
<Button
size="xs"
colorScheme="teal"
position="absolute"
top="5px"
right="5px"
onClick={copyCode}
>
{hasCopied ? 'COPYIED' : 'COPY'}
</Button>
{children}
</pre>
</>
);
};
export default CopyButton;