Modern web development came a long way. The blog that you are currently reading was built in about ten days, with not more than an hour spent on it on those days. Because of all the open-source libraries available, the site is fast and accessible, with little extra work required on my end.
This article contains a few quick tips that will help you build your blog from scratch, should you choose to go down on that path.
First, let's address the elephant in the room! Why would anyone build their blog from scratch in 2020, when we have services like Ghost or Wordpress?
Previously, I used a blog engine called Hexo. While it worked well for a few years, it became increasingly hard to maintain and update. It doesn't have a vibrant plugin ecosystem, so quite a few times, I ended up monkey-patching it's build pipeline to include support for web workers or webp images formats. So maintaining the old blog was not an option anymore.
Secondly, I wanted to have a small side project to learn and experiment with new technologies and language features. As I wrote in the article Coding as an Engineering Manager, as a manager, I usually work on bug fixes when it comes to coding. This website allows working on a project end-to-end and keeps my technical chops up-to-date.
Be aware, working on your blog can also result in endless procrastination (let me quickly fix that one LAST thing). I have been there done that.
Next.js is a web framework built for React. The reasons I picked it for my blog:
I picked Base Web as the component library for this site. While it doesn't matter which component library you choose from a stylistic point of view, do pay attention to the following technical details:
Once you start using Next.js or any React frameworks, I highly recommend starting using MDX. MDX is a format that lets you write JSX in your Markdown documents. So in practice, you can keep wiring markdown-based blog posts that Next.js/Gatsby can easily pick up.
Read more on it here.
It may be tempting to utilize external libraries for things like share buttons that enable your readers to post content to Twitter, Facebook or LinkedIn. It doesn't just add a lot of external dependencies to your site and slows it down, but it also adds additional trackers to your site.
Instead, you can rely on share URLs that most social networks provide:
https://www.linkedin.com/shareArticle?url=
.https://twitter.com/intent/tweet/?url=
.https://www.facebook.com/sharer/sharer.php?u=
.Similarly, you can integrate most newsletter services, like Mailchimp, without any additional JavaScript dependencies. For example, check out the Mailchimp integration at the bottom of this page.
Originally, the blog posts I wrote lived under the root of the domain, without name namespace, like: https://nemethgergely.com/coding-as-an-engineering-manager
. While initially it worked well, it became problematic as the number of blog posts increased.
Because of that, I've decided to move all blog posts under the namespace /blog/
. So the previously mentioned article would be accessible from https://nemethgergely.com/blog/coding-as-an-engineering-manager
. To ensure that I don't break any previous links to the site, I wanted to create redirects to the new locations.
This is where Cloudflare Workers become super handy - they provide extreme flexibility and are simple to write. This is the script that I use today to create the redirects:
const base = "https://nemethgergely.com"const statusCode = 301;const routes = ["engineering-productivity",...];addEventListener('fetch', event => {event.respondWith(handleRequest(event.request))})async function handleRequest(request) {const url = new URL(request.url)let { pathname } = urlif (routes.includes(pathname)) {return Response.redirect(`${base}/blog/${pathname}`, statusCode)}return fetch(request)}
Twitter, Facebook or LinkedIn display an image in users' feed when you share one of your articles. These images are coming from OpenGraph tags, and you can set almost any image (with some requirements) to be displayed. However, creating these images whenever you write a new article can be taxing at times.
Because of this, and to ensure that these images are consistent, I implemented the following automation:
undefined
title in HTML, and creates screenshots.When I started building this blog, I broke it a few times (mostly the layout or links). That's when I realized that I should add some basic sanity tests. As of today, I have two checks:
It always fun for me to build something. If you decide to create your blog too, keep these in mind: