Daniel Doubrovkine bio photo

Daniel Doubrovkine

aka dB., @awscloud, former CTO @artsy, +@vestris, NYC

Email Twitter LinkedIn Github Strava
Creative Commons License

Github has been petitioned, begged and implored to enable SSL on custom domains running on Github pages. They finally delivered SSL support with LetsEncrypt.

This is what I had to do for my Github pages Jekyll site at https://www.dblock.org. You can see the changes in www.dblock.org@5f6f047d.

_config.yml

Change url in _config.yml to https://www.dblock.org to fix asset and other internal links.

I couldn’t figure out how to make those relative to either HTTP or HTTPs.

_includes/_enforce_ssl.html

Add a JavaScript redirect to _head.html from HTTP to HTTPs.

<script language="javascript">
  // Enforce SSL
  (function (root) {
    "use strict";
    var h = root ? root.location.hostname : "",
    p = root ? root.location.protocol : "";
    if ("http:" === p && !(/^(localhost|127.0.0.1)/).test(h)) {
      root.location.protocol = "https:";
    }
  }
  ("undefined" !== typeof window ? window : this));
</script>

I couldn’t find a plugin that could make a 301 redirect before page load, something that Google recommends.

_includes/_head.html

Include the JavaScript.

{% include _enforce_ssl.html %}