Jekyll Intermediate Workshop

Build and customize a website with Jekyll

Land Acknowledgement

UBC Vancouver is located on the traditional, ancestral, and unceded territory of the xʷməθkʷəy̓əm (Musqueam), səl̓ilwətaɁɬ təməxʷ (Tsleil-Waututh), Stz’uminus, S’ólh Téméxw (Stó:lō), Skwxwú7mesh-ulh Temíx̱w (Squamish), and Coast Salish peoples.

Please take a moment to explore native-land.ca so that you can visualize the indigenous territories, languages, and treaties in your area.

Outline



  • Introduction
  • Installation
  • Building a Website
  • Blogging
  • Site Structure
  • Jekyll Plugins
  • Serving

Why do you need a website?



Use the chat box and share your goals for attending this workshop.

Static website generator based on Ruby

Developed by Tom Preston-Werner

Fully integrated with GitHub

Static vs Dynamic

Image from How the Web Works on Youtube

Static vs Dynamic

Image from Medium @Prime Kreation

Jekyll Installation



If you have not installed it on your system, use the link below to install it later:

Installation

Installation

  • Ruby compiler
  • Rubygems


Verify the installation:


            $ jekyll -v
        

You can still learn about Jekyll structure and tools without a running version on your system.

Build

Jekyll Now is Jekyll's default theme.

Build a new website by typing these commands in the terminal:


            $ jekyll new [name of blog]
            $ jekyll serve
        

Open localhost: http://127.0.0.1:4000

If you do not have Jekyll installed: Download Jekyll Now

Download Jekyll Now

Jekyll Now!

Jekyll Now files

          

Jekyll Now with bundler

Other directories are kept as a gem in the Gemfile.

What is a Gemfile?

A Gemfile is used for describing gem dependencies for Ruby programs

Gems are used to distribute functionalities


If you have a Gemfile, you need to install bundler and ask bundler to serve Jekyll when you change the Gemfile


            $ gem install bundler
            $ bundle exec jekyll serve
        

If you want to stop serving your website locally, use Ctrl + C.

Themes

Activity 1

You can find Jekyll themes for various types of websites:

Choose a "good" theme for your website.

What makes a theme "good"?


Jekyll Now

Download Jekyll Now

Download it from: https://github.com/barryclark/jekyll-now

We will use this theme to learn about other features of Jekyll.

Basic features will work in any other theme.

Site Structure

Site Structure

        . 
        ├── _config.yml 
        ├── _data
        │   └── members.yml
        ├── _drafts
        │   ├── begin-with-the-crazy-ideas.md
        ├── _includes
        |   ├── footer.html
        |   └── header.html
        ├── _layouts
        |   ├── default.html
        |   └── post.html
        ├── _posts
        |   ├── 2021-05-23-why-I-chose-UBC.md
        |   ├── 2021-01-12-welcome-to-jekyll.md
        ├── _sass
        |   ├── _base.scss
        |   └── _layout.scss
        ├── _site
        ├── assets
        ├── 404.html
        ├── about.md
        ├── .jekyll-cache
        │   └── Jekyll
        │       └── Cache
        │           └── [...]
        ├── .jekyll-metadata
        ├── Gemfile
        ├── Gemfile.lock
        └── index.html
    

Activity 2

Put each description in the right basket

Access the sheet here: https://bit.ly/3s00YPA

You can edit this file or make a copy

Blogging

Jekyll has built-in features for blogging

Pages

Standalone content - have no dates

  • Landing page
  • About me
  • Resume

A sample.html file in the root directory is shown in {domain}/sample.html

You can also add Markdown files to build pages

Posts

  • Jekyll solution for blogging
  • The best practice is to use Markdown to write posts but you can also use HTML
  • Starts with Front matter
  • A valid post name must be in the format [year]-[month]-[day]-[post-name].md

Markdown

