Dynamization of Jekyll
Jekyll is a framework for creating websites/blogs using static plain-text files. Jekyll is used by GitHub Pages, which is also the current hosting provider for Shellsharks.com. Iβve been using Git Pages since the inception of my site and for the most part have no complaints. With that said, a purely static site has some limitations in terms of the types of content one can publish/expose.
I recently got the idea to create a dashboard-like page which could display interesting quantitative data points (and other information) related to the site. Examples of these statistic include, total number of posts, the age of my site, when my blog was last updated, overall word count across all posts, etc⦠Out of the box, Jekyll is limited in its ability to generate this information in a dynamic fashion. The Jekyll-infused GitHub pages engine generates the site via an inherent pages-build-deployment Git Action (more on this later) upon commit. The site will then stay static until the next build. As such, it has limited native ability to update content in-between builds/manual-commits.
To solve for this issue, Iβve started using a variety of techniques/technologies (listed below) to introduce more dynamic functionality to my site (and more specificially, the aforementioned statboard).
- Jekyll Liquid
- JavaScript & jQuery
- Git Actions
- Advanced Git Actions (*Future Update!*)
Jekyll Liquid
Though not truly βdynamicβ, Liquid* templating language is an easy, Jekyll-native way to generate static content in a quasi-dynamic way at site build time. As an example, if I wanted to denote the exact date and time that a blog post was published I might first try to use the Liquid template {{ site.time }}
. What this actually ends up giving me is a time stamp for when the site was built (e.g. 2025-05-04 11:03:37 -0400), rather than the last updated date of the post itself. So instead, I can harness the posts custom front matter, such as βupdated:β, and access that value using the tag {{ page.updated }}
(so we get, __).
One component on the (existing) Shellsharks statboard calculates the age of the site using the last updated date of the site (maintained in the change log), minus the publish date of the first-ever Shellsharks post. Since a static, Jekyll-based, GitHub Pages site is only built (and thus only updated) when I actually physically commit an update, this component will be out of date if I do not commit atleast daily. So how did I solve for this? Enter Git Actions.
* Learn more about the tags, filters and other capabilities of Liquid here.
JavaScript & jQuery
Before we dive into the power of Git Actions, itβs worth mentioning the ability to add dynamism by simply dropping straight up, in-line JavaScript directly into the page/post Markdown (.md) files. Remember, Jekyll produces .html files directly from static, text-based files (like Markdown). So the inclusion of raw JS syntax will translate into embdedded, executable JS code in the final, generated HTML files. The usual rules for in-page JS apply here.
One component idea I had for the statboard was to have a counter of named vulnerabilities. So how could I grab that value from the page? At first, I tried fetching the DOM element with the id in which the count was exposed. However this failed because fetching that element alone meant not fetching the JS and other HTML content that was used to actually generate that count. To solve for this, I used jQuery to load the entire page into a temporary <div>
tag, then iterated through the list (<li>
) elements within that div (similar to how I calculate it on the origin page), and then finally set the dashboard component to the calculated count!
$('<div></div>').load('/infosec-blogs', function () {
var blogs = $("li",this).length;
$("#iblogs").html(blogs);
});
Additional notes on the use of JS and jQuery
- I used Googleβs Hosted Libraries to reference jQuery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
. - Be weary of adding JS comments
//
in Markdown files as I noticed the Jekyll parsing engine doesnβt do a great job of new-lining, and thus everything after a comment will end up being commented. - When using Liquid tags in in-line JS, ensure quotes (ββ,ββ) are added around the templates so that the JS code will recognize those values as strings (where applicable).
- The ability to add raw, arbitrary JS means there is a lot of untapped capability to add dynamic content to an otherwise static page. Keep in mind though that JS code is client-side, so you are still limited in that typical server-side functionality is not available in this context.
Git Actions
Thanks to the scenario I detailed in the Jekyll Liquid section, I was introduced to the world of Git Actions. Essentially, I needed a way to force an update / regeneration of my site such that one of my staticly generated Liquid tags would update at some minimum frequency (in this case, at least daily). After some Googling, I came across this action which allowed me to do just that! Essentially, it forces a blank build using a user-defined schedule as the trigger.
# File: .github/workflows/refresh.yml
name: Refresh
on:
schedule:
- cron: '0 3 * * *' # Runs every day at 3am
jobs:
refresh:
runs-on: ubuntu-latest
steps:
- name: Trigger GitHub pages rebuild
run: |
curl --fail --request POST \
--url https://api.github.com/repos/${{ github.repository }}/pages/builds \
--header "Authorization: Bearer $USER_TOKEN"
env:
# You must create a personal token with repo access as GitHub does
# not yet support server-to-server page builds.
USER_TOKEN: ${{ secrets.USER_TOKEN }}
In order to get this Action going, follow these stepsβ¦
- Log into your GitHub account and go to Settings (in the top right) β> Developer settings β> Personal access tokens.
- Generate new token and give it full repo access scope (More on OAuth scopes). I set mine to never expire, but you can choose what works best for you.
- Navigate to your GitHub Pages site repo, ***.github.io β> Settings β> Secrets β> Actions section. Here you can add a New repository secret where you give it a unique name and set the value to the personal access token generated earlier.
- In the root of your local site repository, create a .github/workflows/ folder (if one doesnβt already exist).
- Create a <name of your choice>.yml file where you will have the actual Action code (like what was provided above).
- Commit this Action file and you should be able to see run details in your repo β> Actions section within GitHub.
Additional Considerations for GitHub Actions
- When using the Liquid tag
{{ site.time }}
with a Git Action triggered build, understand that it will use the time of the server which is generating the HTML, in this case the GitHub servers themselves, which means the date will be in UTC (Conversion help). - Check out this reference for informaton on how to specify the time zone in the front matter of a page or within the Jekyll config file.
- GitHub Actions are awesome and powerful, but their are limitations to be aware of. Notably, it is important to understand the billing considerations. Free tier accounts get 2,000 minutes/month while Pro tier accounts (priced at about $44/user/year) get 3,000.
- For reference, the refresh action (provided above) was running (for me) at about 13 seconds per trigger. This means you could run that action over 9,000 times without exceeding the minute cap for a Free-tier account.
- With the above said, also consider that the default pages-build-deployment Action used by GitHub Pages to actually generate and deploy your site upon commit will also consume those allocated minutes. Upon looking at my Actions pane, I am seeing about 1m run-times for each build-and-deploy action trigger.
Whatβs Next
Iβve only just started to scratch the surface of how I can further extend and dynamize my Jekyll-based site. In future updates to this guide (or in future posts), I plan to cover more advanced GitHub Action capabilities as well as how else to add server-side functionality (maybe through serverless!) to the site. Stay tuned!