Abhishek Jha / November 16, 2021
After over a month of Design <-> Redesign Build <-> Rebuild and thousands of lines of code finally completed building my personal portfolio
I have created this blog section inside my portfolio itself to share some useful stuff with the world.
Here I'll write some text based tutorials for competitive programming 📊 and development 💻 (You can suggest topics through the contact form too)
I've used Sendgrid for email delivery service and Prism react renderer for syntax highlighting in the code blocks.
Here's a small code snippet to show how you can use Prism react renderer and Chakra UI to show code blocks inside your website
import Highlight, { defaultProps, Language } from "prism-react-renderer";import darkTheme from "prism-react-renderer/themes/nightOwl";import lightTheme from "prism-react-renderer/themes/vsLight";import { FaCopy } from "react-icons/fa";import { Box, Button, useClipboard, useColorMode } from "@chakra-ui/react";import { useRef } from "react";interface CodeBlockProps {children: string;className: string;}export const CodeBlock = ({ children, className }: CodeBlockProps) => {const { colorMode } = useColorMode();const { hasCopied, onCopy } = useClipboard(children.trim());const codeRef = useRef<HTMLDivElement>(null);const language: unknown = className ? className.replace(/language-/, "") : "";return (<Box fontSize="sm" position="relative" ref={codeRef}><ButtonrightIcon={<FaCopy />}colorScheme="telegram"size="sm"variant="outline"position="absolute"top={-10}right={4}onClick={onCopy}>{hasCopied ? "Copied 👌 " : "Copy "}</Button><Highlight{...defaultProps}theme={colorMode === "dark" ? darkTheme : lightTheme}code={children}language={language as Language}>{({ className, style, tokens, getLineProps, getTokenProps }) => (<preclassName={className}style={{...style,padding: 10,overflowX: "auto",}}>{tokens.map((line, i) => (<div key={i} {...getLineProps({ line, key: i })}>{line.map((token, key) => (<span key={key} {...getTokenProps({ token, key })} />))}</div>))}</pre>)}</Highlight></Box>);};
More blogs (Specially for various topics of DSA and CP) will be coming soon :)