<linkhref="https://mcshelby.github.io/hugo-theme-relearn/basics/customization/index.html"rel="canonical"type="text/html"title="Customization :: Hugo Relearn Theme">
<p>The theme is usable in different scenarios, requiring the following mandatory settings in your <code>hugo.toml</code>. All settings not mentioned can be set to your liking.</p>
<h3id="public-webserver-from-root">Public Webserver from Root</h3>
<divclass="wrap-code highlight"><pretabindex="0"class="chroma"><codeclass="language-toml"data-lang="toml"><spanclass="line"><spanclass="cl"><spanclass="nx">baseURL</span><spanclass="p">=</span><spanclass="s2">"https://example.com/"</span></span></span></code></pre></div><h3id="public-webserver-from-subdirectory">Public Webserver from Subdirectory</h3>
<p>Using a <code>baseURL</code> with a subdirectory and <code>relativeURLs=true</code> are mutally exclusive due to the fact, that <ahref="https://github.com/gohugoio/hugo/issues/12130"target="_blank">Hugo does not apply the <code>baseURL</code> correctly</a>.</p>
<p>If you need both, you have to generate your site twice but with different settings into separate directories.</p>
<p>Sublemental pages (like <code>sitemap.xml</code>, <code>rss.xml</code>) and generated social media links inside of your pages will always be generated with absolute URLs and will not work if you set <code>relativeURLs=true</code>.</p>
<p>If you are using <code>uglyURLs=false</code> (Hugo’s default), the theme will append an additional <code>index.html</code> to all page links to make your site be servable from the file system. If you don’t care about the file system and only serve your page via a webserver you can generate the links without this:</p>
</span></span><spanclass="line"><spanclass="cl"><spanclass="nx">home</span><spanclass="p">=</span><spanclass="p">[</span><spanclass="s2">"html"</span><spanclass="p">,</span><spanclass="s2">"rss"</span><spanclass="p">,</span><spanclass="s2">"search"</span><spanclass="p">]</span></span></span></code></pre></div><p>This will generate a search index file at the root of your public folder ready to be consumed by the Lunr search library. Note that the <code>search</code> outputformat was named <code>json</code> in previous releases but was implemented differently. Although <code>json</code> still works, it is now deprecated.</p>
<p>If you want to use the search feature from the file system, migrating from an older installation of the theme, make sure to change your outputformat for the homepage from the now deprecated <code>json</code> to <code>search</code><ahref="/hugo-theme-relearn/basics/customization/index.html#activate-search">as seen below</a>.</p>
<p>You can add a dedicated search page for your page by adding the <code>searchpage</code> outputformat to your home page by adding the following lines in your <code>hugo.toml</code> file. This will cause Hugo to generate a new file <code>http://example.com/mysite/search.html</code>.</p>
</span></span><spanclass="line"><spanclass="cl"><spanclass="nx">home</span><spanclass="p">=</span><spanclass="p">[</span><spanclass="s2">"html"</span><spanclass="p">,</span><spanclass="s2">"rss"</span><spanclass="p">,</span><spanclass="s2">"search"</span><spanclass="p">,</span><spanclass="s2">"searchpage"</span><spanclass="p">]</span></span></span></code></pre></div><p>You can access this page by either clicking on the magnifier glass or by typing some search term and pressing <code>ENTER</code> inside of the menu’s search box .</p>
<p><ahref="#R-image-f32551bb718e6827259bc1b5383269dd"class="lightbox-link"><imgsrc="/hugo-theme-relearn/basics/customization/search_page.png?&width=60pc"alt="Screenshot of the dedicated search page"class="figure-image bg-white border lightbox noshadow"style="height: auto; width: 60pc;"loading="lazy"></a>
<ahref="javascript:history.back();"class="lightbox-back"id="R-image-f32551bb718e6827259bc1b5383269dd"><imgsrc="/hugo-theme-relearn/basics/customization/search_page.png?&width=60pc"alt="Screenshot of the dedicated search page"class="lightbox-image bg-white border lightbox noshadow"loading="lazy"></a></p>
<p>To have Hugo create the dedicated search page successfully, you must not generate the URL <code>http://example.com/mysite/search.html</code> from your own content. This can happen if you set <code>uglyURLs=true</code> in your <code>hugo.toml</code> and defining a Markdown file <code>content/search.md</code>.</p>
<p>You can activate print support to add the capability to print whole chapters or even the complete site. Just add the <code>print</code> output format to your home, section and page in your <code>hugo.toml</code> as seen below:</p>
</span></span><spanclass="line"><spanclass="cl"><spanclass="nx">page</span><spanclass="p">=</span><spanclass="p">[</span><spanclass="s2">"html"</span><spanclass="p">,</span><spanclass="s2">"rss"</span><spanclass="p">,</span><spanclass="s2">"print"</span><spanclass="p">]</span></span></span></code></pre></div><p>This will add a little printer icon in the top bar. It will switch the page to print preview when clicked. You can then send this page to the printer by using your browser’s usual print functionality.</p>
<p>The resulting URL will not be <ahref="https://gohugo.io/templates/output-formats/#configure-output-formats"target="_blank">configured ugly</a> in terms of <ahref="https://gohugo.io/content-management/urls/#ugly-urls"target="_blank">Hugo’s URL handling</a> even if you’ve set <code>uglyURLs=true</code> in your <code>hugo.toml</code>. This is due to the fact that for one mime type only one suffix can be configured.</p>
<p>Nevertheless, if you’re unhappy with the resulting URLs you can manually redefine <code>outputFormats.print</code> in your own <code>hugo.toml</code> to your liking.</p>
</span></span><spanclass="line"><spanclass="cl"><spanclass="p">...</span></span></span></code></pre></div><p>If this option is not configured for a specific language, they will get their default values:</p>
<divclass="wrap-code highlight"><pretabindex="0"class="chroma"><codeclass="language-toml"data-lang="toml"><spanclass="line"><spanclass="cl"><spanclass="nx">landingPageName</span><spanclass="p">=</span><spanclass="s2">"<i class='fas fa-home'></i> Home"</span></span></span></code></pre></div><p>The home button is going to look like this:</p>
<h2id="social-media-meta-tags">Social Media Meta Tags</h2>
<p>You can add social media meta tags for the <ahref="https://gohugo.io/templates/internal/#open-graph"target="_blank">Open Graph</a> protocol and <ahref="https://gohugo.io/templates/internal/#twitter-cards"target="_blank">Twitter Cards</a> to your site. These are configured as mentioned in the Hugo docs.</p>
<h2id="change-the-menu-width">Change the Menu Width</h2>
<p>If you want to adjust the menu width you can define the following CSS variables in your <code>custom-header.html</code>. Note that <code>--MENU-WIDTH-S</code> applies to the menu flyout width in mobile mode for small screen sizes.</p>
</span></span><spanclass="line"><spanclass="cl"><spanclass="p">}</span></span></span></code></pre></div><h2id="own-shortcodes-with-javascript-dependencies">Own Shortcodes with JavaScript Dependencies</h2>
<p>Certain shortcodes make use of additional JavaScript files. The theme only loads these dependencies if the shortcode is used. To do so correctly the theme adds management code in various files.</p>
<p>You can you use this mechanism in your own shortcodes. Say you want to add a shortcode <code>myshortcode</code> that also requires the <code>jquery</code> JavaScript library.</p>
<p>Add the dependency loader file <code>layouts/partials/dependencies/myshortcode.html</code>. The loader file will be appended to your header or footer, dependend on the <code>location</code> setting in your <code>hugo.toml</code>.</p>
<li>the <code>name</code> setting in your <code>hugo.toml</code> must match the key (that needs to be prefixed with a <code>has</code>) you used for the store in your <code>layouts/shortcodes/myshortcode.html</code>.</li>
<li>the key on <code>params.relearn.dependencies</code> in your <code>hugo.toml</code> must match the base file name of your loader file.</li>
<p>Certain parts of the theme can be changed for support of your own <ahref="https://gohugo.io/templates/output-formats/"target="_blank">output formats</a>. Eg. if you define a new output format <code>PLAINTEXT</code> in your <code>hugo.toml</code>, you can add a file <code>layouts/partials/header.plaintext.html</code> to change the way, the page header should look like for that output format.</p>
<h2id="react-to-variant-switches-in-javascript">React to Variant Switches in JavaScript</h2>
<p>Once a color variant is fully loaded, either initially or by switching the color variant manually with the variant selector, the custom event <code>themeVariantLoaded</code> on the <code>document</code> will be dispatched. You can add an event listener and react to changes.</p>
<p>The Relearn theme has been built to be as configurable as possible by defining multiple <ahref="https://gohugo.io/templates/partials/"target="_blank">partials</a></p>
<p>In <code>themes/hugo-theme-relearn/layouts/partials/</code>, you will find all the partials defined for this theme. If you need to overwrite something, don’t change the code directly. Instead <ahref="https://gohugo.io/themes/customizing/"target="_blank">follow this page</a>. You’d create a new partial in the <code>layouts/partials</code> folder of your local project. This partial will have the priority.</p>
<p>This theme defines the following partials :</p>
<li><code>header.html</code>: the header of the page. See <ahref="/hugo-theme-relearn/basics/customization/index.html#output-formats">output-formats</a></li>
<li><code>footer.html</code>: the footer of the page. See <ahref="/hugo-theme-relearn/basics/customization/index.html#output-formats">output-formats</a></li>
<li><code>body.html</code>: the body of the page. The body may contain of one or many articles. See <ahref="/hugo-theme-relearn/basics/customization/index.html#output-formats">output-formats</a></li>
<li><code>article.html</code>: the output for a single article, can contain elements around your content. See <ahref="/hugo-theme-relearn/basics/customization/index.html#output-formats">output-formats</a></li>
<li><code>menu.html</code>: left menu. <em>Not meant to be overwritten</em></li>
<li><code>search.html</code>: search box. <em>Not meant to be overwritten</em></li>
<li><code>custom-header.html</code>: custom headers in page. Meant to be overwritten when adding CSS imports. Don’t forget to include <code>style</code> HTML tag directive in your file.</li>
<li><code>custom-footer.html</code>: custom footer in page. Meant to be overwritten when adding JavaScript. Don’t forget to include <code>javascript</code> HTML tag directive in your file.</li>
<li><code>heading-pre.html</code>: side-wide configuration to prepend to pages title headings. If you override this, it is your responsibility to take the page’s <code>headingPre</code> setting into account.</li>
<li><code>heading-post.html</code>: side-wide configuration to append to pages title headings. If you override this, it is your responsibility to take the page’s <code>headingPost</code> setting into account.</li>
<li><code>logo.html</code>: the logo, on top left hand corner</li>
<li><code>meta.html</code>: HTML meta tags, if you want to change default behavior</li>
<li><code>menu-pre.html</code>: side-wide configuration to prepend to menu items. If you override this, it is your responsibility to take the page’s <code>menuPre</code> setting into account.</li>
<li><code>menu-post.html</code>: side-wide configuration to append to menu items. If you override this, it is your responsibility to take the page’s <code>menuPost</code> setting into account.</li>
<li><code>menu-footer.html</code>: footer of the the left menu</li>
<li><code>toc.html</code>: table of contents</li>
<li><code>content.html</code>: the content page itself. This can be overridden if you want to display page’s meta data above or below the content.</li>
<li><code>content-header.html</code>: header above the title, has a default implementation but you can overwrite it if you don’t like it.</li>
<li><code>content-footer.html</code>: footer below the content, has a default implementation but you can overwrite it if you don’t like it.</li>