Verson: 0.0.1
Foreword
This blog post mainly introduces the blog construction and related content based on Hexo and Github Pages.
Environment build
Install Nodejs
- Go to the official website to download the latest Nodejs installation package.
- Run the installation package to install, note that you need to select
Add to PATHin theCustom Setupstep.
Install Git
- Go to the official website to download the latest Git installation package.
- Run the installation package to install.
Verify Nodejs installation configuration
- Right click anywhere and select
Git BashHere. - Execute the command
node -vandnpm -v. If the output information is the version number, it proves that the configuration is successful.
Install cnpm
- Execute the command
npm install -g cnpm --registry=https://registry.npmmirror.comornpm install -g cnpm --registry=https://registry.npmjs.orginGit Bash. - Execute the command
cnpm -v. If the output information is the version number, it proves that the configuration is successful.
Hexo
Install Hexo
- Execute the command
cnpm install hexo-cli -ginGit Bash. - Choose a suitable location to create a
blogfolder, openGit Bashin thisblogfolder and execute the commandhexo init. Note that in the mainland network environment, there may be a freeze atInstall dependencies. If the installation freezes for a long time, you could execute the commandCtrl+Cto end the command Install dependencies, and execute the commandcnpm installto continue to use the mainland mirror to complete the initialization of the hexo blog. - Execute the command
hexo serverto preview the blog. The output URL is generally http://localhost:4000/, which is the preview page for local deployment.
Replace Hexo theme
The Hexo official website provides a large number of Hexo themes for users to choose.
If you want to practice this step of replace Hexo theme, you can choose the Next theme. The Next theme provides preview effects, project addresses and configuration documents, which is quiet easy to grasp.
Download other themes
- Open the project addresses of the theme you enjoy, click the
Clone or download. - Copy the address started with “https://“.
- Open
Git Bashin yourblogfolder and execute the commandgit clone *address you copied* themes/*theme name*. Here,git clonestands for cloning, followed by the download addresses you just copied. The lastthemes/*theme name*is to download the folder to the theme directory, and name the theme file “theme name”.
Modify the configuration file to enable the new theme
- Open the file named
_config.ymlin the blog directory. - Find the line
themes, and then change the theme name to*theme name*you have just named.
Generate new blog posts
- Open
Git Bashin yourblogfolder and execute the commandhexo new *your blog name*. - Each generated blog post is stored in
source/_postsunder yourblogfolder. - Blog posts are generally markdown-based
.mdformat files. You could further write and revise your blog posts.
Git
Create new repository
Click the Create repository button to create a new repository. The name of new repository must be *your user name*.github.io.
Generate a git key and link
- Open
Git Bashin yourblogfolder and execute the commandssh-keygen -t rsa -C "your_email@youremail.com". No matter what message appears, you just need to pressEnter. - Execute the command
cat ~/.ssh/id_rsa.pub. Thesecret keyis output. You could copy the output key directly. - Click the
avatarof your github, clickSettings–SSH and GPG keys–New SSH Key. - Paste the
secret keyyou just copied in the key text box. Click the buttonAdd SHH key. - Open
Git Bashin yourblogfolder and execute the commandssh -T git@github.com. The output information will promptAre you sure you want to continue connecting (yes/no/[fingerprint])?, enteryes, and then pressEnter. - Open your repository, click the
Clone or download–Use SSH. Copy the address started with “git”. Open site configuration file. Modify deployment information_config.yml.1
2
3
4deploy:
type: git
repo: *the address started with "git" you just copied*
branch: master - Open
Git Bashin yourblogfolder and execute the commandgit config --global user.name "yourname"and commandgit config --global user.email "youremail".
Deploy and upload
- Install the upload plugin. Open
Git Bashin yourblogfolder and execute the commandcnpm install hexo-deployer-git --save. - Upload. Open
Git Bashin yourblogfolder and execute the commandhexo g -d.
Preview
- Open
Git Bashin yourblogfolder and execute the commandhexo s. - Your local preview version will be running at http://localhost:4000/.