A markup language for creating formatted text using a plain-text editor

  • Headings:
    • # H1
    • ## H2
    • ### H3
  • Emphasis:
    • **bold**
    • *italic*
  • Links:
    • [I'm an inline-style link](https://www.google.com)
  • Images:
    • Inline-style: ![alt text](https://ubc-library-rc.github.io/intermediate-Jekyll/slides/figures/JekyllNow.png "Title Text")

Use Markdown-it for more

HTML & CSS

Two of the core technologies for building webpages

  • HTML describes the structure of a web page using elements, e.g.
  •  

    {{ page.title }}

  • CSS describes the presentation of web pages e.g.
  •  
                  h1 {
                    font-size: 36px;
                  }
                  

CSS files are commonly stored in _sass folder in Jekyll directory

Activity 3

Write one "Post" and change "About me" page

Try Markdown syntax

Serve them on your local machine

Are you looking for an example? Take a look at this file!

Liquid

Liquid is an open-source template language created by Shopify and written in Ruby.


  • Liquid Objects
  • Liquid Tags
  • Liquid Filters

Liquid Objects

Objects contain the content that Liquid displays on a page.

To output content into a page, two curly braces are used e.g.


{{ site.title }} 

Jekyll Workshop
        

Liquid Tags

Tags create programming logic and control flow for templates.

To perform logic statements or run a loop, curly braces are used with a percentage sign on each side e.g.


        {% if user %}
            Hello {{ user.name }}!
        {% endif %}
        

Hello Adam!
        

Liquid Filters

Filters change the output of a Liquid object or variable.

You can use filters to change strings or manipulate a list of items.


            {{ "How many characters are in this string?" | size }}
        

39
        

Front Matter

  • It guides Jekyll to parse your Markdown files and put content in the right place
  • Use YAML format wrapped between triple-dashed lines

Open any of the files in _posts directory:


            ---
            layout: post
            title: Blogging Like a Hacker
            ---
        

Now open page.html in the _layout directory:


            ---
            layout: default
            ---
            

{{ page.title }}

{{ content }}

Layouts

Jekyll later fills each section with the content of Markdown files, following the instructions of Front matter.

Layouts

Open default.html in _layouts directory:

                Layout example
            

Later, we will learn how to ask Jekyll to put Markdown content in this layout.

Includes

Reusable components - Snippets of code that we want to use over multiple pages, such as:

  • Google analytics tags
  • Headers and Footers
  • Media Frames
  • Sidebars
  • Comment systems

Includes

Let's look at the content of head.html in _includes:

                Include example
            

Includes

Includes can be used in other web pages via Liquid tags:


                {% include head.html %}
            

We can also pass parameters to include:



                {% include youtube.html youtube_id="xtMBD1P3tz0" %}
            

Variables

Jekyll creates variables and assigns values to them by looking at 3 locations:

  • _config.yml
  • files in _data directory
  • Front matter of Markdown files


_config.yml files in _posts directory
site.title, site.url page.title, page.date

The title in the file name will be stored in .title of site.posts object while the title in the Front matter of the post is stored in page.title.

_config.yml

A YAML file with data in the format of key:value

                config.yml
            

You can also create your own variables by defining them in the Front matter or _config.yml and later using them in Liquid tags.

Activity 4

If your group number if an odd number, solve Exercise 1

and if it is an even number, solve Exercise 2

Jekyll Plugins

Jekyll plugins extend the capabilities of Jekyll

  • Jekyll-scholar is for the academic blogger to format the bibliographies and reading lists for the web.
  • Jekyll Picture Tag automates the process of making your figures across all different browsers and devices.
  • Jekyll Feed plugin generates an RSS-like feer of your Jekyll posts.
  • Jekyll Sitemap Generator Plugin silently generates a sitemaps.org compliant sitemap for your Jekyll site.
  • Jekyll does not support commenting but you can use community platforms such as Disqus.

If you plan to serve your website on GitHub Pages, make sure that the plugins you are using are supported by GitHub Pages

Serve and Deployment

  • Domain
  • Host

GitHub Pages

Free host with a GitHub domain

Other options

Jekyll generates your static site to the _site directory by default. You can transfer the contents of this directory via FTP or any other file transfer method to almost any hosting provider.

Hyde and Troubleshooting

Download it from: https://github.com/poole/hyde

More from the Research Commons at (UBC-V)