Deploy Hexo static blog for free using Vercel
Install Hexo#
- Refer to the official documentation Documentation | Hexo
- In theory, you only need to complete the "Overview" and "Setup" steps
- Install themes: see later section
Create a GitHub remote repository#
- Create a new repo on GitHub with any name, leave other settings unchanged, and it can be set as private
- Generate a Personal access token in your account settings and keep it secure.
Create a local git repository and push to GitHub#
- Go to the root directory of Hexo
# Create a git repository
git init
git add .
git commit -m "first commit"
git branch -M main
# Connect to GitHub, example: https://github.com/<username>/<repo>.git
git remote add origin <your remote repository address>
# Set credential helper, remove --global parameter to save only for the current repository
git config --global credential.helper store
git push -u origin main
# It will prompt for username and password, note that the password is the previously generated Personal access token, not the password of your GitHub account
Deploy using Vercel#
- Log in to vercel.com with your GitHub account
- Choose to add a new project from GitHub and select the repo you just created
- It will automatically recognize it as a Hexo project, no need to make any changes, just confirm
- Now you can access it using the domain provided by Vercel or use your own domain
- If there are any changes in the local project, use
git add .
,git commit
,git push
, and Vercel will automatically update
Notes#
About themes#
- There are pros and cons to both
git clone
andgit submodule add
, you can choose after understanding them
git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly
# or
git submodule add https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly
About file names#
- If you paste a Markdown file from elsewhere, remember to remove special characters from the file name, otherwise, although it can run locally, it will result in a 404 error on Vercel
- If it is a file created using
hexo new
, you will notice that even if there are special characters, they will be automatically removed from the file name (not affected in Front-matter), so you can confidently use special characters.