Hi there! This is the first record in my blog, it could be “Hello world” but it would be too boring :)

Let it be instruction on how to install a blog like that (for free) with zero cost for maintenance.

0. Goals & Why

Nowadays we have plenty of platforms that will do a blog or any site hosting & management. CMS can be Cloud (Google blogs/Medium) or self-hosted - like WordPress.

With a Cloud/Service solution, there are several problems:

  1. You are not the owner of the system - and at any point, the service may close your account
  2. Migration between services is a pain

In the case of self-hosted solutions (like WordPress) the main problem is the cost of support. You need to maintain the Server with DB and perform upgrades and patches. It is more flexible than Cloud options but it might take much more time for support.

At this point, static HTML generators (Jamstack) come to the stage.

You don’t need to maintain a server - you can use free static file hosting (Github/Cloudflare/etc). On the server, we will not have any dynamic information - only static HTML files and assets (javascript and images).

Our “DB” is just a Git repository with Markdown files that can be easily edited using a favorite tool, and if something goes south - it can be easily moved to a new hosting provider.

Goals

  1. Own blog/website that will not rely on on any blogging platform, with zero maitananance cost.
  2. Automatically publish any changes / new posts (CICD pipeline).
  3. Pure static HTML (jamstack)

1. What we will use

  1. Hugo - as static site generator
  2. Markdown as text/post format
  3. CloudFlare as a free hosting
  4. GitHub as a repository storage and versioning
  5. VSCode for text editing

2. Preconditions

  1. GitHub account created
  2. CloudFlare account created
  3. (Optional!) domain bought
  4. Git & Hudo installed on your device
  5. You are using Mac (in the case of Windows/Linux - the command might be adjusted) Basic understanding of Git, Terminal

3. Storing website on GitHub

  1. Create a new repository on GitHub (it can be private)
  2. To clone (sync) the repository between your Mac and GitHub you can use:
    1. terminal git command (for this you need to generate a token here https://github.com/settings/tokens and use it instead of the password)
    2. http://desktop.github.com - Application with UI
  3. Let’s assume they use went with option #1, pick a URL from the repository that you created on GitHub and type git clone #URL# in the terminal where URL - URL that you got from GitHub for your repository. Keep in mind, that this will be the place where you will store a local copy of your blog! Let’s assume that you created your blog in /Users/Me/repos/myBlog
  4. You might be prompted for a username and password, enter your username and instead of a password - provide a token from step #2.1

4. Creating a Hugo-based site

Let’s create a local Hugo site, for that, you just need to type 6 commands in your terminal:

hugo new site quickstart
cd quickstart
git init
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke
echo "theme = 'ananke'" >> hugo.toml
hugo server

After this step, you can go to http://localhost:1313/ and see your working local website.

Did it work? If yes - congratulations, more than 50% done!

5. Use VSCode as an editor & First Blog Post

I highly recommend using VSCode as a text editor, it is free and can be downloaded here https://code.visualstudio.com

When installed, just open your blog folder in it.

Let’s open a blog post and edit it!

  1. Create a new file in blog_folder/content/, let’s name it helloworld.md -.md means that we will use MarkDown as a document format.
  2. Insert some content into your first blog post:
---
title: "Hello world!"
date: 2024-04-21T20:43:04+01:00
draft: false
---

Hi, it is my first blog post!
  1. Save the file by Command+S

If the Hugo server is still live, you should be able to see your post by navigating to http://localhost:1313/, if it is not available, you can start it again by hugo server - from your blog directory.

6. Upload to GitHub

  1. In the VSCode navigate to Git Section (Source Control)
  2. Add the file that you recently created in the changes section Write a message & select Commit

At this step, you should be able to open your repository in GitHub. In the same folder/content/ you should see the file with your post.

7. Publish for everyone via CloudFlare Pages

On this step, you should already have everything prepared to go live! To do this, we need to expose the blog to the internet. We will use CloudFlare’s Pages for that.

CloudFlare’s Pages is a no-code no-server deployment, you need to link your GitHub repository with CloudFlare and after that any changes that will be pushed to GitHub will be deployed via cloudflare for everyone!

  1. Sign in to CloudFlare and navigate to: Workers&Pages –> Create Application –> Pages –> Connect to Git
  2. You need to link CloudFlare <—> GitHub accounts
  3. Select your repository with the blog
  4. Select framework Hugo, and select Project name`` - it will be also domain project_name.pages.dev.`
  5. Click Save and Deploy