<?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: Jon Arne Viksås</title>
    <description>The latest articles on DEV Community by Jon Arne Viksås (@craftsmandigital).</description>
    <link>https://dev.to/craftsmandigital</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F210313%2Fae00beb4-2d21-42a5-9c5d-c3b973586b02.jpeg</url>
      <title>DEV Community: Jon Arne Viksås</title>
      <link>https://dev.to/craftsmandigital</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/craftsmandigital"/>
    <language>en</language>
    <item>
      <title>Python</title>
      <dc:creator>Jon Arne Viksås</dc:creator>
      <pubDate>Sun, 29 Dec 2024 12:25:05 +0000</pubDate>
      <link>https://dev.to/craftsmandigital/python-39a1</link>
      <guid>https://dev.to/craftsmandigital/python-39a1</guid>
      <description></description>
      <category>python</category>
    </item>
    <item>
      <title>Hugo modules for "dummies"</title>
      <dc:creator>Jon Arne Viksås</dc:creator>
      <pubDate>Tue, 22 Oct 2019 14:05:52 +0000</pubDate>
      <link>https://dev.to/craftsmandigital/hugo-modules-for-dummies-42j9</link>
      <guid>https://dev.to/craftsmandigital/hugo-modules-for-dummies-42j9</guid>
      <description>&lt;p&gt;&lt;a href="https://gohugo.io/hugo-modules/"&gt;&lt;strong&gt;Hugo modules&lt;/strong&gt;&lt;/a&gt; has been available in &lt;a href="https://gohugo.io/"&gt;&lt;strong&gt;Hugo&lt;/strong&gt;&lt;/a&gt; since version 0.56. There is hard to find a step by step tutorial that make it easy to get up and running with &lt;strong&gt;Hugo modules&lt;/strong&gt;. I made this tutorial for me and other noobs, that are fighting with &lt;strong&gt;Hugo modules&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The tutorial grasps the core functionality of &lt;strong&gt;Hugo modules&lt;/strong&gt; with examples that you can follow, to get an example &lt;strong&gt;Hugo&lt;/strong&gt; site up and running with &lt;strong&gt;Hugo modules&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;prerequisite to this tutorial is knowledge abut &lt;strong&gt;Hugo&lt;/strong&gt;, &lt;a href="https://git-scm.com/"&gt;&lt;strong&gt;Git&lt;/strong&gt;&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/GitHub"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The original post from my blog is available &lt;a href="https://craftsmandigital.net/blog/hugo-modules/"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Part 1. Prepare a Hugo site to test Hugo modules

&lt;ul&gt;
&lt;li&gt;Install latest version of go on your computer&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Prepare a test site to implement a theme as a Hugo module

&lt;ul&gt;
&lt;li&gt;Part 2. Add a theme as a Hugo module&lt;/li&gt;
&lt;li&gt;For now it has only been bureaucracy. The fun part is starting now:&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Part 3. Add content as a Hugo module

&lt;ul&gt;
&lt;li&gt;Adding content as a module, that is what you really, really, really whant&lt;/li&gt;
&lt;li&gt;Upload your site to GitHub with two modules added.&lt;/li&gt;
&lt;li&gt;Updating modules.&lt;/li&gt;
&lt;li&gt;You can use Hugo modules to mount any kind of resources to your Hugo site.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Part 1. Prepare a Hugo site to test Hugo modules
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Install latest version of go on your computer
&lt;/h3&gt;

&lt;p&gt;Make sure that you have installed a recent version of &lt;strong&gt;go&lt;/strong&gt; on your computer. &lt;a href="https://golang.org/dl/"&gt;Here is the link to the &lt;strong&gt;go&lt;/strong&gt; install&lt;/a&gt;. Follow the instructions carefully. &lt;a href="https://gohugo.io/commands/hugo_mod/"&gt;The &lt;code&gt;hugo mod&lt;/code&gt; commands&lt;/a&gt; do not work without doing this. If you use the &lt;code&gt;hugo mod&lt;/code&gt; commands, without installing &lt;strong&gt;go&lt;/strong&gt;, nothing happens. You don't get an error message as feedback.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prepare a test site to implement a theme as a Hugo module
&lt;/h3&gt;

