5

个人博客搭建3——hexo

 2 years ago
source link: https://ljason.cn/Linux-SetUp-hexo/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

  其实在很久以前我的博客就改用 hexo 了,现在就来说说怎么装。

  第一步还是安装 gcc:

apt-get install gcc g++

安装 node

  安装 node,上一篇有讲,这里就不说了。

  我写了个自动更新 node 的脚本,如果要用这个脚本还得先安装 jq:

apt-get install -y libonig-dev
# 这里改成下载的路径
cd /mnt/storage/home/down
rm -rf oniguruma
git clone https://github.com/kkos/oniguruma.git && cd oniguruma/
autoreconf -vfi && ./configure
make && make install

cd .. && rm -rf jq
git clone https://github.com/stedolan/jq.git && cd jq
autoreconf -i && ./configure --disable-maintainer-mode
make && make install

  接下来把脚本保存为 AutoUpdateNode.sh

#!/bin/bash

# 这句是配合 polipo 科学上网用的,如果下载 node 太慢就请使用 polipo 并取消注释
# export http_proxy=http://127.0.0.1:8123/ && export https_proxy=http://127.0.0.1:8123/

# 这里改成下载的路径
path=/mnt/storage/home/down
latest=$(curl https://nodejs.org/dist/index.json | jq ".[0].version" | sed 's/\"//g')
node=$(node -v)

install(){
cd $path
rm -rf node*
wget -c https://nodejs.org/dist/$latest"/node-$latest".tar.gz
tar zxvf node-$latest.tar.gz
cd node-$latest/
./configure && make && make install
}

if [ "$latest" != "$node" ];then
install
fi

  给脚本添加可执行权限:

chmod +x /mnt/storage/home/script/AutoUpdateNode.sh

  添加定时更新,执行:

crontab -e

  添加一行:

0 6 * * * /mnt/storage/home/script/AutoUpdateNode.sh

安装 hexo(需要科学上网)

npm install -g hexo-cli

  新建一个博客:

hexo init myBlog
cd myBlog/
npm install

  这样就新建好一个博客了,可以在 source_posts 文件夹里面添加文章,用 markdown 写。

  等添加完就可以生成静态网页了:

hexo g

  有时候会出现一些奇奇怪怪的问题,就在生成静态页面之前删除之前的缓存即可:

hexo cl
hexo g

  写完博客玩魂2啦٩(๑>◡<๑)۶


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK