DEV Community

C. Plug
C. Plug

Posted on • Edited on • Originally published at clpsplug.com

4 4

Use "source" Jekyll configuration to avoid deployment mistake

By default, Jekyll includes into the website whatever exists at the project root minus some files and directories that has special meanings.

my_jekyll_site
|- GemFile  // safe by default
|- GemFile.lock  // safe by default
|- _config.yml  // safe by default
|- .gitignore  // safe by default
|- index.md  // included
|- _posts  // included (parsed and then included)
 |- ...
Enter fullscreen mode Exit fullscreen mode

There is one problem with this setup. If you add a script file here, you are going to expose that file!

my_jekyll_site
|- Gemfile
|- ...
|- script.sh  // uh oh, you're exposing this file!
Enter fullscreen mode Exit fullscreen mode

There can be multiple reasons for creating a non-Jekyll related scripts, examples being:

  • Automated build script for the server to publish your site
  • Yarn/Webpack config for your javascript needs

You could specify exclude key in your _config.yml, but this is merely a manual denylist - you may forget to add stuff until it is too late.

exclude: ["webpack.js"]
Enter fullscreen mode Exit fullscreen mode

There is even better way:

The source key

This tells Jekyll to stop looking at the project root for the content to build; instead, it will use the directory you have specified.

source: "_src"
Enter fullscreen mode Exit fullscreen mode

In this example, you put everything into _src directory and everything will work just as fine. No more need to update your exclude key!

One small notice is if you're generating stuff outside of Jekyll, e.g., transpiling your typescript, you need to point the input and output into the source directory.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more