Use Hexo to quickly build a blog and deploy it to Github

Source: Internet
Author: User
Tags install node

Use Hexo to quickly build a blog and deploy it to Github

This article aims to record the process of setting up a blog through Hexo and deploying it on Github. It will also help me learn and reference it quickly in the future. For more details or official documents, click the official Hexo document.

Prerequisites

Installing Hexo is very simple. Pre-installation required:

  • Node. js
  • Git

Install and configure Node. js v4.0.0 on Ubuntu 14.04/15.04

How to install Node. js in CentOS 7

Build a Node. js development environment in Ubuntu 14.04

Git server setup and Client installation

After the prerequisites are met, you can start to install Hexo.

Install Hexo

Open Git Bash and execute the command

1
$ npm install -g hexo-cli

 

Create a blog

After Hexo is installed, run the following commands respectively. Hexo automatically generates the required folder.

1
2
3
$ Hexo init <folder >## <folder> specifies the file address for you
$ Cd <folder>
$ Npm install

For example, if you want to build a blog under D: \ my_hexo, run the following commands:hexo init D:\my_hexo,cd D:\my_hexo,npm install
After executing the command, if there is no problem, we can execute the startup command to view our blog.

Local Preview
1
2
3
$ Hexo server # Start the service. The default port is 4000.
$ Hexo server-p xxxx # Start the service through a custom Port
$ Hexo clean # Clear cache. You can run this command when the page is abnormal.

Enter http: // 127.0.0.1: 4000/in the browser to access

Create Repository
  1. Log on to github and click "+" in the upper right corner to Create a new repository.

Create a new repository

  1. Copy the newly created https connection:https://github.com/Admol/admol.github.io.git
  2. Open_config.yml
  3. Set deploy information, such:
    1
    2
    3
    4
    deploy:
    type: git
    repository: https://github.com/Admol/admol.github.io.git
    branch: master

 

Set SSH key
  1. Check whether a key already exists
    Execute commands separately

    1
    2
    cd ~
    cd .ssh

    Then execute the commandlsCheck that an existing key file exists. If a key exists, it is displayed.id_rsa.pubAndid_dsa.pubNo key is displayed for these two files.

  2. Add an SSH key

    Run the following command (skip step 2 if the key already exists ):

    1
    2
    3
    $ Ssh-keygen-t rsa-C "your_email@mail.com"

    # T specifies the key type. The default value is rsa, which can be omitted. -C: Set the comment text, such as email address or other text.

    Then you will be promptedEnter Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [Press enterEnter a file name to save the ssh key. The defaultid_rsa.pubAndid_dsa.pub

    After you press enter, you need to enter the password twice (this password is the password you need to enter when you push the file, rather than the github password)
    After entering the password, the following information is displayed. The SSH key is successfully added.

  3. Set SSH key on Github

    Log on to github and clickSettingsAnd then clickSSH keysOn this page, you can manage all your ssh keys
    Then clickAdd SSH key
    Open the added key file in a text editorid_rsa.pub, Copy all content in it
    Return to the github page and paste the copied content to the text box corresponding to the key of the page. You can enter the title as needed.

  4. Test whether the ssh key is successfully added.
    On the command line, enter:

    1
    $ ssh -T git@github.com

    There will be a warning code. Enter yes and press Enter. Then you will be asked to enter the password you just set. Then it will say to you:Hi, handsome guy... about?

Now the SSH key is set.

Deploy to Github

Open the command window and return to your hexo blog directory. Do not execute the following command:

1
2
hexo generate
hexo deploy

 

After the command is executed, you can check whether the Code has been submitted to github, and enter admol. github. io in the browser to access it.

 

Create page
1
$ hexo new page 'pageName'

After executing the command, you can/sourceThe folder named after the page is added to the directory.

Display page

After opening the file, you canindex.mdEdit and open/themes/jacmanDirectory_config.ymlFile (the topic you are using ),
Add the newly added page:

1
2
3
4
5
Menu:
Homepage :/
Statistics:/archives
About:/about
PageName:/pageName # the preceding pageName can be customized, and the following pageName must be the name of the newly added page.

 

Create an article
1
$ hexo new [layout] 'name'

[Layout] is optional. If this parameter is left blank, the default value is post./sourceThe folder name under the directory islayoutName

Installation topic
1
$ git clone https://github.com/JamesPan/hexo-theme-icarus.git themes/icarus
Change subject

First download the topic, and then open_cinfig.yml, ModifyTheme: name of the topic to be changed

Modify topic color

Open/themes/jacmanDirectory_config.ymlFile, modify:

1
2
Theme_color:
Theme: 'color value'

 

Modify logo image

Open_config.ymlFile, modify:

1
2
3
4
Imglogo:
Enable: false # Show logo
Src: img/logo.gif # logo image address
Favicon: img/qq. ico # icon in the upper left corner of the page

Hexo Version Upgrade

1
$ npm update hexo -g

GitHub Tutorials:

Create a personal technical blog via GitHub

GitHub tutorials

Git tag management details

Git branch management

Git remote repository details

Git local Repository (Repository) Details

Git server setup and Client installation

Git Overview

Share practical GitHub tutorials

GitHub details: click here
GitHub: click here

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.