Building a Blog with Hexo and Github Pages

Required Environment⌗
- Node.js
- Git
Installation⌗
yarn global add hexo-cli
npm install hexo-cli -g
Creating a Site⌗
hexo init <folder>
cd <folder>
yarn or npm install
After creation, the directory structure of the specified folder is as follows:
.
├── _config.yml
├── package.json
├── scaffolds
├── source
| ├── _drafts
| └── _posts
└── themes
Now you can start writing your blog…
Generating Static Files⌗
hexo generate
Hexo will create a directory for static files according to the public_dir configuration item in the _config.yml file (static files must run in an HTTP server environment). Here you need to set its value to docs, because Github Pages reads static files from the docs directory of the repository by default.
Deployment⌗
yarn add hexo-deployer-git
npm install hexo-deployer-git --save
Configure Deployment Parameters⌗
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repository: [email protected]:USERNAME_OR_ORGNAME/REPOSITORY_NAME.git
branch: master
Deploy⌗
hexo deploy
You can also deploy directly when generating static files
hexo generate --deploy or hexo deploy --generate
The above two commands produce the same result: first generate static files, then execute the deployment task! For detailed instructions, you can read the official documentation
Next, I will write a blog post about how to set up a custom domain based on Github Pages and enable HTTPS.
I hope this is helpful, Happy hacking…