&lt;p&gt;The theme &lt;strong&gt;&lt;a href="http://github.com/yihui/hugo-xmin"&gt;hugo-xmin&lt;/a&gt;&lt;/strong&gt; are used as an example.&lt;/p&gt;

&lt;p&gt;First you have to prepare a Hugo site to test out the &lt;strong&gt;&lt;a href="http://github.com/yihui/hugo-xmin"&gt;hugo-xmin&lt;/a&gt;&lt;/strong&gt; theme as a &lt;strong&gt;Hugo module&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Download the example site for the &lt;strong&gt;hugo-xmin&lt;/strong&gt; theme:
You can &lt;a href="https://github.com/yihui/hugo-xmin/archive/master.zip"&gt;download the zip file here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/yihui/hugo-xmin/tree/master/exampleSite"&gt;Extract the folder &lt;code&gt;exampleSite&lt;/code&gt;&lt;/a&gt; to your harddrive&lt;/li&gt;
&lt;li&gt;Rename &lt;code&gt;exampleSite&lt;/code&gt; to &lt;code&gt;hugo-test-modules&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Later on, you will add the &lt;strong&gt;hugo-xmin&lt;/strong&gt; theme as a &lt;strong&gt;Hugo module&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 2. Add a theme as a Hugo module
&lt;/h2&gt;

&lt;p&gt;There are different ways to use &lt;strong&gt;Hugo modules&lt;/strong&gt; to add a theme to your Hugo site. This is one of them.&lt;/p&gt;

&lt;p&gt;When you test your site in this stadium. You get an error message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;hugo serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Error: module "hugo-xmin" not found; ...&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;That's because no theme is added to the Hugo site.&lt;/p&gt;

&lt;h3&gt;
  
  
  For now it has only been bureaucracy. The fun part is starting now:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Comment out or delete the variable &lt;code&gt;theme&lt;/code&gt; in &lt;a href="https://github.com/craftsmandigital/hugo-test-modules/blob/master/config.toml"&gt;&lt;code&gt;config.toml&lt;/code&gt; file&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight toml"&gt;&lt;code&gt;   &lt;span class="c"&gt;# theme = "hugo-xmin&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We no longer need this variable since we make use of &lt;strong&gt;Hugo modules&lt;/strong&gt; (It is possible to use the &lt;code&gt;theme&lt;/code&gt; variable to mount modules. For simplicity you use the new preferred method).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add this to your &lt;a href="https://github.com/craftsmandigital/hugo-test-modules/blob/master/config.toml"&gt;&lt;code&gt;config.toml&lt;/code&gt; file&lt;/a&gt; to specify a theme as Hugo module:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight toml"&gt;&lt;code&gt;  &lt;span class="nn"&gt;[module]&lt;/span&gt;
    &lt;span class="nn"&gt;[[module.imports]]&lt;/span&gt;
      &lt;span class="py"&gt;path&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"github.com/yihui/hugo-xmin"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;You don't have to specify the folder to mount to, neither that it is a theme you are mounting. By default &lt;strong&gt;Hugo modules&lt;/strong&gt; behave as it is a theme. Hugo mounts github.com/yihui/hugo-xmin in the Hugo theme folder.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Initialize project as &lt;strong&gt;Hugo module&lt;/strong&gt;. Go to CLI and type in this command in your Hugo site:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;   hugo mod init ugly-dummy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;YES IT WAS &lt;code&gt;ugly-dummy&lt;/code&gt; (It really doesn't mater what the parameter is to the &lt;code&gt;hugo mod init&lt;/code&gt; command, but there are some restrictions on ".", "/", etc.). I think it's more appropriate to name the module as your Hugo site name. In this case hugo-test-modules. but ugly-dummy is also fine.&lt;br&gt;
   The command could output something like this:&lt;br&gt;
   &lt;code&gt;go: creating new go.mod: module ugly-dummy&lt;/code&gt;&lt;br&gt;
   &lt;em&gt;information: a new file&lt;/em&gt; &lt;code&gt;go.mod&lt;/code&gt; &lt;em&gt;was created&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Test your site:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;   hugo serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Your site should look exactly the same as &lt;a href="https://xmin.yihui.name/"&gt;this site&lt;/a&gt;&lt;br&gt;
   &lt;em&gt;information: a new file&lt;/em&gt; &lt;code&gt;go.sum&lt;/code&gt; &lt;em&gt;was created&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now its time to upload your finished site to &lt;strong&gt;GitHub&lt;/strong&gt;. 
