_config.yml: pre-w19 format

For courses prior to w19

The most important part of configuring a Jekyll site is to get the _config.yml right.

This page goes over the _config.yml for one of our Github Pages course sites. We’ll start with the _config.yml for a site such as ucsb-cs16-f18-mirza.github.io, and then discuss the one for a site such as ucsb-cs16.github.io.

The first part

In the first part, we define these variables, which are then available through the syntax ,, etc. in any file on the site:

name: "CS16 Fall 2018, Mirza"
qtr: "F18"
github_url: https://github.com/ucsb-cs16-f18-mirza/ucsb-cs16-f18-mirza.github.io

The github_url is particularly important, since it is what makes the “Edit this Page On Github” link at the bottom of each page work properly.

Special Subdirectories

The software we are using, Jekyll, requires two special subdirectories:

For now, create these directories and put an empty file in them called keep. You can do this through the github web interface, or at command line with these commands:

mkdir _layouts
mkdir _includes
touch _layouts/keep
touch _includes/keep
git add _layouts _includes
git commit -m "add placeholders for _layouts and _includes"
git push origin master

The empty keep file is just a placeholder; git ignores empty directories, so if we want the directory to exist, it needs at least one file in it. Once we add some real content to either directory, the keep file may be deleted.

The collections

Except for the special directories called _layouts and _includes, all of the directories we created that start with underscore correspond to a collection. These include such directories as:

Collections:

Here is an example of the part of the _config.yml that specifies the _info and _hwk collections:

Here’s the explanation of each:

collections:
  hwk:
    output: true
    permalink: /hwk/:path/
    last_before: false
  lab:
    output: true
    permalink: /lab/:path/
    last_before: false
  exam:
    output: true
    permalink: /exam/:path/
  info:
    output: true
    permalink: /info/:path/
  lectures:
    output: true
    permalink: /lectures/:path/

The defaults section

In the defaults section, we specify the mapping between the path in our repo, the type of each collection, and what the default layout for that collection should be.

To be honest, the code below could probably be made much cleaner and more efficient with some refactoring. We went with simple examples, and some copying/pasting, and what you see below is the result.

 defaults:
  -
    scope:
      path: "" # an empty string here means all files in the project
    values:
      layout: default
  -
    scope:
      path: ""
      type: hwk
    values:
      layout: hwk
  -
    scope:
      path: ""
      type: lab
    values:
      layout: lab
  -
    scope:
      path: ""
      type: exam
    values:
      layout: exam_info
  -
    scope:
      path: ""
      type: info
    values:
      layout: info
  -
    scope:
      path: ""
      type: lectures
    values:
      layout: lecture
  -
    scope:
      path: "syllabus.md"
      type: info
    values:
      layout: handout

Related topics: