Hexo-GitHub-Pages-Build a personal blog

1. Preparations

1. Install Node.js

  1. Download Node.js: official website download address (here take Windows as an example):

  2. Double-click the downloaded .msi file, press Next, and install it;

  3. In the cmd command window, enter the following command. If the version of Node.js can be displayed, the installation is successful.

    node -v
    

2. Install Git

  1. Download Git: official website download address (here, take Windows as an example, I downloaded it here) You can also go to the official website to download;

  2. Double-click the downloaded Git installation package, press Next to install it;

  3. In the cmd command window, enter the following command. If the version of Git can be displayed, the installation is successful.

git -version

  1. If you want to know more about Git, you can learn from the following websites. If you have a better website, you can also recommend it to me:
  • official website
  • W3Cschool
  • Liao Xuefeng Website Tutorial

2. Hexo build blog

1. Install Hexo

  1. In the computer, create a winneyBlog folder to store your own blog content.

  2. In the winneyBlog folder, right mouse button, select Git Bash, enter the command window

  3. In the command window, enter the following code:

    npm install -g hexo-cli
    

    as the picture shows:

2. Initialize Hexo

  1. In the command window, enter the following code: (a hexo folder will be created under the winneyBlog directory)

    hexo init hexo
    

    as the picture shows:

3. Configure Hexo

  1. Enter the hexo folder

    cd hexo
    
  2. install dependencies

    npm install
    
  3. deployment file

    hexo generate
    

    as the picture shows:

4. Start the server

  1. Execute the following code in the command window:

    As shown in the figure: (If you want to perform other command operations, you can press Ctrl + C to stop the server)

    hexo server
    
  2. Enter http://localhost:4000/ in the address bar of the browser (the default port is 4000). If you can see the effect as shown in the figure, it means that the initialized Hexo blog has been successfully built.
    as the picture shows:

3. Deploy the local Hexo blog to GitHub Pages

  1. Create a new warehouse named winney07.github.io (the name of this warehouse must be named in strict accordance with the format of username.github.io) [provided that you have A Github account]
    As shown in the picture: (Because I have already created this library, a red warning will be displayed, but later I will rewrite a new one with the same name for screenshots)

  2. Enter the warehouse that has been created (click your avatar, select Your profile, click the newly created warehouse to enter the warehouse), click settings, find the GitHub Pages option, click Choose a theme to choose a theme (you can choose or not) , decide whether to operate this step according to your own needs)
    as the picture shows:

  3. Configure Git personal information, in the winneyBlog directory, right mouse button, select Git Bash, enter the command window, enter the following command

    git config --global user.name "Github username" //My Github account name
    git config --global user.email "Github mailbox" // Register your own Github email address
    
  4. Generating SSH KEY means generating a public key and key, because Github needs a key to connect to the local. Enter the following command in the command window, and then you need to press Enter 3 times in a row to generate the key (you can see the corresponding information every time you press Enter) [You can also check whether you already have the ssh key: cd ~/.ssh If there is no key, there will be no such folder, and if there is, the backup will be deleted]

    ssh-keygen -t rsa -C "Github mailbox" //Register your own Github email address
    

    as the picture shows:

  5. The generated SSH KEY will be saved to the C:/Users/computer name/username/.ssh directory (according to your own computer user name, open the corresponding directory)

    (1) Open the .ssh directory, open the id_rsa.pub file, and copy all the contents inside (these contents are the keys)

  6. Add SSH keys to GitHub

    1. Open Github, click on the avatar, and select Settings;

    2. Select the SSH and GPG keys item, click the New SSH key button in the upper right corner, and paste the newly copied key into the key input box, title just give it a name

    3. Finally click Add Key, if this interface is displayed, it means that the SSH KEY configuration is successful:

  7. Modify the global configuration file

    1. Under the hexo folder, find the _config.yml file;
      as the picture shows:

    2. Copy warehouse address:
      as the picture shows:

    3. Modify the deploy attribute in the _config.yml file (the purpose is to put the local hexo project on Github)
      as the picture shows:

      Note: [If the https protocol is filled in repository, and hexo d uploads the code to Github with the following similar error, you can replace repository to link to ssh]
      as the picture shows:

  8. Install the hexo-deployer-git plugin to quickly host the code on Github

    npm install hexo-deployer-git --save
    
  9. Host the hexo project on GitHub (commands can be written separately or together)

    hexo clean & amp; & amp; hexo generate & amp; & amp; hexo deploy
    

    Remarks:
    hexo clean : Clear cache files (db.json) and generated static files (public)
    hexo generate : Pre-generate static files before deployment, abbreviated as hexo g
    hexo deploy : Deploy the website immediately after the file is generated, abbreviated as hexo d

  10. Enter https://username.github.io/ in the browser address bar to access, (username is your Github account name), if it can be accessed normally, and the content displayed by the local hexo project is the same, then it means You have deployed your local hexo project to Github.