&lt;a href="https://github.com/new"&gt;Create a &lt;strong&gt;GitHub&lt;/strong&gt; Repo&lt;/a&gt; and name it &lt;code&gt;hugo-test-modules&lt;/code&gt;
Git commands to upload repo:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;   git init
   git add &lt;span class="nt"&gt;-A&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Initial Commit"&lt;/span&gt;
   git remote add origin https://github.com/&amp;lt; your username &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/hugo-test-modules.git
   git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin master
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;When you now clone your newly updated repo to your machine, there is no need for &lt;code&gt;git clone --recursive&lt;/code&gt;. It's just plug and play. Just do a regular &lt;code&gt;git clone&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;   git clone https://github.com/&amp;lt; your username &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/hugo-test-modules.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;That was all “happy moduling”&lt;/p&gt;
&lt;h2&gt;
  
  
  Part 3. Add content as a Hugo module
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Adding content as a module, that is what you really, really, really whant
&lt;/h3&gt;

&lt;p&gt;Your site is up and running with a &lt;strong&gt;Hugo module&lt;/strong&gt;, the theme &lt;strong&gt;&lt;a href="http://github.com/yihui/hugo-xmin"&gt;hugo-xmin&lt;/a&gt;&lt;/strong&gt; . Now lets add some markdown files to your content. You can mount folders with markdown files from any git repo(It's also possible to mount folders from your hard drive). The repo you mount, don't has to be a Hugo repo. You are going to mount a folder from this &lt;a href="https://github.com/craftsmandigital/markdown-content-repo"&gt;repo&lt;/a&gt;. Check it out and be familiar with it. The repo contains a folder &lt;code&gt;testing-hugo-modules&lt;/code&gt;, that could be mounted. The folder contains two files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;testing-hugo-modules/file-1.md&lt;/li&gt;
&lt;li&gt;testing-hugo-modules/file-2.md&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is the configuration that you could drop in your &lt;a href="https://github.com/craftsmandigital/hugo-test-modules/blob/master/config.toml"&gt;&lt;code&gt;config.toml&lt;/code&gt; file&lt;/a&gt;. Add it just under the theme stuff, under &lt;code&gt;[module]&lt;/code&gt; section:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="nn"&gt;[[module.imports]]&lt;/span&gt;
    &lt;span class="py"&gt;path&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"github.com/craftsmandigital/markdown-content-repo"&lt;/span&gt;
    &lt;span class="py"&gt;disabled&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;

    &lt;span class="nn"&gt;[[module.imports.mounts]]&lt;/span&gt;
    &lt;span class="py"&gt;source&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"testing-hugo-modules"&lt;/span&gt;
    &lt;span class="py"&gt;target&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"content/new-stuff"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;path&lt;/code&gt; describe the repo you mount content from&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;source&lt;/code&gt; describe witch folder(from root) in mounted repo you could append to your Hugo site (&lt;a href="https://github.com/craftsmandigital/markdown-content-repo/tree/master/testing-hugo-modules"&gt;this link brings you inside the actual folder&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;target&lt;/code&gt; describe witch folder(from root) in your Hugo site the mount could appear (&lt;code&gt;content/new-stuff&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After updating &lt;a href="https://github.com/craftsmandigital/hugo-test-modules/blob/master/config.toml"&gt;&lt;code&gt;config.toml&lt;/code&gt; file&lt;/a&gt; there is nothing more to do. It's time to test your site.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;hugo serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now you can see your two new posts at the bottom of the start page (&lt;a href="http://localhost:1313/"&gt;http://localhost:1313/&lt;/a&gt;)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2019/09/12 file 1 for testing Hugo modules for content&lt;/li&gt;
&lt;li&gt;2019/09/12 file 2 for testing Hugo modules for content&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Click on one of the posts. Check out the URL address&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://localhost:1313/new-stuff/file-2/"&gt;http://localhost:1313/new-stuff/file-2/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do you recognize &lt;code&gt;new-stuff&lt;/code&gt; from your &lt;a href="https://github.com/craftsmandigital/hugo-test-modules/blob/master/config.toml"&gt;&lt;code&gt;config.toml&lt;/code&gt; file&lt;/a&gt;. That was your &lt;code&gt;target&lt;/code&gt; for your mounting point(&lt;code&gt;content/new-stuff&lt;/code&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  Upload your site to GitHub with two modules added.
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nt"&gt;-A&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Added Hugo module for content"&lt;/span&gt;
git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin master
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Try to clone your Hugo site:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/&amp;lt; your username &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/hugo-test-modules.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Your site could work right out of the box:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;hugo serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Updating modules.
&lt;/h3&gt;

&lt;p&gt;When your &lt;strong&gt;Hugo&lt;/strong&gt; site is up and running and there has been changes inn the repo's witch your modules are connected to. You have to take action to get these changes in your site. When you do the &lt;strong&gt;hugo mod init&lt;/strong&gt; command, it represent a snapshot in time. Its like &lt;strong&gt;git submodules&lt;/strong&gt;, you have to take action to update. In our example there can bee changes in:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Changes&lt;/th&gt;
&lt;th&gt;Repo&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Hugo Theme&lt;/td&gt;
&lt;td&gt;github.com/yihui/hugo-xmin&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Content&lt;/td&gt;
&lt;td&gt;github.com/craftsmandigital/markdown-content-repo&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The quick and dirty way to get the newest version of all your connected modules is to do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Do this in your site root folder&lt;/span&gt;
&lt;span class="nb"&gt;rm &lt;/span&gt;go.&lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="c"&gt;# Removes the go.mod and go.sum file&lt;/span&gt;
hugo mod init uglydumy &lt;span class="c"&gt;# Init modules to newest version.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In many cases there is not appropriate to download latest version of all modules. For example you don't always want to update to the newest version of your &lt;strong&gt;Hugo&lt;/strong&gt; theme. There is also possible to connect to a specific version of the connected &lt;strong&gt;GitHub&lt;/strong&gt; repo. If you want to do other thing than "quick and dirty" then head over to the &lt;a href="https://gohugo.io/commands/hugo_mod/"&gt;&lt;strong&gt;Hugo&lt;/strong&gt; documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  You can use Hugo modules to mount any kind of resources to your Hugo site.
&lt;/h3&gt;

&lt;p&gt;You can mount &lt;code&gt;layouts&lt;/code&gt; like &lt;code&gt;partials&lt;/code&gt; &lt;code&gt;shortcodes&lt;/code&gt; resources like JS libraries. Etc. Use your Imagination.&lt;/p&gt;

&lt;p&gt;That was all, really really really “happy moduling”&lt;/p&gt;

&lt;p&gt;If you have some comments or criticism please let me know in the comments below.&lt;/p&gt;

&lt;p&gt;An older version of this post is published on the &lt;a href="https://discourse.gohugo.io/t/hugo-modules-for-dummies/20758"&gt;Hugo community&lt;/a&gt;&lt;/p&gt;

</description>
      <category>hugo</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>github</category>
    </item>
  </channel>
</rss>
