<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>YuXuan Tay</title><link>https://yxtay.github.io/</link><description>Recent content on YuXuan Tay</description><image><title>YuXuan Tay</title><url>https://yxtay.github.io/avatar.jpg</url><link>https://yxtay.github.io/avatar.jpg</link></image><generator>Hugo</generator><language>en</language><copyright>YuXuan Tay</copyright><lastBuildDate>Tue, 30 Jun 2020 00:00:00 +0800</lastBuildDate><atom:link href="https://yxtay.github.io/index.xml" rel="self" type="application/rss+xml"/><item><title>Python Environment, Package and Dependency Management</title><link>https://yxtay.github.io/blog/2020-06-30-python-environment-package-dependency-management/</link><pubDate>Tue, 30 Jun 2020 00:00:00 +0800</pubDate><guid>https://yxtay.github.io/blog/2020-06-30-python-environment-package-dependency-management/</guid><description>My python project setup for environment management in 2020 after considering many options.</description><content:encoded><![CDATA[<p>In my experience of developing python applications for production
deployment with docker, I often find myself setting up many components
and configurations which may be repetitive and reusable. Along the way,
I have also done a lot of research on the python developer tools
available and best practices in setting them up.
In the next series of posts, I will be distilling my findings
and sharing what I think makes sense for me.
In this post, I will cover environment, package and dependency management.</p>
<p>Information discussed here are set up in the following repository.
Please star the repo if you find it useful.</p>
<ul>
<li><a href="https://github.com/yxtay/python-project-template">https://github.com/yxtay/python-project-template</a></li>
</ul>
<p>The repository has been configured as a <a href="https://help.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template">project template</a>
which you may use to generate new python project repositories.</p>
<p><img alt="Use this tempalte" loading="lazy" src="/static/images/use-this-template.png"></p>
<h2 id="motivation">Motivation</h2>
<p>Environment, package and dependency management is important if you have
to handle multiple python projects are different stages of development.
Environment management is required to prevent dependency conflict between
different projects. Package and dependency management is necessary to
create reproducible environments for development and production.</p>
<p>Unfortunately, even in 2020, this is still a bit of a mess as
it is not well handled by the standard libraries.
The ecosystem has developed a few options and there isn&rsquo;t yet a clear winner.</p>
<p>My use cases are generally private applications such as
machine learninig web API for a particular business use case.
It does not cover developing python packages meant to be published
and distributed to a wider general audience.</p>
<h2 id="pip">pip</h2>
<ul>
<li>standard package installer</li>
<li>unable to uninstall packages cleanly</li>
<li>used for production in docker image</li>
</ul>
<p>pip is the standard package installer.
With pip, dependencies are specified in <code>requirements.txt</code> file.
At the minimum, the top level project required packages should be specified,
with versions appropriately pinned. For reproducible builds,
it is recommended to include all dependencies in <code>requirements.txt</code>.
This will be rather tedious to do manually. As <code>requirements.txt</code>
is a standard package specification format, other tools can be used
to generate the complete project dependencies, as I will cover later.</p>
<p>pip is able to resolve the dependency graph on installation.
However, as dependencies are not tracked by pip,
packages are not uninstalled cleanly. This results in an environment
which can potentially be polluted by previously installed dependencies
that are no longer being required. This is also the reason why using
<code>pip freeze &gt; requirements.txt</code> for dependency management is a bad idea.</p>
<p>I use pip for production package management in docker,
as it is a standard library without additional dependency.
Since dependency management should be properly done in the development
environment, only package installation is required in preparing
the prooduction environment, which pip performs without issue.</p>
<h2 id="venv">venv</h2>
<ul>
<li>standard virtual environment manager</li>
<li>unable to create environments with different python versions</li>
<li>used for production in docker image</li>
</ul>
<p>venv is the standard virtual environment manager.
venv creates lightweight environments with the python version
matching the python version used to create the environment.
It is unable to create environments with different python versions.</p>
<p>I use venv for production environment management in docker.
Since the python version is specified in the docker base image,
I do not need to manage python versions with venv.
While it may be argued that virtual environment is not necessary
in docker images, they are still useful,
especially for using multi-stage builds to reduce docker image sizes.
I will cover this topic in another post.</p>
<h2 id="conda">Conda</h2>
<ul>
<li>easy to install contained python environment in Windows, Mac and Linux</li>
<li>able to install different python versions and non-python dependencies</li>
<li>extensive Anaconda distribution useful for data scientists</li>
<li>package repository is not as complete as PyPI, hence using pip is often required</li>
<li>use for development environment management</li>
</ul>
<p>Conda is the full featured package, dependency and environment management
tool. It simplifies python installation in Windows, Mac and Linux.
The installed python environment is contained in a single directory and
isolated from the one in the operating system. This prevents me from
accidentally installing libraries into the python operating system
environment and messing it up.</p>
<p>I use Conda to manage my development environments.
It is able to create environments with different python version.
To reduce footprint, I use the <a href="https://docs.conda.io/en/latest/miniconda.html">Miniconda distribution</a>.
I usually use the base Conda environment to manage environments only and avoid
installing packages there directly. However, in the event that I make a mistake,
it is easy to delete the whole Conda directory and reinstall.</p>
<p>Conda contains a package installer that is able install non-python dependencies.
For example, it is able to install TensorFlow with CUDA drivers.
This makes it fuss free if I am only developing and using my project locally.
The <a href="https://docs.anaconda.com/anaconda">Anaconda package</a> includes a bunch of python data science
libraries that are useful for general data science projects.
However, for projects with production requirements, I will eventually have to
figure out the installation of the non-python dependencies without Conda.</p>
<p>With Conda, dependencies are specified in a <code>environment.yml</code> file
that has its own package specification format and
is thus not compatible with other tools in the python ecosystem.
Moreover, the Conda package repository is not as complete as PyPI.
This means I often have to fallback to using pip.
The packages installed with pip can also be specified
in a section in <code>environment.yml</code>.</p>
<p>In the past, I have attempted to create docker images for production
with Conda as the package installer. However,
I realised that this created docker images that quickly blew up in size.
It is not uncommon to see images in excess of 2GB.
I have since avoided using Conda in docker images and
stick to using pip with python base images instead.</p>
<h2 id="poetry">Poetry</h2>
<ul>
<li>tool for dependency management and packaging in Python</li>
<li>packages can be uninstalled cleanly as dependencies are tracked</li>
<li>able to generate <code>requirements.txt</code> that is compatible with pip</li>
<li>use for development package and dependency management in development</li>
</ul>
<p>Poetry is a relatively new tool for dependency management and packaging.
It has recently (Dec 2019) reached version 1.0.
Poetry tracks the complete dependency graph and, hence, is able to
install and uninstall packages cleanly. Both project and development
dependencies are specified in <code>pyproject.toml</code>. When packages are
installed with Poetry, they are automatically added to <code>pyproject.toml</code>
with dependencies and versions pinned in <code>poetry.lock</code>.
It is able to generate <code>requirements.txt</code> that is compatible with pip.
I have recently adopted Poetry for package and dependecy management
in my development environment.</p>
<p>Poetry is also able to create and activate environments automatically.
With Poetry, I am able to run commands in the right environment
without having to manually activate it. However, as I use Conda
to manage my environments, I need to modify my usage for them
to work well together. I will cover how I do this in another post.</p>
<p>Poetry also includes features for build and publishing packages.</p>
<h2 id="other-notable-tools">Other notable tools</h2>
<h3 id="pip-tools">pip-tools</h3>
<ul>
<li>generates <code>requirements.txt</code> that is compatible with pip</li>
<li>multiple requirement files to handle</li>
</ul>
<p>pip-tools is a package and dependency management tool.
Before I adopted Poetry, I used pip-tools, mainly with influence
from the article by <a href="https://hynek.me/articles/python-app-deps-2018">Schlawack</a>.
pip-tools generates requirement files with pinned dependency versions
and matches the virtual environment installations to those versions.
The generated requirement files are compatible with pip.
pip-tools works well with environments created by another tool.</p>
<p>However, to use pip-tools, I need to manually add packages to the
source requirement files based on which pip-tools generates.
This is not a major problem as I am used to doing that.
Using pip-tools also results in 2 requirements files for every set
of dependencies: source and generated. With project and development
dependencies, this results in 4 requirement files.
I had to create a requirements directory so that my project root is
not cluttered.</p>
<h3 id="pipenv">Pipenv</h3>
<ul>
<li>environment and dependency management tool hosted by PyPA</li>
<li>development was dead in 2019, but seems to be ressurected in 2020</li>
</ul>
<p>Pipenv is an environment and dependency management tool hosted by PyPA.
Conceptually, it is very similar to Poetry and has similar features,
including package building and publishing.</p>
<p>However, Pipenv has received quite a bit of bad reputation
until recently. The tool was slow and buggy and
there has been breaking changes between releases.
Development was almost dead in 2019, with no releases that year.
Things has since improved with a few releases since May 2020.</p>
<h3 id="pyenv">pyenv</h3>
<ul>
<li>python version management</li>
</ul>
<p>pyenv is a tool for python version management.
It is able to install and manage multiple versions of Python.
If I am not using Conda, pyenv will be the tool I use to
manage python versions.</p>
<h2 id="conclusion">Conclusion</h2>
<ul>
<li>Production
<ul>
<li>environment management: venv</li>
<li>package installer: pip</li>
<li>dependency management: NA</li>
</ul>
</li>
<li>Development
<ul>
<li>environment management: Conda</li>
<li>package installer: Poetry, Conda</li>
<li>dependency management: Poetry</li>
</ul>
</li>
</ul>
<p>I use different tools for production and development environments.
With production, I mainly use standard libraries as they do not
have additional dependencies and are available in the python base images.
With that, the tools I use for development need to be compatible with
those I use for production. As long as I do proper dependency management
in development, I will be able to create reproducible environments
for production.</p>
<p>There are still multiple contenders within the python ecosystem on this
issue with consistent development. I expect the situation for
managing python environments and dependencies to improve going forward.</p>
<p>In my next few articles, I will cover other aspects of my project
template, such as application tools, development tools and docker deployment.</p>
<p>Hope you have found it useful! Please let me know what you think in the comments.</p>
<h2 id="references">References</h2>
<ul>
<li>Tools
<ul>
<li><a href="https://pip.pypa.io/en/stable">pip</a></li>
<li><a href="https://docs.python.org/3/library/venv.html">venv</a></li>
<li><a href="https://docs.conda.io/en/latest">Conda</a></li>
<li><a href="https://python-poetry.org">Poetry</a></li>
<li><a href="https://github.com/jazzband/pip-tools">pip-tools</a></li>
<li><a href="https://github.com/pyenv/pyenv">pyenv</a></li>
<li><a href="https://github.com/pypa/pipenv">Pipenv</a></li>
</ul>
</li>
<li>Conda
<ul>
<li><a href="https://jakevdp.github.io/blog/2016/08/25/conda-myths-and-misconceptions">Conda: Myths and Misconceptions</a> by Jake VanderPlas</li>
<li><a href="https://www.anaconda.com/blog/tensorflow-in-anaconda">TensorFlow in Anaconda</a> on Anaconda: benefits of using Conda to install packages with non-python dependencies</li>
</ul>
</li>
<li>Tools comparison
<ul>
<li><a href="https://hynek.me/articles/python-app-deps-2018">Python Application Dependency Management in 2018</a> by Hynek Schlawack: comparing Pipenv, Poetry and pip-tools</li>
<li><a href="https://jacobian.org/2019/nov/11/python-environment-2020">My Python Development Environment, 2020 Edition</a> by Jacob Kaplan-Moss: using pyenv, pipx and Poetry</li>
<li><a href="https://www.pluralsight.com/tech-blog/managing-python-environments">Managing Python Environments</a> by John Walk: comparing venv, virtualenv, pyenv, Pipenv, Conda and docker</li>
</ul>
</li>
<li>Python project structure
<ul>
<li><a href="https://docs.python-guide.org/writing/structure">Structuring Your Project</a> on The Hitchhiker&rsquo;s Guide to Python</li>
<li><a href="https://realpython.com/python-application-layouts">Python Application Layouts: A Reference</a> on Real Python</li>
<li><a href="https://github.com/jacebrowning/template-python">Jace&rsquo;s Python Template</a></li>
</ul>
</li>
</ul>
]]></content:encoded></item><item><title>Setting Jekyll Themes on GitHub Pages</title><link>https://yxtay.github.io/blog/2020-06-09-setting-jekyll-themes-on-github-pages/</link><pubDate>Tue, 09 Jun 2020 00:00:00 +0800</pubDate><guid>https://yxtay.github.io/blog/2020-06-09-setting-jekyll-themes-on-github-pages/</guid><description>Understanding how to set up Jekyll Themes on GitHub Pages</description><content:encoded><![CDATA[<p>Another confusion I faced while setting up this blog
is regarding setting Jekyll themes for GitHub Pages.
If you are setting up a blog with Jekyll, it is likely
that you will want to set a theme to customise the
look and feel, and also to use features implemented
by authors of Jekyll themes.</p>
<p>There are 3 main methods for setting Jekyll themes on GitHub Pages.</p>
<ul>
<li>Gem-based themes</li>
<li>Remote themes</li>
<li>Regular themes</li>
</ul>
<p>I will go through each of the 3 methods, how to set them up,
and what the pros and cons are of each method.
For GitHub Pages, the <a href="https://help.github.com/en/github/working-with-github-pages/adding-a-theme-to-your-github-pages-site-using-jekyll">documentation</a>
will be the relevant reference for this topic.</p>
<h2 id="gem-based-themes">Gem-based Themes</h2>
<p>This is the default method used for new Jekyll projects.
When you initialise a new Jekyll project with <code>jekyll new</code>,
you will notice that the <code>_config.yml</code> is set up with <code>theme: minima</code>.
<a href="https://github.com/jekyll/minima">Minima</a> is a minimalistic Jekyll theme
that is installed together with Jekyll.</p>
<p>This method requires that you make configuration changes at 2 locations:
<code>Gemfile</code> and <code>_config.yml</code>.</p>
<p>The following specifies and installs the gem for the theme.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ruby" data-lang="ruby"><span class="line"><span class="cl"><span class="c1"># Gemfile</span>
</span></span><span class="line"><span class="cl"><span class="n">gem</span> <span class="s2">&#34;minimal-mistakes-jekyll&#34;</span>
</span></span></code></pre></div><p>This activates the theme in Jekyll.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="c"># _config.yml</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">theme</span><span class="p">:</span><span class="w"> </span><span class="l">minimal-mistakes-jekyll</span><span class="w">
</span></span></span></code></pre></div><p>Pros</p>
<ul>
<li>Simple to set up</li>
<li>Sufficient for simple needs, such as project documentation</li>
<li>Theme development and maintenance managed by theme author</li>
</ul>
<p>Cons</p>
<ul>
<li>Only themes with published gems can be configured with this method</li>
<li>Limited theme customisation</li>
<li>For GitHub Pages, only limited themes are available with this method</li>
</ul>
<p>The final point is the severe limitation of using gem-based theme configuration.
According to the <a href="https://pages.github.com/themes">documentation</a>,
there are only 15 themes available for GitHub Pages.
If you are using GitHub Pages, you will not be able to use any other
gem-based theme by adding it into the <code>Gemfile</code>.
The included themes are as follows.</p>
<ul>
<li>minima</li>
<li>jekyll-swiss</li>
<li>jekyll-theme-primer</li>
<li>jekyll-theme-architect</li>
<li>jekyll-theme-cayman</li>
<li>jekyll-theme-dinky</li>
<li>jekyll-theme-hacker</li>
<li>jekyll-theme-leap-day</li>
<li>jekyll-theme-merlot</li>
<li>jekyll-theme-midnight</li>
<li>jekyll-theme-minimal</li>
<li>jekyll-theme-modernist</li>
<li>jekyll-theme-slate</li>
<li>jekyll-theme-tactile</li>
<li>jekyll-theme-time-machine</li>
</ul>
<p>These themes are available in the &ldquo;Theme Chooser&rdquo; under
&ldquo;GitHub Pages&rdquo; in the repo settings. When you select a theme
using this method, GitHub automatically creates a <code>_config.yml</code> file
and set the <code>theme</code> field.</p>
<p>Most of these themes are not developed to be used for blogging purposes.
They lack functionality to generate posts and handle posts pagination.
Out of the themes in this list, Minima is probably the most feature complete
as it is the default theme, with development supported by Jekyll directly.
However, your GitHub Pages website will look like many out there.</p>
<h2 id="remote-themes">Remote Themes</h2>
<p>This method requires the <a href="https://github.com/benbalter/jekyll-remote-theme">Jekyll remote theme plugin</a>.
This plugin is included with GitHub Pages and installed together
with <code>github-pages</code> <a href="https://github.com/github/pages-gem">gem</a>.
(Please read my <a href="/blog/understanding-jekyll-and-github-pages">previous post</a>
to understand how this gem works.)</p>
<p>With the Jekyll remote theme plugin installed
(either individually or with <code>github-pages</code> gem),
set up the remote theme configuration in the <code>_config.yml</code> file.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="c"># _config.yml</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">remote_theme</span><span class="p">:</span><span class="w"> </span><span class="l">minimal-mistakes</span><span class="w">
</span></span></span></code></pre></div><p>Pros</p>
<ul>
<li>Simple to set up</li>
<li>Many themes are available on GitHub</li>
<li>Theme development and maintenance managed by theme author</li>
</ul>
<p>Cons</p>
<ul>
<li>Long build time due to downloading of theme files on build</li>
<li>Customisability depends on theme</li>
<li>Only work for themes published on GitHub</li>
</ul>
<p>In my opinion, the remote theme method offers the best balance
of selection, customisability and complexity.
I am using this method to use the <a href="https://mmistakes.github.io/minimal-mistakes">Minimal Mistakes theme</a>.
The remote theme method is applicable to any theme
that is hosted on GitHub, this means a large number of themes are available,
even it is not a gem. However, do take note that pay attention to
whether themes are still being maintained or meant to be used this way.</p>
<h2 id="regular-themes">Regular Themes</h2>
<p>The regular theme method is the most raw and complex method.
When you fork the repo of a Jekyll theme to start your GitHub Pages,
you are inadvertently using this method.</p>
<p>To better understand how this method works, it is a good idea to
go through the <a href="https://jekyllrb.com/docs/themes">Jekyll documentation</a>.
In essence, you are required to set up the following
4 folders and their associated content.
These set the theme page layouts, appearance and functionality.</p>
<ul>
<li><code>/_includes</code>: HTML components used in page layouts</li>
<li><code>/_layouts</code>: HTML page layouts</li>
<li><code>/_sass</code>: SASS files for page styling with CSS</li>
<li><code>/assets</code>: other static assets for the theme</li>
</ul>
<p>Pros</p>
<ul>
<li>Allows for any customisation you want</li>
<li>Can be easily started by cloing a GitHub repo of a Jekyll theme</li>
<li>No external dependency</li>
</ul>
<p>Cons</p>
<ul>
<li>Requires understanding of theme authoring</li>
<li>Customisation requires knowledge of static website development
with HTML, CSS, JS, Liquid and Jekyll</li>
</ul>
<p>I do not recommend using the regular theme method to set up
theme for your Jekyll website, unless you know what you are doing.
Unfortunately, many theme authors lazily suggest to start using the theme
by cloning the GitHub repo.
The primary problem with this method is that any updates to the theme
need to be merged into the user repo manually by the user.
This gets complicated really quickly,
especially if you have made customisation to the theme files.
Another issue is that the user Jekyll project may be polluted by
many theme files that is not required and clean up is needed.
However, this can only be done only when
the user is somewhat familiar with Jekyll theme authoring.</p>
<p>While exploring theme configuration, I was initially attracted to
author my own theme to get my unique look and feel.
However, as I went deeper into the rabbit hole, I discovered
that it gets very complicated really quickly.
Hence, this is really not a good idea unless you are a proficient
website developer familiar with HTML, CSS and JS.</p>
<h2 id="conclusion">Conclusion</h2>
<p>There are 3 methods to set up Jekyll themes.</p>
<ul>
<li>Gem-based theme
<ul>
<li>Sufficient for simple needs such as project documentation</li>
</ul>
</li>
<li>Remote theme
<ul>
<li>Recommended for blogging with Jekyll</li>
<li>Best balance between selection, customisation and complexity</li>
</ul>
</li>
<li>Regular theme
<ul>
<li>Not recommended, unless familiar with Jekyll site development</li>
</ul>
</li>
</ul>
<p>I hope I have helped the reader better understand the underlying
workings of setting up Jekyll themes.
This shall conclude the sharing of my journey into setting up
my blog with Jekyll on GitHub Pages.</p>
<p>Thank you for reading!</p>
<p>My other post on Jekyll and GitHub Pages.</p>
<ul>
<li><a href="/blog/understanding-jekyll-and-github-pages">Understanding Jekyll and GitHub Pages</a></li>
</ul>
<h2 id="references">References</h2>
<ul>
<li><a href="https://help.github.com/en/github/working-with-github-pages/adding-a-theme-to-your-github-pages-site-using-jekyll">https://help.github.com/en/github/working-with-github-pages/adding-a-theme-to-your-github-pages-site-using-jekyll</a></li>
<li><a href="https://pages.github.com/themes">https://pages.github.com/themes/</a></li>
<li><a href="https://jekyllrb.com/docs/themes">https://jekyllrb.com/docs/themes/</a></li>
</ul>
]]></content:encoded></item><item><title>Understanding Jekyll and GitHub Pages</title><link>https://yxtay.github.io/blog/2020-06-03-understanding-jekyll-and-github-pages/</link><pubDate>Wed, 03 Jun 2020 00:00:00 +0800</pubDate><guid>https://yxtay.github.io/blog/2020-06-03-understanding-jekyll-and-github-pages/</guid><description>Understanding how Jekyll and GitHub Pages work</description><content:encoded><![CDATA[<p>In the midst of setting up this blog, I had spent some effort
going through the documentation of Jekyll and GitHub Pages
to understand how GitHub Pages worked together with Jekyll.
I thought it would be a good idea to share my understanding
so that someone may find it useful later.</p>
<p>Below are a few references that I found useful.</p>
<ul>
<li><a href="https://jekyllrb.com">Jekyll documentation</a></li>
<li><a href="https://help.github.com/en/github/working-with-github-pages">GitHub Pages help</a></li>
<li><a href="https://www.smashingmagazine.com/2014/08/build-blog-jekyll-github-pages">Build A Blog With Jekyll And GitHub Pages on Smashing Magazine</a></li>
</ul>
<p>I assume that the reader is familiar with Git, GitHub
and will not be covering instructions to add, commit and push
code onto GitHub.</p>
<h2 id="jekyll-the-static-site-generator">Jekyll, the static site generator</h2>
<p>Jekyll is a static site generator implemented in Ruby.
A static site refers to a website which consists of
complete HTML files that are served directly on request.
This means the contents on the website are completely
contained in the HTML files. This is as opposed to
a dynamic site where website contents are generated by a
web application server on request.</p>
<p>Jekyll pre-builds HTML files with content from Markdown files.
To do so, Jekyll has features such as HTML components,
HTML layouts, CSS preprocessing, etc.
The generated static site is completely contained in the
<code>_site</code> folder in the Jekyll project and served from there.</p>
<h2 id="github-pages-the-static-site-hosting-service">GitHub Pages, the static site hosting service</h2>
<p>GitHub Pages is the static site hosting service offered by GitHub.
It serves any static page as long as the file is contained in the
source directory. This directory can be the root directory
in the <code>master</code> or <code>gh-page</code> branch or the <code>docs</code> directory
in the <code>master</code> branch, depending on your configuration.
You can specify this in the repository settings.
The static pages do not necessary have to be generated by Jekyll.</p>
<p>GitHub Pages is also able to use Jekyll to generate static site
from the source directory as long as
it is properly configured as a Jekyll project and
serve the generated static pages in the <code>_site</code> folder.</p>
<p>This is a source of confusion for me
as it did not seem to make sense that the same directory
used to serve static pages directly can also be
used to generate static pages with Jekyll.
It turns out, this is a feature of Jekyll.
Any static file in the source directory is copied
into the <code>_site</code> folder mentioned earlier without any processing
and can be served directly from there.
This also has the effect of preserving any relative links
between static pages in the source directory,
allowing linking between pages without modification.</p>
<p>From my understanding, when GitHub Pages is activated,
a continuous deployment pipeline is set up in the source directory.
This runs the <code>jekyll build</code> command to generate the static pages.
The contents in the <code>_site</code> folder are then served on GitHub Pages.
This pipeline is run on every push to the branch.</p>
<p>To serve up static files in the source directory directly without
any processing by <code>jekyll build</code>,
you may include an empty <code>.nojekyll</code> file.</p>
<h2 id="setting-up-jekyll">Setting up Jekyll</h2>
<p>There are <a href="https://jekyllrb.com/docs/installation">instructions</a> for installing Jekyll
on the official documentation, hence I will not repeat them here.
The components for setting up a Jekyll project is also
succintly explained in the <a href="https://jekyllrb.com/docs/ruby-101">documentation</a>.
I will cover them briefly.</p>
<ul>
<li>Ruby
<ul>
<li>Jekyll is implemented in Ruby programming language.</li>
</ul>
</li>
<li>Gem
<ul>
<li>Ruby libraries are called gems and distributed on <a href="https://rubygems.org">RubyGems</a>.
Gem is used to download and install these libraries.
Jekyll is itself a gem. This is analagous to <code>pip</code> in Python.</li>
</ul>
</li>
<li>Gemfile
<ul>
<li>This file contains the list of gems required for a Ruby project.
For Jekyll, it is also used to manage Jekyll plugins.
This is analagous to the <code>requirements.txt</code> file in Python.</li>
</ul>
</li>
<li>Bundle
<ul>
<li>I understand this as the environment manager for Ruby,
to ensure the right versions of gems are used.
This is analagous to virtual environment in Python.</li>
</ul>
</li>
</ul>
<h2 id="setting-up-jekyll-for-github-pages">Setting up Jekyll for GitHub Pages</h2>
<p>This is where information can get confusing.
Jekyll is used to generate static site in general,
not specifically for GitHub Pages.
GitHub Pages uses a specific version of Jekyll
and has limited whitelisted plugins.</p>
<p>You may see suggestions to fill up the Gemfile as follows.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ruby" data-lang="ruby"><span class="line"><span class="cl"><span class="c1"># Gemfile</span>
</span></span><span class="line"><span class="cl"><span class="n">source</span> <span class="s2">&#34;https://rubygems.org&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">gem</span> <span class="s2">&#34;jekyll&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">group</span> <span class="ss">:jekyll_plugins</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="n">gem</span> <span class="s2">&#34;jekyll-feed&#34;</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span></code></pre></div><p>This allows specifying arbitrary versions of Jekyll
and Jekyll plugins, which may not work with GitHub Pages.
To ensure that your local environment works with GitHub Pages,
you will have to install Jekyll with the <code>github-page</code> gem.
The gem specifies the correct version of Jekyll and also
includes a list of plugins installed in the GitHub Pages environment.</p>
<p>Please specify the Gemfile as follows.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ruby" data-lang="ruby"><span class="line"><span class="cl"><span class="c1"># Gemfile</span>
</span></span><span class="line"><span class="cl"><span class="n">source</span> <span class="s2">&#34;https://rubygems.org&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">gem</span> <span class="s2">&#34;github-pages&#34;</span><span class="p">,</span> <span class="ss">group</span><span class="p">:</span> <span class="ss">:jekyll_plugins</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">group</span> <span class="ss">:jekyll_plugins</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span></code></pre></div><p>You may then run <code>bundle update</code> and <code>bundle install</code>
to set up your environment.
Run <code>bundle exec jekyll new . --force</code> to initialise
the Jekyll project.
You will have to modify the Gemfile again to revert it.
Run <code>bundle exec jekyll serve</code> to build and serve the
website locally for a preview. It should look similar to
the <a href="https://jekyll.github.io/minima">Jekyll Minima theme website</a>.</p>
<p>You may start working on your website from here.</p>
<h2 id="github-pages-plugins">GitHub Pages plugins</h2>
<p>The <code>github-pages</code> gem specifies
a list of <a href="https://pages.github.com/versions">plugins and their versions</a>.
Do take note that, according to the <a href="https://help.github.com/en/github/working-with-github-pages/about-github-pages-and-jekyll">documentation</a>
and the <a href="https://github.com/github/pages-gem">source code</a> of the gem, there are selected
Jekyll plugins that are enabled, installed and whitelisted.
Any plugins not included cannot be used for Jekyll on GitHub Pages,
even if they work in your local environment,
unless you set up your own continuous deployment process.</p>
<p>At the time of this writing, they are listed as follows.</p>
<ul>
<li>Enabled by GitHub Pages and cannot be disabled
<ul>
<li><code>jekyll-coffeescript</code></li>
<li><code>jekyll-commonmark-ghpages</code></li>
<li><code>jekyll-default-layout</code></li>
<li><code>jekyll-gist</code></li>
<li><code>jekyll-github-metadata</code></li>
<li><code>jekyll-optional-front-matter</code></li>
<li><code>jekyll-paginate</code></li>
<li><code>jekyll-readme-index</code></li>
<li><code>jekyll-relative-links</code></li>
<li><code>jekyll-titles-from-headings</code></li>
</ul>
</li>
<li>Installed by <code>github-pages</code> gem
<ul>
<li><code>jekyll-avatar</code></li>
<li><code>jekyll-feed</code></li>
<li><code>jekyll-mentions</code></li>
<li><code>jekyll-redirect-from</code></li>
<li><code>jekyll-remote-theme</code></li>
<li><code>jekyll-seo-tag</code></li>
<li><code>jekyll-sitemap</code></li>
<li><code>jemoji</code></li>
</ul>
</li>
<li>Whitelisted in the source code of <code>github-pages</code> gem
<ul>
<li><code>jekyll-include-cache</code></li>
<li><code>jekyll-octicons</code></li>
</ul>
</li>
</ul>
<p>To ensure all whitelisted plugins are available for use in your
Jekyll project, you may want to specify the Gemfile as follows.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ruby" data-lang="ruby"><span class="line"><span class="cl"><span class="c1"># Gemfile</span>
</span></span><span class="line"><span class="cl"><span class="n">source</span> <span class="s2">&#34;https://rubygems.org&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">gem</span> <span class="s2">&#34;github-pages&#34;</span><span class="p">,</span> <span class="ss">group</span><span class="p">:</span> <span class="ss">:jekyll_plugins</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">group</span> <span class="ss">:jekyll_plugins</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">  <span class="n">gem</span> <span class="s2">&#34;jekyll-include-cache&#34;</span>
</span></span><span class="line"><span class="cl">  <span class="n">gem</span> <span class="s2">&#34;jekyll-octicons&#34;</span>
</span></span><span class="line"><span class="cl"><span class="k">end</span>
</span></span></code></pre></div><h2 id="conclusion">Conclusion</h2>
<p>I have covered my understanding of Jekyll,
how Jekyll works on GitHub Pages and
how to setup the Gemfile to facilitate local development
and site preview. With this knowledge,
I find that it will be easier for me to set up
GitHub Pages for project documentation in the future.</p>
<p>Hope this benefits you too!</p>
<p>Update: below is my other post on Jekyll and GitHub Pages.</p>
<ul>
<li><a href="/blog/setting-jekyll-themes-on-github-pages/">Setting Jekyll Themes on GitHub Pages</a></li>
</ul>
<h2 id="references">References</h2>
<ul>
<li><a href="https://jekyllrb.com">https://jekyllrb.com</a></li>
<li><a href="https://help.github.com/en/github/working-with-github-pages">https://help.github.com/en/github/working-with-github-pages</a></li>
<li><a href="https://www.smashingmagazine.com/2014/08/build-blog-jekyll-github-pages">https://www.smashingmagazine.com/2014/08/build-blog-jekyll-github-pages</a></li>
<li><a href="https://pages.github.com/versions">https://pages.github.com/versions</a></li>
<li><a href="https://github.com/github/pages-gem">https://github.com/github/pages-gem</a></li>
</ul>
]]></content:encoded></item><item><title>Blogging with Jekyll on GitHub Pages</title><link>https://yxtay.github.io/blog/2020-05-31-blogging-with-jekyll-on-github-pages/</link><pubDate>Sun, 31 May 2020 00:00:00 +0800</pubDate><guid>https://yxtay.github.io/blog/2020-05-31-blogging-with-jekyll-on-github-pages/</guid><description>What I did to create a static blog with Jekyll on GitHub Pages.</description><content:encoded><![CDATA[<p>Finally, managed to create a blog with <a href="https://jekyllrb.com">Jekyll</a> on <a href="https://pages.github.com">Github pages</a>.
Have been thinking of writing a blog for a while,
but had put it off as I imagined the effort required
to create and maintain it will be beyond me.
However, this circuit breaker has given me some time and opportunity
to finally figure this out and get to work.</p>
<h2 id="about-me"><a href="/about/">About me</a></h2>
<p>My name is YuXuan Tay, I am a data scientist from Singapore.
The primary purpose of this blog will be as an outlet for me
to share my technical learnings and thoughts.
Given my background, the content will likely to be on
data science applications with Python.</p>
<h2 id="what-it-took">What it took</h2>
<p>Part of the reason it had taken me so long to set up this blog
was due to setting up and understanding <a href="https://jekyllrb.com">Jekyll</a> on <a href="https://pages.github.com">Github pages</a>.
Jekyll is written in Ruby which was intimidating
as I imagined I would have to familiarise myself with another
programming language and its ecosystem.
Turned out, it did take a bit of effort, but was not as scary as I imagined.</p>
<p>Other reasons were that I have a few specific feature requirements
on setting up a blog as follows.</p>
<ul>
<li><strong>Free</strong>: free forever, assuming manageable viewership</li>
<li><strong>Little fuss</strong>: as few components as required for blog preview, deployment and hosting</li>
<li><strong>Ownership</strong>: content wholly owned and controlled by myself</li>
<li><strong>Search</strong>: article search feature</li>
<li><strong>Comments</strong>: readers are able to leave comments on articles</li>
<li><strong>Analytics</strong>: Google Analytics for tracking</li>
</ul>
<p>The first 3 points are clearly fulfilled by <a href="https://pages.github.com">Github pages</a>.
They are part of the reasons why I did not consider using <a href="https://medium.com">Medium</a> or <a href="https://wordpress.org">Wordpress</a>.
However, <a href="https://jekyllrb.com">Jekyll</a> can get a bit complicated if I want to make specific customisations.
Fortunately, there are many <a href="https://jekyllthemes.io">Jekyll themes</a> available
with good layout and features,
hence I do not really have to get my hands dirty with HTML, CSS and JavaScript,
as long as my needs are common.</p>
<p>The last 3 points are fulfilled by the Jekyll theme I am using:
<a href="https://mmistakes.github.io/minimal-mistakes">Minimal Mistakes</a> by <a href="https://mademistakes.com">Michael Rose</a>.
It is quite a rich theme including features such as responsive layout, feed and sitemap.
A few additional features that I really liked are search engine optimisation
and social sharing.</p>
<p>Other than configuring those features, I have also taken the effort to create
proper <a href="/about/">about me</a> and <a href="/404.html">404</a> pages.
Please take a look!</p>
<h2 id="what-is-next">What is next</h2>
<p>Given the amount of effort I have spent figuring out Jekyll on GitHub Pages,
I thought it will be a good idea to share my understanding over a couple of posts.
Rather ironic given my original purpose of sharing on data science applications.
However, I am not going to let those content go to waste.</p>
<p>Thank you for reading!</p>
<p>Update: below are my completed posts on Jekyll and GitHub Pages.</p>
<ul>
<li><a href="/blog/understanding-jekyll-and-github-pages/">Understanding Jekyll and GitHub Pages</a></li>
<li><a href="/blog/setting-jekyll-themes-on-github-pages/">Setting Jekyll Themes on GitHub Pages</a></li>
</ul>
]]></content:encoded></item><item><title>About</title><link>https://yxtay.github.io/about/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://yxtay.github.io/about/</guid><description>about</description><content:encoded><![CDATA[<p>My name is YuXuan Tay, I am a data scientist from Singapore. The primary
purpose of this blog is an outlet for me to share my technical learnings and
thoughts. Given my background, the content leans towards data science
applications with Python.</p>
<ul>
<li>GitHub: <a href="https://github.com/yxtay">yxtay</a></li>
<li>X: <a href="https://twitter.com/yxtay">@yxtay</a></li>
<li>LinkedIn: <a href="https://www.linkedin.com/in/yxtay/">in/yxtay</a></li>
<li>Email: <a href="mailto:wyextay@gmail.com">wyextay@gmail.com</a></li>
</ul>
]]></content:encoded></item></channel></rss>