野声

Hey, 野声!

谁有天大力气可以拎着自己飞呀
twitter
github

How to create a better Hexo user experience

I often update my blog on webide, but this is only possible when there is an internet connection. If I want to debug locally, I need to synchronize the source files to my local machine before losing internet access. This functionality can be achieved using git.

The basic idea is to create a branch in the blog's repository to backup the source files. Before deploying the webpage, you can synchronize the source files to the backup branch, and then pull them back locally when needed.


Backup to Repository#

You need to have git installed.
First, you need to add a remote repository in the root directory of your blog.

# git remote add [shortname] [url]
# [shortname] sets the name of the repository
# [url] is the link to the remote repository
git remote add hexo https://git.coding.net/Artin/Artin.git

Then create a new branch:

git branch backup

Switch to the backup branch:

git checkout backup

Then execute the following command in the root directory of your blog:

git add .
git commit -am "update"
git push hexo backup

You can refer to Liaoxuefeng's git tutorial for more information.

For those who encounter push theme failure, you can delete the .git in the theme folder, or simply not push the theme.


A More Convenient Method#

First, create a git.sh file in the root directory of your blog. Enter the following code in the file:

#!/bin/bash/
# The path here should be the path to your blog
cd /home/ubuntu/workspace/hexo/
echo "Executing hexo clean"
hexo clean
echo "hexo clean executed"
echo "Pushing source code"
git add .
git commit -am "update"
git push hexo master
echo "Pushing source code executed"
echo "Executing hexo g -d"
hexo g -d
echo "hexo g -d executed"

In the future, if you want to update your blog, simply enter the following command in the root directory of your blog:

sh git.sh
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.