<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>theme on
A Scripter's Notes</title><link>https://scripter.co/tags/theme/</link><description>Recent content in theme
on A Scripter's Notes</description><language>en-us</language><managingEditor>kaushal.modi@gmail.com (Kaushal Modi)</managingEditor><webMaster>kaushal.modi@gmail.com (Kaushal Modi)</webMaster><lastBuildDate>Wed, 22 Apr 2026 08:24:58 -0400</lastBuildDate><generator>Hugo -- gohugo.io</generator><docs>https://validator.w3.org/feed/docs/rss2.html</docs><atom:link href="https://scripter.co/tags/theme/index.xml" rel="self" type="application/rss+xml"/><item><title>Hugo Modules: Importing a Theme</title><link>https://scripter.co/hugo-modules-importing-a-theme/</link><description>&lt;blockquote>A brief guide on how to install Hugo themes using Hugo Modules.&lt;/blockquote>&lt;div class="ox-hugo-toc toc">
&lt;div class="heading">Table of Contents&lt;/div>
&lt;ul>
&lt;li>&lt;a href="#clean-up-the-old-way-of-setting-a-theme">&lt;span class="section-num">1&lt;/span> Clean up the old way of setting a theme&lt;/a>&lt;/li>
&lt;li>&lt;a href="#import-the-theme-module">&lt;span class="section-num">2&lt;/span> Import the &amp;ldquo;theme&amp;rdquo; module&lt;/a>
&lt;ul>
&lt;li>&lt;a href="#module-imports-example">Quick Example&lt;/a>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>&lt;a href="#hugo-mod-tidy">&lt;span class="section-num">3&lt;/span> &lt;code>hugo mod tidy&lt;/code>&lt;/a>&lt;/li>
&lt;li>&lt;a href="#updating-the-theme">&lt;span class="section-num">4&lt;/span> Updating the theme&lt;/a>&lt;/li>
&lt;li>&lt;a href="#dependency-graph">Dependency Graph&lt;/a>&lt;/li>
&lt;li>&lt;a href="#building-your-hugo-site-on-a-server">Building your Hugo site on a server&lt;/a>&lt;/li>
&lt;li>&lt;a href="#in-a-nutshell">In a nutshell&lt;/a>&lt;/li>
&lt;li>&lt;a href="#references">References&lt;/a>&lt;/li>
&lt;/ul>
&lt;/div>
&lt;!--endtoc-->
&lt;p>Hello! You are reading this post because you are probably interested
in the Hugo Modules feature and are considering to import a Hugo
Module as a theme.&lt;/p>
&lt;p>&lt;strong>Step 0&lt;/strong> for that approach is to make your site repo a Hugo Module. If
your site already is, then it would have a &lt;code>go.mod&lt;/code> file in the repo
root. If you don&amp;rsquo;t have the &lt;code>go.mod&lt;/code> file, check out the previous post
&lt;a href="https://scripter.co/hugo-modules-getting-started/">Hugo Modules: Getting Started&lt;/a> first ‼️&lt;/p>
&lt;div class="note">
&lt;p>If you don&amp;rsquo;t have a &lt;code>go.mod&lt;/code> file for your site repo, and you still
decide to continue with the next steps, don&amp;rsquo;t complain if you see
errors like &lt;em>module &amp;ldquo;foo&amp;rdquo; not found; either add it as a Hugo Module or
store it in &amp;ldquo;&amp;lt;your site repo&amp;gt;/themes&amp;rdquo;.: module does not exist&lt;/em>. &amp;mdash;
&lt;a href="https://discourse.gohugo.io/t/hugo-mod-init-fails-to-create-go-mod-if-hugo-detects-an-error-prematurely-in-site-config-toml/36687">speaking from experience&lt;/a> 😉.&lt;/p>
&lt;/div>
&lt;p>With that out of the way, here are the next steps ..&lt;/p>
&lt;h2 id="clean-up-the-old-way-of-setting-a-theme">&lt;span class="section-num">1&lt;/span> Clean up the old way of setting a theme&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#clean-up-the-old-way-of-setting-a-theme">#&lt;/a>&lt;/h2>
&lt;p>If you are upgrading your Hugo site to switch from the legacy method
of using themes (i.e using the &lt;code>theme&lt;/code> variable in the site config
&lt;span class="sidenote-number">&lt;small class="sidenote">
In my posts, you may have seen me use the &lt;em>Site Config&lt;/em> term or
&lt;code>config.toml&lt;/code> &amp;ndash; They mean the same thing.
&lt;/small>&lt;/span>
), you need to clean that up.&lt;/p>
&lt;ol>
&lt;li>Remove the &lt;code>theme&lt;/code> variable from your site config.&lt;/li>
&lt;li>Remove the &lt;code>themes&lt;/code> directory, or move it out of your Hugo site
repo.
&lt;ul>
&lt;li>If you were cloning a theme developed by someone else in there,
you can just remove this directory.&lt;/li>
&lt;li>If you are maintaining your own theme in that directory, move it
out of your site repo and &lt;a href="https://scripter.co/hugo-modules-getting-started/#convert-to-hugo-module">convert it to a Hugo Module&lt;/a>.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;h2 id="import-the-theme-module">&lt;span class="section-num">2&lt;/span> Import the &amp;ldquo;theme&amp;rdquo; module&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#import-the-theme-module">#&lt;/a>&lt;/h2>
&lt;p>The &lt;em>theme&lt;/em> is quoted in this title, because the concept of a Hugo
&amp;ldquo;theme&amp;rdquo; is a bit old now (&lt;span class="timestamp-wrapper">&lt;span class="timestamp">&amp;lt;2022-05-26 Thu&amp;gt;&lt;/span>&lt;/span>) and that has been
superseded with the concept of &amp;ldquo;modules&amp;rdquo;.&lt;/p>
&lt;p>The main difference between a theme and a generic &lt;em>Hugo Module&lt;/em> is
that the former will allow you to build your site entirely, while the
latter might implement only some modular features like enabling the
ATOM feed, or adding a search to your website.&lt;/p>
&lt;div class="note">
&lt;p>I am mentioning this again for convenience, from &lt;a href="https://scripter.co/hugo-modules-getting-started/">the previous post in
this series&lt;/a>:&lt;/p>
&lt;p>&lt;em>A module can be your main project or a smaller module providing one
or more of the 7 component types defined in Hugo: &lt;strong>static&lt;/strong>, &lt;strong>content&lt;/strong>,
&lt;strong>layouts&lt;/strong>, &lt;strong>data&lt;/strong>, &lt;strong>assets&lt;/strong>, &lt;strong>i18n&lt;/strong>, and &lt;strong>archetypes&lt;/strong>. You can combine
modules in any combination you like, and even mount directories from
non-Hugo projects, forming a big, virtual union file system.&lt;/em>&lt;/p>
&lt;/div>
&lt;p>A theme will need to have the &amp;ldquo;layout&amp;rdquo; component. Additionally, it
might have the &amp;ldquo;assets&amp;rdquo;, &amp;ldquo;static&amp;rdquo;, and other components too.&lt;/p>
&lt;p>Importing a module as a theme will typically look like this in your
site config:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-toml" data-lang="toml">&lt;span class="line">&lt;span class="cl">&lt;span class="p">[&lt;/span>&lt;span class="nx">module&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">[[&lt;/span>&lt;span class="nx">module&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">imports&lt;/span>&lt;span class="p">]]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">path&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;URL of the theme&amp;#39;s git remote *without* the &amp;#39;https://&amp;#39; part&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The &lt;strong>path&lt;/strong> here would be something like
&lt;code>github.com/USER/THEME-REPO-NAME&lt;/code> or
&lt;code>gitlab.com/USER/THEME-REPO-NAME&lt;/code>.&lt;/p>
&lt;dl>
&lt;dt>Note&lt;/dt>
&lt;dd>It&amp;rsquo;s possible to take &lt;span class="underline">any&lt;/span> Hugo theme git repo and import
that as a Hugo Module even if that repo isn&amp;rsquo;t actually one
i.e. doesn&amp;rsquo;t have a &lt;code>go.mod&lt;/code>. But it&amp;rsquo;s recommended that the theme be
a proper Hugo Module so that you have better dependency tracking
between your site and the theme.&lt;/dd>
&lt;/dl>
&lt;h3 id="module-imports-example">Quick Example&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#module-imports-example">#&lt;/a>&lt;/h3>
&lt;p>Follow these steps if you want to try out how this Hugo Module based
theme importing&lt;/p>
&lt;div class="note">
&lt;p>As a reminder, you &lt;a href="https://scripter.co/hugo-modules-getting-started/#install-a-recent-version-of-go">need to have Go installed&lt;/a>
on your system.&lt;/p>
&lt;/div>
&lt;ol>
&lt;li>Create a temporary directory somewhere and &lt;code>cd&lt;/code> to it.&lt;/li>
&lt;li>Initialize your site as a Hugo Module: &lt;code>hugo mod init foo&lt;/code> (yeah,
type that out literally &amp;mdash; it will work)&lt;/li>
&lt;li>Create a &lt;code>config.toml&lt;/code> file with the below content. It imports the
&lt;a href="https://gitlab.com/kaushalmodi/hugo-mwe-theme">&lt;code>hugo-mwe-theme&lt;/code>&lt;/a>
&lt;span class="sidenote-number">&lt;small class="sidenote">
&lt;code>hugo-mwe-theme&lt;/code> is a minimal Hugo theme that I use to quickly try
out some new feature in Hugo or to create a &lt;em>minimal working
example&lt;/em> to reproduce a bug.
&lt;/small>&lt;/span>
theme.
&lt;a id="code-snippet--theme-module-import-example">&lt;/a>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-toml" data-lang="toml">&lt;span class="line">&lt;span class="cl">&lt;span class="p">[&lt;/span>&lt;span class="nx">module&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">[[&lt;/span>&lt;span class="nx">module&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">imports&lt;/span>&lt;span class="p">]]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">path&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;gitlab.com/kaushalmodi/hugo-mwe-theme&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="src-block-caption">
&lt;span class="src-block-number">&lt;a href="#code-snippet--theme-module-import-example">Code Snippet 1&lt;/a>:&lt;/span>
Example of importing a Hugo module as a theme in &lt;code>config.toml&lt;/code>
&lt;/div>
&lt;/li>
&lt;li>Create &lt;code>content/hello.md&lt;/code>. This step is optional and is only so
that your test site as some content.
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-md" data-lang="md">&lt;span class="line">&lt;span class="cl">+++
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">title = &amp;#34;Hello&amp;#34;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">+++
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Hey!
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/li>
&lt;/ol>
&lt;p>That&amp;rsquo;s it! Now run the Hugo server (&lt;code>hugo server&lt;/code>) and look at your
site running on localhost .. while thinking in disbelief.. &lt;em>just how
easy all of this was!&lt;/em> 😃.&lt;/p>
&lt;ul>
&lt;li>Did you need to manually clone any theme? &lt;strong>No&lt;/strong>&lt;/li>
&lt;li>Would you need to deal with the &lt;code>.gitmodules&lt;/code> file? &lt;strong>No&lt;/strong>&lt;/li>
&lt;/ul>
&lt;h2 id="hugo-mod-tidy">&lt;span class="section-num">3&lt;/span> &lt;code>hugo mod tidy&lt;/code>&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#hugo-mod-tidy">#&lt;/a>&lt;/h2>
&lt;p>Finally, run &lt;a href="https://gohugo.io/commands/hugo_mod_tidy/">&lt;code>hugo mod tidy&lt;/code>&lt;/a> to clean up the &lt;code>go.mod&lt;/code> and
update/generate the &lt;code>go.sum&lt;/code> file. These files will track the module
dependencies for your site.&lt;/p>
&lt;ul>
&lt;li>The &lt;code>go.mod&lt;/code> contains the direct module dependencies for your site.&lt;/li>
&lt;li>The &lt;code>go.sum&lt;/code> contains the versions and hashes of all the direct &lt;strong>and
indirect&lt;/strong> dependencies
&lt;span class="sidenote-number">&lt;small class="sidenote">
Just as you added a theme as a Hugo Module to your site, it&amp;rsquo;s
possible that that theme is depending on other Hugo Modules (like
the ones I mentioned earlier: ATOM feeds, search, etc.).
&lt;/small>&lt;/span>
for your site.&lt;/li>
&lt;/ul>
&lt;div class="note">
&lt;p>You would need to commit the &lt;code>go.mod&lt;/code> and &lt;code>go.sum&lt;/code>&lt;sup id="fnref:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup> files if you
build and deploy your website on a remote server or a &lt;a href="https://en.wikipedia.org/wiki/CI/CD">CI/CD&lt;/a> system.&lt;/p>
&lt;/div>
&lt;p>If you ran the &lt;a href="#module-imports-example">Quick Example&lt;/a>, you will see this (as of
&lt;span class="timestamp-wrapper">&lt;span class="timestamp">&amp;lt;2022-05-26 Thu&amp;gt;&lt;/span>&lt;/span>) in your &lt;code>go.mod&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="cl">module foo
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">go 1.18
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">require gitlab.com/kaushalmodi/hugo-mwe-theme v0.1.1 // indirect
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>.. and this in your &lt;code>go.sum&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="cl">gitlab.com/kaushalmodi/hugo-mwe-theme v0.1.1 h1:FyTp43CJRpBfoHyWnwQFx//cipgP6xQ9/uucj+qjj1U=
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">gitlab.com/kaushalmodi/hugo-mwe-theme v0.1.1/go.mod h1:vvq0r/SfKMbiPbyqL4YottSOkpCkBSosqGRm82aDNrU=
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;h2 id="updating-the-theme">&lt;span class="section-num">4&lt;/span> Updating the theme&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#updating-the-theme">#&lt;/a>&lt;/h2>
&lt;p>Here are some common ways to update the theme module going forward:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Command&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>hugo mod get -u&lt;/code>&lt;/td>
&lt;td>Update only the modules that your site directly depends on.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>hugo mod get -u ./...&lt;/code>&lt;/td>
&lt;td>Update the modules that your site depends on in a recursive fashion.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Additionally, you might or might not need these, but I am documenting
them here for completeness:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Command&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>hugo mod get -u &amp;lt;module path&amp;gt;&lt;/code>&lt;/td>
&lt;td>Update only the specified module&lt;sup id="fnref:2">&lt;a href="#fn:2" class="footnote-ref" role="doc-noteref">2&lt;/a>&lt;/sup> to the latest version. Example: &lt;code>hugo mod get -u gitlab.com/kaushalmodi/hugo-mwe-theme&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>hugo mod get &amp;lt;module path&amp;gt;@&amp;lt;git ref&amp;gt;&lt;/code>&lt;/td>
&lt;td>Update a module to the specified git tag or commit. Example: &lt;code>hugo mod get gitlab.com/kaushalmodi/hugo-mwe-theme@v0.1.1&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="dependency-graph">Dependency Graph&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#dependency-graph">#&lt;/a>&lt;/h2>
&lt;p>If you have a theme added as a Hugo Module, which depends on other
Hugo Modules, it&amp;rsquo;s often helpful to know the dependency graph. You can
do that by running:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">hugo mod graph
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>For the above &lt;a href="#module-imports-example">Quick Example&lt;/a>, you will see just this one line because
that theme does not depend on other modules:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="cl">foo gitlab.com/kaushalmodi/hugo-mwe-theme@v0.1.1
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;h2 id="building-your-hugo-site-on-a-server">Building your Hugo site on a server&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#building-your-hugo-site-on-a-server">#&lt;/a>&lt;/h2>
&lt;p>Alright, so you are able to build your site locally after switching to
using themes as modules, great!&lt;/p>
&lt;p>Now, if you build and deploy your site on a remote server like Netlify
or Vercel, you need to ensure that you have a recent version of Go
installed in their environment too.&lt;/p>
&lt;p>I deploy this website using Netlify, and so I know how to do that
there &amp;mdash; Set the &lt;code>GO_VERSION&lt;/code> environment variable to a recent
version like &lt;strong>1.18&lt;/strong> in the &lt;a href="https://docs.netlify.com/configure-builds/environment-variables/">Environment variables&lt;/a> section in Netlify
&lt;em>Build &amp;amp; deploy&lt;/em> settings.&lt;/p>
&lt;h2 id="in-a-nutshell">In a nutshell&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#in-a-nutshell">#&lt;/a>&lt;/h2>
&lt;ol>
&lt;li>&lt;strong>First&lt;/strong> convert your Hugo site to a Hugo module.&lt;/li>
&lt;li>Then replace the &lt;code>theme&lt;/code> in your site config with a module import.&lt;/li>
&lt;/ol>
&lt;p>Enjoy! 🍾&lt;/p>
&lt;h2 id="references">References&amp;nbsp;&lt;a class="headline-hash no-text-decoration" href="#references">#&lt;/a>&lt;/h2>
&lt;ul>
&lt;li>&lt;a href="https://gohugo.io/hugo-modules/use-modules/">Hugo Modules documentation&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.thenewdynamic.com/article/hugo-modules-everything-from-imports-to-create/">Hugo Modules: Everything you need to know!&lt;/a>&lt;/li>
&lt;/ul>
&lt;div class="footnotes" role="doc-endnotes">
&lt;hr>
&lt;ol>
&lt;li id="fn:1">
&lt;p>It is recommended to &lt;em>git commit&lt;/em> the &lt;code>go.sum&lt;/code> along with your
site&amp;rsquo;s &lt;code>go.mod&lt;/code>. From the &lt;a href="https://github.com/golang/go/wiki/Modules#releasing-modules-all-versions">Go Modules documention&lt;/a>: &lt;em>Ensure your
&lt;code>go.sum&lt;/code> file is committed along with your &lt;code>go.mod&lt;/code> file. See &lt;a href="https://github.com/golang/go/wiki/Modules#should-i-commit-my-gosum-file-as-well-as-my-gomod-file">FAQ
below&lt;/a> for more details and rationale.&lt;/em>&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:2">
&lt;p>Trust me.. once you get a hang of the Hugo Module system, your
site will have more than one!&amp;#160;&lt;a href="#fnref:2" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;/div></description><author>Kaushal.Modi@fakeEmailToMakeValidatorHappy.com (Kaushal Modi)</author><category domain="https://scripter.co/categories/hugo">hugo</category><category domain="https://scripter.co/series/hugo-modules">Hugo Modules</category><category domain="https://scripter.co/tags/module">module</category><category domain="https://scripter.co/tags/100daystooffload">100DaysToOffload</category><category domain="https://scripter.co/tags/theme">theme</category><category domain="https://scripter.co/tags/component">component</category><guid>https://scripter.co/hugo-modules-importing-a-theme/</guid><pubDate>Thu, 26 May 2022 16:26:00 -0400</pubDate></item></channel></rss>