How to build this blog
OS
Ubuntu 22.04.3 LTS
Install Gitea
Install Hexo on local and server
I am using Mac so the process is similar on local and server.
Install Git
Install nodejs and npm using nvm
1
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
Then restart your terminal and verify nvm command using
command -v nvm
Download the latest nodejs and npm by:
1
2nvm install node # "node" is an alias for the latest version
nvm use node # using the latest version node in all shellInstall Hexo
1
npm install -g hexo-cli
The following config only need set in local as the git will sync them.
Get start on Hexo
1 | mkdir blog |
Install nexT theme
1 | npm install hexo-theme-next |
1 | theme: next # set the theme. And also there are a lot of things need to set. |
Install sitemap
1 | npm install hexo-generator-sitemap --save |
1 | plugins: |
Enable visitors and reading counting
1 | vim _config.yml |
1 | theme_config: |
Enable image click to zoom
1 | vim _config.yml |
1 | theme_config: |
Initiate some new page
1 | hexo new page tags |
Both of them are like:
1 | --- |
Edit the template
All of your template are storaged in ~/blog/scaffolds
1 | cd scaffolds |
1 | --- |
Start your writing
1 | cd blog |
Deploy your blog on server automatically via Gitea and hooks
create a new repository on your gitea and link it in your local directory.
1
2cd blog
git remote add origin your_username@your_gitea_server:your_usernaem/Hexo.git # change the url to your git repo urlcreate a sh script in local for git hook to run.
1
2cd blog
vim deploy.sh1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
file_log=deploy.log
file_fifo=run.fifo
rm -f "$file_log" "$file_fifo"
mkfifo $file_fifo
cat $file_fifo | tee -a $file_log &
exec 3>&1
exec 4>&2
exec 1>$file_fifo
exec 2>&1
gbError="\033[1;31m[ERROR]\033[0m"
gbWarning="\033[1;33m[WARNING]\033[0m"
gbInfo="\033[1;32m[INFO]\033[0m"
gbGood="\033[1;32m[GOOD]\033[0m"
current_time=$(date "+%Y-%m-%d %H:%M:%S")
echo -e "\n <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $current_time >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> \n"
echo -e "$gbInfo Start to build and deploy hexo blog...\n"
hexo clean
hexo generate
# hexo deploy
if [ $? -eq 0 ]; then
echo -e "\n$gbGood Successfully built and deployed hexo blog!"
else
echo -e "\n$gbError Faild to deploy hexo blog, please check it!"
fi
printf "\015"
exec 1>&3
exec 2>&4
rm -f "$file_fifo"log into your sever and change work path to your git repository hook directory.
1
2
3cd /var/lib/gitea/data/gitea-repositories/doublefire.chen/hexo.git/hooks/
cd post-receive.d/
vim post-receive1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
gbError="\033[1;31m[ERROR]\033[0m"
gbWarning="\033[1;33m[WARNING]\033[0m"
gbInfo="\033[1;32m[INFO]\033[0m"
gbGood="\033[1;32m[GOOD]\033[0m"
echo -e "\n$gbInfo Hexo blog post-receive git hook is running...\n"
bare_repo=/var/lib/gitea/data/gitea-repositories/doublefire.chen/hexo.git # your git location
cloned_repo=/home/git/hexo # your temp clone location
blog_dir=/var/www/blog # your blog location
rm -rf $cloned_repo
git clone $bare_repo $cloned_repo
cd $cloned_repo
chmod +x deploy.sh
./deploy.sh
if [ $? -eq 0 ]; then
rm -rf ${blog_dir}/*
cp -rf public/* ${blog_dir}/
fiAfter writing, commit and push your changes.
1
2
3git add .
git commit -m "make some commit"
git push origin main
Install needed plugin manually
Though config file contains many function, some of them are usable only after installing essential plugin.
Install symbols count plugin
1 | npm install hexo-symbols-count-time --save |
Install search tool plugin
1 | npm install hexo-generator-searchdb --save |
Reference: