Oct 2024 · 5 mins · Fx64b
Hello World!
Hello World! This is the first "blog post" on this site.
After procrastinating for close to two years, I finally found the time to replace the "Work in Progress" page with a proper site:

What I used to build this site
- Next.js for static and dynamic pages.
- Gray Matter & React Markdown for markdown to react conversion
- Tailwind CSS & NextUI for components and additional styling.
- Prism Themes & React Syntax Highlighter for code syntax highlighting.
- Vercel for hosting, analytics and deployment.
...
Well you might ask yourself now, "Why not use plain HTML and CSS and just build a static site?"
Great question! It's almost like asking a chef why he didn't just microwave a frozen pizza for dinner.
Sure, it's quick and gets the job done but where is the fun in that?
And nothing screams "I'm serious about web development" like having a CI/CD pipeline and automated versioning set up for a blog that I'll probably update twice a year.
So why all this?
Because I can.- Because, honestly, I really wanted to experiment with these technologies, but I don't really have any ideas for actual projects to use them on.
Building the site
The most interesting and difficult part was definitely the MarkdownRenderer.tsx, specifically the codeblock and syntax highlighting part.
After several hours of googling and getting nonsense answers from ChatGPT I ended up with this not so clean solution:
TypeScript
Here is how it works
CodeBlockSubcomponent
TypeScript
- We start off by setting the
useState()for the copy button. - Then we extract the language. During the markdown processing a class that looks like this is added to the codeblock to later identify the correct language:
language-tsx - Then the children prop (which contains all the code) is converted into a string and all trailing newline (
\n)
The Copy button isn't too interesting, I just use the react-copy-to-clipboard package.
Syntax highlighting is done by the <SyntaxHighlighter> component from react-syntax-highlighter with this relatively simple code block:
TypeScript
If the code is inline (for example an npm install command) we just use a basic span element which results in a clean look:
TypeScript
and looks like this:
Bash
- Hot-gluing it all together
Now we take these two components and patch them together like this:
TypeScript
rehypeRawis used that things like<br>tags are not rendered as text so that the content renders halfway decently.- In the
componentsattribute I specified the html elements I want to override with my own elements, specifically theCodeBlockcomponent
Handling of Markdown files
Posts are stored as simple markdown files in the /content directory.
The filename also acts as the slug in the url /content/hello-world.md -> /blog/hello-world
Here is how postdata and content is fetched:
TS
This function additionally has a replace for .md in case the function is called by a function that gets all filenames from the content directory like this:
TS
and then:
TS
Conclusion
There is much more code I could cover here, but I'm not gonna do that. Check out the code yourself if you want to: Fx64b/fx64b.dev.
If you have some spare time to waste you can help me clean up the code by creating a pull request.
Feel free to copy the code from this site. If you for some reason decide to copy content from my blog posts and publish them yourself, please add a reference to the original post.
Written by Fx64b
Software engineer from Switzerland. Get in touch.