Bootstrap A New Hugo Theme From Scratch [video]
Part 2 after Installation. This video covers initiating a new theme and getting hugo to see it in your project.
A part of using Hugo is the freedom of making your own theme. In this tutorial, I will explain how to bootstrap a new Hugo theme so you can customize it exactly how you want to. I will go over verifying installation, creating a theme, telling Hugo how to use your new theme, and we walk through the very basics of setting up a theme so that the home page displays.
Need help installing hugo? I have a How To Install Hugo Tutorial that is a part of this Hugo theme tutorial that can help you get started.
This starts in your favorite terminal prompt.
- Verify your Hugo install with - hugo version
- Verify your working directory with - pwd
- `hugo new site mysite’ 👉 mysite is the name of your project 
- cd mysite
- hugo new theme mytheme👉mytheme can be replaced with the name of your theme
- if you are using VS CODE, then type - code .and your project should open up in VS Code.
- Find your - config.tomlfile. Add an entry- theme = "mytheme"where mytheme is the name of the theme you created at the terminal prompt with .
- At this point we can open a new terminal in the directory and type - hugo server. Nothing will serve at this point.
- Next, I am creating a new file at the base of the content directory called - _index.md. This is a markdown file. Markdown is how you create pages in Hugo. It accepts something called frontmatter.
If you want to learn how to write frontmatter I have a post to get you started. Essentially, markdown is a way to pass data into Hugo’s templates. I will explore this more later on in this mini course. Markdown has very simple content but it can be limited in it’s scope.
- After you create the content file, we need to edit the - index.htmlfile which is located under- themes/mytheme/layouts. This is where you put in your html. Hugo uses to Golang templating syntax. Variables are wrapped in double-curly braces like this:- {{ .Title }}.
- Next, we can include stylesheets into our templates. To do this, we are the static directory inside of the theme. This is probably the easiest way. hugo strips the - /staticprefix so when you include your html you do not need to add- /staticto access the stylesheet.
I highly recommend checking out the following resources to learn more about bootstrapping a Hugo theme.
In the next article, we will start fleshing out our single and list pages and talk about how partials and context work.
This article is part of a series on how to create a Hugo website from scratch. Read the original article here: How To Create A Hugo Website From Scratch: An Overview