hexo 迁移到树莓派遇到大坑

之前放在hexo是放在Windows 里的,文章里没加data字段。

然后这个星期把hexo博客迁移到了树莓派,发现网站发布文章的日期都是今天的。

还得一片一片加data时间,还好文章不多。

记下笔记。

title: 太子湾公园附近
date: 2021-02-22
category:
- 杭州周边旅游景点
- 太子湾公园附近
tags:
- 太子湾公园附近

搞了个树莓派重启自动运行hexo 脚本,并自动上传文件到GitHub(防止树莓派崩了)

首先是创建启动hexo 脚本

脚本

#!/bin/bash
echo "执行hexo"
USER=$(whoami)
pid=$(ps -ef | grep hexo | grep -v grep | awk 'NR==1 {print $2}')
kill ${pid}
cd /home/hexo/blog
hexo g
# 自动同步到github
git config --global user.email "email"
git config --global user.name "name"
#git checkout -b master
git add .
git commit -m "更新hexo"
git push -u origin +master
nohup hexo server &

git命令行执行,git配置GitHub可以百度

echo "# hexo_saiita.cn" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/a506488043/hexo_saiita.cn.git
git push -u origin main

然后在 /etc/rc.local文件exit 0之前, 添加执行脚本的命令行(su saiita -c "exec /home/shell/auto.sh" )

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %sn" "$_IP"
fi

# 开启hexo

su saiita -c "exec /home/shell/auto.sh" 

exit 0



知识共享许可协议本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。

相关推荐

暂无评论