oliverdavies.uk/source/_posts/publishing-sculpin-sites-with-github-pages.md

4.2 KiB
Raw Permalink Blame History

title date excerpt tags meta
Publishing Sculpin Sites with GitHub Pages 2017-07-13 How I moved my website to GitHub pages.
github
php
sculpin
image
url type height width
/images/blog/jackson-octocat.png image/png 200 451

![](/images/blog/jackson-octocat.png)

Earlier this week I moved this site from my personal Linode server to GitHub Pages.

This made sense as I already kept the source code in on GitHub, the issue was that GitHub Pages doesnt know how to dynamically parse and generate a Sculpin site like it does with some other static site generators. It can though parse and serve HTML files, which is what Sculpin generates. Its just a case of how those files are added to GitHub.

Ive seen different implementations of this, mostly where the Sculpin code is on one branch, and the generated HTML code is on a separate gh-pages or master branch (depending on your repository name). Im not fond of this approach as it means automatically checking out and merging branches which can get messy, and also its weird to look at a repos branches page and see one branch maybe tens or hundreds of commits both ahead and behind the default branch.

This has been made simpler and tidier now that we can use a docs directory within the repository to serve content.

<img src="/images/blog/github-pages.png" alt="" class="is-centered" style="margin-top: 20px; margin-bottom: 20px"

This means that I can simply re-generate the site after making changes and add it as an additional commit to my main branch with no need to switch branches or perform a merge.

To simplify this, Ive added a new publish.sh script into my repository to automate the sites. This is how it currently looks:

#!/usr/bin/env bash

SITE_ENV="prod"

# Remove the existing docs directory, build the site and create the new
# docs directory.
rm -rf ./docs
vendor/bin/sculpin generate --no-interaction --clean --env=${SITE_ENV}
touch output_${SITE_ENV}/.nojekyll
mv output_${SITE_ENV} docs

# Ensure the correct Git variables are used.
git config --local user.name 'Oliver Davies'
git config --local user.email oliver@oliverdavies.uk

# Add, commit and push the changes.
git add --all docs
git commit -m 'Build.'
git push origin HEAD

This begins by removing the deleting the existing docs directory and re-generating the site with the specified environment. Then I add a .nojekyll file and rename the output directory to replace docs.

Now the changes can be added, committed and pushed. Once pushed, the new code is automatically served by GitHub Pages.

HTTPS

GitHub Pages unfortunately does not support HTTPS for custom domains.

As the site was previously using HTTPS, I didnt want to have to go back to HTTP, break any incoming links and lose any potential traffic. To continue using HTTPS, I decided to use Cloudflare to serve the site via their CDN which does allow for HTTPS traffic.

Next Steps

  • Enable automatically running publish.sh when new changes are pushed to GitHub rather than running it manually. I was previously using Jenkins and Fabric for this, though Im also going to look into using Travis to accomplish this.
  • Add the pre-build steps such as running composer install and yarn to install dependencies, and gulp to create the front-end assets. This was previously done by Jenkins in my previous setup.

Resources