4. Configure blog personal information

  1. In the hexo directory, find the global configuration file _config.yml

  2. The configuration information is as follows:

    # Hexo Configuration
    ## Docs: https://hexo.io/docs/configuration.html
    ## Source: https://github.com/hexojs/hexo/
    
    # Site site information configuration
    title: winney #site name
    subtitle: It is never too old to learn. #Site subtitle
    description: Doing is better than saying. #Site Information Introduction
    keywords: winneyBlog Blog
    author: winney #site author
    language: zh-Hans #site language, default is English, zh-Hans is Chinese
    timezone: Asia/Shanghai #timezone
    
    # URL blog address
    ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    url: https://AAAAAAAAAA.github.io/
    root: /
    permalink: :year/:month/:day/:title/
    permalink_defaults:
    
    # Directory directory settings
    source_dir: source
    public_dir: public
    tag_dir: tags
    archive_dir: archives
    category_dir: categories
    code_dir: downloads/code
    i18n_dir: :lang
    skip_render:
    
    # Writing article layout
    new_post_name: :title.md # File name of new posts
    default_layout: post
    titlecase: false # Transform title into titlecase
    external_link: true # Open external links in new tab
    filename_case: 0
    render_drafts: false
    post_asset_folder: true
    relative_link: false
    future: true
    highlight:
      enable: true
      line_number: true
      auto_detect: false
      tab_replace:
      
    # Home page setting Home page setting
    # path: Root path for your blogs index page. (default = '')
    # per_page: Posts displayed per page. (0 = disable pagination)
    # order_by: Posts order. (Order by date descending by default)
    index_generator:
      path: ''
      per_page: 3 #number of articles per page
      order_by: -date
      
    # Category & amp; Tag categories and tags
    default_category: uncategorized
    category_map:
    tag_map:
    
    # Date / Time format date / time format
    ## Hexo uses Moment.js to parse and display date
    ## You can customize the date format as defined in
    ## http://momentjs.com/docs/#/displaying/format/
    date_format: YYYY-MM-DD
    time_format: HH:mm:ss
    
    # Pagination archive display
    ## Set per_page to 0 to disable pagination
    per_page: 10
    pagination_dir: page
    
    # Extensions extension
    ## Plugins: https://hexo.io/plugins/
    ## Themes: https://hexo.io/themes/
    theme: next
    
    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
      type: git #deployment type
      repository: https://github.com/AAAAAAA/AAAAAAA.github.io.git #warehouse address
      branch: master #branch name
      message: hexo deploy #submit information
    
    #Search
    search:
      path: search.xml
      field: post
      format: html
      limit: 10000
    

    Note: The .yml file has strict format requirements. All configurations in the file are: colon space value, and the colon is the input in English. If you want to know more, you can go to the official website.

  3. In the blog directory, right-click Git Bash, enter the command window, enter the following command, and you can see the content you just set is displayed on the page in the browser:

    hexo server // abbreviated as hexo s
    

Submit to the remote warehouse to report an error

Report 403 or enter the account password every time you submit

You can put _config.yml in

repository: https://github.com/********.github.io.git #warehouse address

Change to:

repository: [email protected]:********.github.io.git #warehouse address

Originality is not easy, please indicate the source of this article and the link to the original article when reprinting.

Like it, if this article is helpful to you, please give it a like, it will be the driving force for my creation!

Bookmark, if you think this article is of reference value, please bookmark it for future reading.

Comments, welcome to share your thoughts and suggestions with me in the comment area, it will be my greatest support and encouragement.