Kamus
2024-05-27

How to build...

Why use WSL

Using Windows Subsystem for Linux (WSL) instead of relying solely on Windows can offer several advantages, particularly for developers and IT professionals. WSL allows users to run a GNU/Linux environment directly on Windows, without the overhead of a traditional virtual machine or dual-boot setup. This enables seamless access to a wide range of Linux tools and utilities, which are often preferred for development tasks, scripting, and system administration. Additionally, WSL provides a more consistent and familiar environment for those accustomed to Unix-based systems, facilitating smoother workflows and integration with cloud-based services. By leveraging WSL, professionals can enjoy the best of both worlds: the robust software ecosystem of Windows and the powerful command-line capabilities of Linux.

Why use Hexo

Hexo offers several advantages over WordPress, particularly for developers and tech-savvy users. As a static site generator, Hexo provides faster load times and improved security since it does not rely on a database or server-side processing, which are common vulnerabilities in WordPress. Additionally, Hexo allows for greater customization through its use of Markdown and extensive plugin ecosystem, enabling users to tailor their sites to specific needs without the overhead of a complex content management system. Furthermore, Hexo’s deployment process is streamlined, often integrating seamlessly with version control systems like Git, making it an excellent choice for those who prioritize efficiency and performance in their web development projects.

Why use Github Pages

Using GitHub Pages instead of a traditional hosting server offers several distinct advantages. Firstly, GitHub Pages provides a seamless integration with GitHub repositories, enabling automatic deployment of websites directly from your codebase. This integration ensures that updates and changes to your site are effortlessly managed through version control, promoting a streamlined workflow. Additionally, GitHub Pages is cost-effective, offering free hosting with custom domain support, which can significantly reduce overhead costs for personal projects or small businesses. The platform also boasts robust security features, leveraging GitHub’s infrastructure to protect your site from common vulnerabilities. Furthermore, the simplicity and ease of use make GitHub Pages an attractive option for developers who want to focus on writing code rather than managing server configurations and maintenance. Overall, GitHub Pages combines efficiency, cost savings, and security, making it an excellent choice for hosting static websites and project documentation.

GO!

Assume already has a WSL environment running

If not, refer to “How to install Linux on Windows with WSL“.

To say we are running WSL distro - Ubuntu 22.04

1
2
3
4
5
6
7
8
9
10
11
12
13
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.4 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

Install Node.js

Since Hexo is written by Node.js, nodejs must be installed.

1
2
sudo apt update
sudo apt install nodejs npm

Install GIT

Since Hexo uses Git to publish pages on GitHub, Git must be installed.

1
sudo apt install git

Install Hexo

1
sudo npm install -g hexo-cli

Init Hexo project

Our goal is to deploy the static HTML file generated by Hexo to GitHub Pages. To achieve this, we need to create a repository named “[username].github.io” on GitHub. Therefore, we will initialize this directory directly using Hexo. Note: Be sure to replace [username] with your actual GitHub username.

1
hexo init kamusis.github.io

Create Github pages

Creating GitHub Pages is very simple, reference: https://pages.github.com/

Connecting to Github with SSH

Reference: https://docs.github.com/en/authentication/connecting-to-github-with-ssh

Basically, generate a key using the ssh-keygen command and upload the public key to the GitHub.

Once the SSH connection is established, use the following command to verify it:

1
2
$ ssh -T git@github.com
Hi kamusis! You've successfully authenticated, but GitHub does not provide shell access.

Set URL for your new blog

1
2
3
4
5
6
$ vi _config.yml

~~~~~~~~~~~~~~~~~~ _config.yml ~~~~~~~~~~~~~~~~~~
# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: http://kamusis.github.io

Set Git information to let hexo can push contents into Github Pages

1
2
3
4
5
6
7
8
9
10
$ npm install hexo-deployer-git --save
$ vi _config.yml

~~~~~~~~~~~~~~~~~~ _config.yml ~~~~~~~~~~~~~~~~~~
# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: git
repo: git@github.com:kamusis/kamusis.github.io.git
branch: master

Generate the site and push to Github pages

1
2
$ hexo clean
$ hexo deploy

Assuming everything has been set up correctly, you can now view a hello-world article on a website by navigating to https://[username].github.io.

Write your articles and publish

1
hexo new "My first post"

A markdown file will automatically be created and placed in the source/_posts directory. It can then be edited and saved using your preferred text or markdown editor.

Of course, you can also clean up the initial hello-world article.

1
rm source/_posts/hello-world.md

Publish the articles.

1
2
$ hexo clean
$ hexo deploy

Reference:

https://hexo.io/docs/github-pages#One-command-deployment

https://gist.github.com/btfak/18938572f5df000ebe06fbd1872e4e39