In this article, we’re going to show one way (among many) to automate the publishing process for a Jekyll site. This is an advanced article and requires referencing of other information. Where appropriate, links to supporting material have been provided.
Before proceeding with this article, it is highly recommended that you familiarize yourself with Git. Git is a popular version control system we will use to publish our site.
But, if you already know Git well, and you’re ready to proceed, we will learn how to publish a Jekyll site with Git.
Make Sure Git is Installed
In order to use the automation process we’re going to show here, you must have Git installed on your computer (local) and your server (remote).
Initialize Git in Your Jekyll Directory
First, we will need to go into our Jekyll site directory via command line and initiate a Git repository.
- Open your terminal application
- Use the cd command to change into the Jekyll site directory on your computer
- Run the Git initialization command here
[email protected]$ git init
You have now initialized a Git repository in your local site. You can now use Git to version control your site and push it to your server. Keep reading to find out how to accomplish this.
Add a Remote Repository to Your Server
In this stage of the process, we’re going to create a remote Git repository on our server. This remote repository will server many purposes. It will be a place to store your site information remotely, and thus can be used as backup. It will also be able to “check out” or publish the site files.
Here we will reference our full guide on publishing files to your server with Git. However, in this instance, use this as the post-receive hook:
#!/bin/sh git --work-tree=/home/userna5 --git-dir=/home/userna5/production.git checkout HEAD -- /public_html
As in the reference guide, make sure to substitute userna5 with your correct cPanel username.
Change Your Site’s Base Directory (Important)
You may remember in the article about customizing Jekyll, we learned that you can change the “build” directory for your site. This is know as the base directory. It’s the directory from which the site is served.
Your InMotion Hosting server (with cPanel) has already chosen
public_html as the root directory for serving your site. You could change this behavior, but it would be easier to work with it instead. In order to do this you will just need to create a folder called
public_html in your site directory. Then, change the base directory for your site to that
public_html folder. Now, when you run the jekyll build command, your site files will be built in the
Completing the Process
Now you have a local and remote repository for your site. Using the jekyll build command, you can now build your site to the
public_html directory. Then, you can use Git to push the site to the remote repository and simultaneoulsy checkout the site files to the appropriate folder.