# start shadowsocks service sudo systemctl start shadowsocks
# start shadowsocks on startup sudo systemctl enable shadowsocks
# install linuxbrew sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
# install zsh sudo apt-get install zsh
# install oh my zsh, this dependends on zsh sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" vim .zshrc
# install Nginx, MySQL, Php wget http://soft.vpser.net/lnmp/lnmp1.5-full.tar.gz gunzip lnmp1.5-full.tar.gz tar xf lnmp1.5-full.tar cd lnmp1.5-full sudo ./install.sh lnmp
# 为了解决一些权限问题,www 是 nginx 配置文件中声明的 web server 的 user name # 这样就把 group 改为了 www,并且 group 用户都有 write 的权限 sudo chgrp -R www <root_dir_of_wordpress> sudo chmod -R g+w <root_dir_of_wordpress>
# in hexo root directory hexo g # generate static web files
hexo server # start local web server, then browse http://localhost:4000 to preview web pages
# copy files in public to server's directory, therefore updated pages can be browsed at https://tao93.top/
以上就是简单的用法,不过实际上我做了一些额外工作。例如为了避免 markdown 文件意外丢失,我们需要把它们备份到 server 上,server 和 local 同时丢失的可能性极小。另外,markdown 中插入图片时,可以先把图片放在本地,然后 markdown 中指向图片的本地路径,这样生成的 web 文件会把图片拷贝到 public 目录中某处,然后 html 文件引用 public 目录中的 image,这时的引用其实就是一个 url 了。但是我不是这样做的,我是先把要插入的图片拷贝到 Server 的 public 目录某处,这样就会得到一个指向次图片的 url,然后再 markdown 中直接使用这个 url。这样的话,只要 server 的图片库保持稳定,markdown 文件就不用和本地图片库绑定在一起。同样的,server 的图片库也需要备份到 local,以确保安全。下面就开始介绍以上两点。
首先是本地 source 目录需要备份到 server 上,我的方式是本地 source 目录使用 git 来追踪,然后 server 上简历一个 bare repository source.git,这样本地的每次 commit 都 push 到 server 上的 source.git,就可以作为备份了。相应的本地的 public 目录也要 push 到 server 上的 public.git 这样一个 bare repository,然后在 server 上的 public 中,从 public.git 这个 remote git pull 一下,这样 server 中的 public 就有了最新的 web 文件。
from PIL import ImageGrab, Image import sys import datetime import os
now = datetime.datetime.now()
# store image files in date format directory path in server date_path = now.strftime('%Y/%m/%d')
# use timestamp as image file name in server f_name = str(int(now.timestamp()))
if len(sys.argv) == 1: # get picture in clipboard im = ImageGrab.grabclipboard() # check whether it's a picture if isinstance(im, Image.Image): # file name in server f_name = str(int(datetime.datetime.now().timestamp())) + '.png' # save in local im.save(f_name) # the url of the image url = 'http://tao93.top/images/' + date_path + '/' + f_name # copy the url to clipboard os.system("echo '%s' | pbcopy" % url) print('url has been copied') print('copying...') dest_path = '/home/liutao/hexo_blog/public/images/' + date_path # mkdir in server and copy the image os.system("ssh liutao@tao93.top 'mkdir -p " + dest_path + "'") os.system('scp ' + f_name + ' liutao@tao93.top:' + dest_path) print('copy finished') # remove local image file os.remove(f_name) else: print('clipboard content is not a image!')
elif len(sys.argv) == 2: if os.path.isfile(sys.argv[1]): # file name in server f_name = str(int(datetime.datetime.now().timestamp())) dot_loc = sys.argv[1].rfind('.') if dot_loc >= 0: f_name += sys.argv[1][dot_loc:] # append the file extension url = 'http://tao93.top/images/' + date_path + '/' + f_name os.system("echo '%s' | pbcopy" % url) print('url has been copied') print('copying...') dest_path = '/home/liutao/hexo_blog/public/images/' + date_path os.system("ssh liutao@tao93.top 'mkdir -p " + dest_path + "'") os.system('scp ' + sys.argv[1] + ' liutao@tao93.top:' + dest_path + '/' + f_name) print('copy finished') else: print(sys.argv[1] + ' is not a file!') else: print('too much arguments')
# make sure it's commited in source directory status=$(git status -s) if [ -z "$status" ]; then # git push in source git push else echo'not commited in source directory!' exit 1 fi
# back into parent directory cd ..
# generate static web files hexo g
# git push in local public directory cd public git add . git commit -m 'update web files' git push cd ..
# git pull in server's public directory ssh liutao@tao93.top 'cd /home/liutao/hexo_blog/public; git pull'