Hexo Best Practice Recommendations

This practice is actually a directory operation specification that, ultimately for ease of use, requires personalized and frequently changing directories or files to be isolated, initialized with a simple Shell script, and upgraded with the NexT theme.

Note: Summary from personal use may not be suitable for everyone, for reference only.

<!-- more -->

1. Final directory structure

.
├── config_hexo.yml # Soft Link to Hexo Profile
├── config_next.yml # Soft Link to NexT Theme Profile
├── core # Hexo root directory, customizable
│   ├── _config.yml -> ../config_hexo.yml # Personally modified profile
│   ├── _config.yml.bak # Original Hexo Profile
│   ├── db.json
│   ├── node_modules
│   ├── package-lock.json
│   ├── package.json
│   ├── public
│   ├── scaffolds
│   ├── source -> ../source_hexo # Resource catalog after personal change
│   ├── source_bak # Backup of the original Hexo resource directory
│   └── themes
│       ├── landscape # Hexo Default Theme Root Directory
│       └── next # NexT Theme Root Directory
│          ├── LICENSE.md
│          ├── README.md
│          ├── _config.yml -> ../../../config_next.yml # Personally modified profile
│          ├── _config.yml.bak # Backup of original theme profile
│          ├── crowdin.yml
│          ├── docs
│          ├── gulpfile.js
│          ├── languages
│          ├── layout
│          ├── package.json
│          ├── scripts
│          └── source # Resource directory under theme
├── deploy.sh # 3. Synchronize remote server scripts
├── init.sh # 1. Hexo Initialization Script
├── source_hexo # Soft Link to Resource Directory under Hexo
├── source_next # Files that need to be added to the resource directory under NexT are placed here
└── update_next.sh # 2. NexT Theme Upgrade Script

1.1. On Github we need to build two warehouses

  • username/username.github.io corresponds to the target directory for the Hexo deployment and is set in the configuration file under the Hexo root directory.
  • The username/blog.xxx.com name is arbitrary and corresponds to the directory above.The core directory needs to be added to the.gitignore file.

1.2. How to use

⚠_Instructions: Only steps 3-5 are required for each writing, and only when switching to a new working environment will complete steps 1-5.

  1. Pull down environment warehouse from Github

    ➜  git clone https://github.com/username/blog.xxx.com.git
    
  2. Initialize the Hexo environment

    # ⚠Prerequisite: You have installed the NodeJS environment and hexo-cli
    # You can modify the shell file yourself if you want
    ➜  chmod u+x init.sh
    ➜  ./init.sh
    
  3. Enter the Hexo root directory

    # The name of the core can be modified in the script init.sh
    ➜  cd core
    
    # Create an article
    ➜  hexo new post "A new article"
    
  4. Hexo Release Deployment

    ➜  hexo clean && hexo g -d
    
  5. Push this modification to warehouse

    # Step back to the core directory to the next level, the warehouse root directory
    ➜  git add .
    ➜  git commit -m "New Articles"
    ➜  git push
    

2. Script files

init.sh

When switching to a new workspace, use this script to initialize Hexo and the workspace based on the original data, then you can continue to write articles and publish.

The sample file is as follows:

# Initialize Hexo
# Note that the NodeJS environment and hexo-cli are not checked here
# Self-expanding if needed
hexo init core

# Install dependencies, modify configuration
cd core
npm install
npm install hexo-deployer-git --save
npm install hexo-generator-searchdb --save
npm install hexo-abbrlink --save
npm install hexo-generator-sitemap --save
npm install hexo-generator-baidu-sitemap --save
npm install hexo-filter-nofollow --save
mv _config.yml _config.yml.bak
ln -s ../config_hexo.yml _config.yml
mv source source_bak
ln -s ../source_hexo source

# Install, configure theme
git clone https://github.com/theme-next/hexo-theme-next themes/next
cd themes/next
mv _config.yml _config.yml.bak
ln -s ../../../config_next.yml _config.yml
\cp -rp ../../../source_next/* source

update_next.sh

When NexT themes need to be upgraded, the sample file is as follows:

# Restore local changes
cd core/themes/next
git checkout . && git clean -xdf

# Update Source
git pull

# Restore Modifications
mv _config.yml _config.yml.bak
ln -s ../../../config_next.yml _config.yml
\cp -rp ../../../source_next/* source

deploy.sh

This script is not required and is only available if you need to distribute the final deployed files to different servers.

The rsync command is recommended for synchronization, but there are no more specific examples.Refer to: Getting started with basic usage of rsync

Original Link: https://blog.sqiang.net/post/1938539149.html

Keywords: git npm github JSON

Added by jacksonpt on Wed, 25 Mar 2020 06:01:39 +0200