Jekyll private deployment?

回眸只為那壹抹淺笑 提交于 2019-12-04 19:38:18

If you don't want to use GitHub Pages, AFAIK there's no other way than to compile your site each time you make a change.

But of course you can script/automate as much as possible.
That's what I do with my own blog as well. I'm hosting it on my own webspace instead of GitHub Pages, so I need to do these steps for each update:

  1. Compile on local machine
  2. Upload via FTP

I can do this with a single click (okay, a single double-click).


Note: I'm on Windows, so the following solution is for Windows.
But if you're using Linux/MacOS/whatever, of course you can use the tools given there to build something similar.


I'm using a batch file (the Windows equivalent to a shell script) to compile my site and then call WinSCP, a free command-line FTP client.

WinSCP allows me to store session configurations, so I saved the connection to my server there once.
Because of this, I didn't want to commit WinSCP to my (public) repository, so my script expects WinSCP in the parent folder.

The batch file looks like this:

call jekyll build

echo If the build succeeded, press RETURN to upload!

pause

set uploadpath=%~dp0\_site
%~dp0\..\winscp.com /script=build-upload.txt /xmllog=build-upload.log

pause

The first parameter in the WinSCP call (/script=build-upload.txt) specifies the script file which contains the actual WinSCP commands

This is in the script file:

option batch abort
option confirm off

open blog
synchronize remote -delete "%uploadpath%"

close
exit

Some explanations:

  1. %~dp0 (in the batch file) is the folder where the current batch file is
  2. The set uploadpath=... line (in the batch file) saves the complete path to the generated site into an environment variable
  3. The open blog line (in the script file) opens a connection to the pre-saved session configuration (which I named blog)
  4. The synchronize remote ... line (in the script file) uses the synchronize command to sync from the local folder (saved in %uploadpath%, the environment variable from step 2) to the server.

IMO this solution is suitable for non-technical persons as well.
If the technical person in your case doesn't know how to use source control, you could even script committing & pushing, too.

There are a number of options available which are mentioned in the documentation: http://jekyllrb.com/docs/deployment-methods/

If you are using Git, I would recommend the Git Post-Receive Hook approach. It simply builds the site after the new code is received:

GIT_REPO=$HOME/myrepo.git
TMP_GIT_CLONE=$HOME/tmp/myrepo
PUBLIC_WWW=/var/www/myrepo

git clone $GIT_REPO $TMP_GIT_CLONE
jekyll build -s $TMP_GIT_CLONE -d $PUBLIC_WWW
rm -Rf $TMP_GIT_CLONE
exit

Since you mentioned that it will be updated by a non-technical person, you might try something like rack-jekyll to automatically rebuild when new files are FTP'd.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!