Sync Hexo Blog Project Using Rsync Nov 9th 2021 Words: 178

Problem

I want to find a way to sync my hexo blog, so that I can work on it at any workplaces. The problem is, my blog contains a lot of images and attachments, so it is not feasible to put it on git. I have tried to store the project directory in my NAS, and run it over network, but running a Node project remotely has a rather terrible experience.

Solution

The ideal solution for me is to sync only the source file and assets through my NAS, and run the node project locally. The selective sync can be achived with rsync easily, since the rsync supports gitignore file. I created the following script and put it in the root directory of my hexo directory.

sync.sh
1
2
3
4
5
6
#!/usr/bin/env bash

SOURCE="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
[email protected]:/path/to/my/blog

rsync --delete-after --filter=":e- .gitignore" --filter "- .git/" -a $SOURCE/ $TARGET

Reference