<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Saran Siriphantnon</title>
    <description>The latest articles on DEV Community by Saran Siriphantnon (@sarans21).</description>
    <link>https://dev.to/sarans21</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4098682%2F0fc6f6c8-c319-4e7e-957b-853f7be5bc79.png</url>
      <title>DEV Community: Saran Siriphantnon</title>
      <link>https://dev.to/sarans21</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sarans21"/>
    <language>en</language>
    <item>
      <title>How Jekyll Works</title>
      <dc:creator>Saran Siriphantnon</dc:creator>
      <pubDate>Fri, 28 Aug 2026 10:32:30 +0000</pubDate>
      <link>https://dev.to/sarans21/how-jekyll-works-1fem</link>
      <guid>https://dev.to/sarans21/how-jekyll-works-1fem</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; This post is a more concise version of the much longer version on &lt;a href="https://sarans.so/articles/how_jekyll_works" rel="noopener noreferrer"&gt;my blog&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://jekyllrb.com/" rel="noopener noreferrer"&gt;Jekyll&lt;/a&gt;, the static site generator, although it is the older technology, only consists of about 6800 lines while can achieve many things: Theme, Layout, Markdown, Plugins, Live-Reload, and more.&lt;/p&gt;

&lt;p&gt;Ever wonder how does it works internally? I hope what's am about to write can give you some ideas.&lt;/p&gt;

&lt;p&gt;When serving the blog (&lt;code&gt;$ jekyll serve&lt;/code&gt;), the internal calls look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0u9vhugwgjbv5xft6lcb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0u9vhugwgjbv5xft6lcb.png" alt="Jekyll Overview" width="800" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In its heart, it's the &lt;a href="https://github.com/jekyll/jekyll/blob/v4.4.1/lib/jekyll/site.rb" rel="noopener noreferrer"&gt;Site&lt;/a&gt; class and its &lt;code&gt;#new()&lt;/code&gt; and &lt;code&gt;#process()&lt;/code&gt; method.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;#new()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;This loads plugins:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;generators&lt;/code&gt; the plugins that receive the &lt;code&gt;site&lt;/code&gt; information and generates additional content such as atom, &lt;code&gt;sitemap.xml&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;converters&lt;/code&gt; the plugins that receive the &lt;code&gt;site&lt;/code&gt; and &lt;code&gt;contents&lt;/code&gt; (pages/posts you wrote and what generated from the &lt;code&gt;generators&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The loading mechanism is especially interesting. Any plugin must inherit from &lt;code&gt;Jekyll::Generator&lt;/code&gt; or &lt;code&gt;Jekyll::Converter&lt;/code&gt;, so we can load them by tracking their descendants:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;instantiate_subclasses&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;klass&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;klass&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;descendants&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;select&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;safe&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;safe&lt;/span&gt; &lt;span class="p"&gt;}.&lt;/span&gt;&lt;span class="nf"&gt;tap&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort!&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map!&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The loading code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;converters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;instantiate_subclasses&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Jekyll&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Converter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generators&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;instantiate_subclasses&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Jekyll&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Generator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;code&gt;#process()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://github.com/jekyll/jekyll/blob/v4.4.1/lib/jekyll/site.rb#L74" rel="noopener noreferrer"&gt;code itself&lt;/a&gt; is very clean:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;process&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;profiler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;profile_process&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"profile"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="n"&gt;reset&lt;/span&gt;
  &lt;span class="n"&gt;read&lt;/span&gt;
  &lt;span class="n"&gt;generate&lt;/span&gt;
  &lt;span class="n"&gt;render&lt;/span&gt;
  &lt;span class="n"&gt;cleanup&lt;/span&gt;
  &lt;span class="n"&gt;write&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;reset&lt;/code&gt; resets &lt;code&gt;site&lt;/code&gt; state into empty states (for example, &lt;code&gt;site.pages = []&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;read&lt;/code&gt; reads site and theme contents into &lt;code&gt;site.pages&lt;/code&gt;, &lt;code&gt;site.posts&lt;/code&gt;, &lt;code&gt;site.static_files&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;generate&lt;/code&gt; uses loaded &lt;code&gt;generators&lt;/code&gt; plugins to generate additional contents as mentioned&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;render&lt;/code&gt; renders contents using &lt;a href="https://shopify.github.io/liquid/" rel="noopener noreferrer"&gt;Liquid template&lt;/a&gt;, converters (such as &lt;code&gt;Markdown&lt;/code&gt; converter), and put into layouts (layout is Liquid template that renders &lt;code&gt;content&lt;/code&gt; variable)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cleanup&lt;/code&gt; removes obsolete files by comparing new set of generated files versus the current generated files&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;write&lt;/code&gt; writes outputs from &lt;code&gt;render&lt;/code&gt; into the actual filesystem&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Watching for File Changes
&lt;/h2&gt;

&lt;p&gt;It uses &lt;code&gt;listen&lt;/code&gt; gem underneath, any file changes will trigger the &lt;code&gt;#new&lt;/code&gt; and &lt;code&gt;#process&lt;/code&gt; steps again (unless incremental build is enabled) then notify the browser via &lt;code&gt;LiveReload&lt;/code&gt; websocket communication.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;LiveReload.js&lt;/code&gt; on the pages got injected when serving files by manipulating &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt; through custom &lt;code&gt;WEBrick&lt;/code&gt; handler.&lt;/p&gt;

&lt;h3&gt;
  
  
  Code Worth Stealing
&lt;/h3&gt;

&lt;p&gt;There are many good piece of code worth stealing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/jekyll/jekyll/blob/v4.4.1/lib/jekyll/site.rb" rel="noopener noreferrer"&gt;lib/jekyll/site.rb&lt;/a&gt; especially on the plugins loading&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/jekyll/jekyll/blob/v4.4.1/lib/jekyll/external.rb" rel="noopener noreferrer"&gt;lib/jekyll/external.rb&lt;/a&gt; for how to handle when &lt;code&gt;require&lt;/code&gt; fails&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/jekyll/jekyll/blob/v4.4.1/lib/jekyll/profiler.rb" rel="noopener noreferrer"&gt;lib/jekyll/profiler.rb&lt;/a&gt; for how a simple profiler could be done for your command line&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/jekyll/jekyll/blob/v4.4.1/lib/jekyll/cache.rb" rel="noopener noreferrer"&gt;lib/jekyll/cache.rb&lt;/a&gt; for how a simple cache on disk could be implemented&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/jekyll/jekyll/blob/v4.4.1/lib/jekyll/commands/serve/servlet.rb" rel="noopener noreferrer"&gt;lib/jekyll/commands/serve/servlet.rb&lt;/a&gt; for LiveReload injection for your site&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/jekyll/jekyll-watch" rel="noopener noreferrer"&gt;jekyll-watch&lt;/a&gt; if you need watching over files and reacting to changes&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/jekyll/jekyll/blob/v4.4.1/History.markdown" rel="noopener noreferrer"&gt;History.markdown&lt;/a&gt; seems to be manually kept&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The Jekyll code itself is very clean (though I would say it is more engineered than clean). I wrote more about it including caching, profiling, security, and more on &lt;a href="https://sarans.so/articles/how_jekyll_works" rel="noopener noreferrer"&gt;my blog&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Hope you like this article. If you spot any mistakes or want to share feedback, please feel free to comment or DM me :)&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
