4 minutes
Malá kulička
Úvod
pokus
$ ls -l
total 8
drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 archetypes
-rw-r--r-- 1 quoha staff 82 Sep 29 16:49 config.toml
drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 content
drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 layouts
drwxr-xr-x 4 quoha staff 136 Sep 29 17:02 public
drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 static
$
Skins
Skins are the files responsible for the look and feel of your site. It’s the CSS that controls colors and fonts, it’s the Javascript that determines actions and reactions. It’s also the rules that Hugo uses to transform your content into the HTML that the site will serve to visitors.
You have two ways to create a skin. The simplest way is to create it in the layouts/
directory. If you do, then you don’t have to worry about configuring Hugo to recognize it. The first place that Hugo will look for rules and files is in the layouts/
directory so it will always find the skin.
Your second choice is to create it in a sub-directory of the themes/
directory. If you do, then you must always tell Hugo where to search for the skin. It’s extra work, though, so why bother with it?
The difference between creating a skin in layouts/
and creating it in themes/
is very subtle. A skin in layouts/
can’t be customized without updating the templates and static files that it is built from. A skin created in themes/
, on the other hand, can be and that makes it easier for other people to use it.
The rest of this tutorial will call a skin created in the themes/
directory a theme.
Note that you can use this tutorial to create a skin in the layouts/
directory if you wish to. The main difference will be that you won’t need to update the site’s configuration file to use a theme.
The Home Page
The home page, or landing page, is the first page that many visitors to a site see. It is the index.html file in the root directory of the web site. Since Hugo writes files to the public/ directory, our home page is public/index.html.
Front Matter
The front matter is information about the content. Like the configuration file, it can be written in TOML, YAML, or JSON. Unlike the configuration file, Hugo doesn’t use the file’s extension to know the format. It looks for markers to signal the type. TOML is surrounded by “+++
”, YAML by “---
”, and JSON is enclosed in curly braces. I prefer to use TOML, so you’ll need to translate my examples if you prefer YAML or JSON.
The information in the front matter is passed into the template before the content is rendered into HTML.
Markdown
Content is written in Markdown which makes it easier to create the content. Hugo runs the content through a Markdown engine to create the HTML which will be written to the output file.
Template Files
Hugo uses template files to render content into HTML. Template files are a bridge between the content and presentation. Rules in the template define what content is published, where it’s published to, and how it will rendered to the HTML file. The template guides the presentation by specifying the style to use.
There are three types of templates: single, list, and partial. Each type takes a bit of content as input and transforms it based on the commands in the template.
Hugo uses its knowledge of the content to find the template file used to render the content. If it can’t find a template that is an exact match for the content, it will shift up a level and search from there. It will continue to do so until it finds a matching template or runs out of templates to try. If it can’t find a template, it will use the default template for the site.
Please note that you can use the front matter to influence Hugo’s choice of templates.