├── LICENSE.md ├── README.md ├── archetypes └── default.md ├── exampleSite ├── config.toml ├── content │ ├── about.md │ └── post │ │ ├── creating-a-new-theme.md │ │ ├── goisforlovers.md │ │ ├── hugoisforlovers.md │ │ ├── math-example.md │ │ └── migrate-from-jekyll.md └── static │ └── .gitkeep ├── gulpfile.js ├── images ├── screenshot.png ├── screenshot_github.png └── tn.png ├── layouts ├── 404.html ├── _default │ ├── list.html │ └── single.html ├── index.html └── partials │ ├── disqus.html │ ├── footer.html │ ├── header.html │ ├── nav.html │ ├── pager.html │ ├── sharing.html │ └── tags.html ├── package.json ├── sass └── style.sass ├── static ├── css │ └── style.css └── wave.ico └── theme.toml /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Morten G. Johansen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hucore 2 | 3 | Hucore is a minimal blog theme for [hugo](https://gohugo.io). The theme is based on [Hemingway2](https://gitlab.com/beli3ver/hemingway2). 4 | 5 | ## Features 6 | 7 | * Responsive & minimal design 8 | * Disqus support 9 | * Google Analytics 10 | * Basic [OpenGraph](http://ogp.me/) metadata support 11 | * Option for social sharing icons on posts 12 | * Option for author on posts 13 | 14 | ## Screenshot 15 | 16 |  17 | 18 | See [technet.cc](https://technet.cc) for an example of this theme in use. 19 | 20 | ## Getting Started 21 | 22 | Clone this repository to your hugo theme directory. 23 | 24 | ``` 25 | mkdir themes 26 | cd themes 27 | git clone https://github.com/mgjohansen/hucore.git 28 | ``` 29 | 30 | ## Configuration 31 | 32 | Take a look in the [exampleSite](https://github.com/mgjohansen/hucore/tree/master/exampleSite) folder. 33 | 34 | This directory contains an example config file and the content for the demo. 35 | It serves as an example setup for your documentation. 36 | 37 | Copy the `config.toml` in the root directory of your website. Overwrite the existing config file if necessary. 38 | 39 | __[config.toml](https://github.com/mgjohansen/hucore/blob/master/exampleSite/config.toml)__: 40 | 41 | ```toml 42 | baseurl = "https://example.com" 43 | languageCode = "en-US" 44 | title = "[Hu]Core" 45 | theme = "Hucore" 46 | copyright = "© 2017 | Follow on Twitter | [Hu]Core theme & Hugo ♥" 47 | disqusShortname = "shortname" 48 | googleAnalytics = "trackingcode" 49 | 50 | [taxonomies] 51 | tag = "tags" 52 | category = "categories" 53 | 54 | [params] 55 | description = "Your description here" 56 | keywords = ["keyword 1", "keyword 2", "keyword 3"] 57 | author = "Morten Johansen" 58 | sharingicons = true 59 | displayauthor = true 60 | 61 | [params.highlight] 62 | style = "github" 63 | languages = ["go", "dockerfile"] 64 | 65 | [[params.social]] 66 | url = "https://github.com/mgjohansen" 67 | fa_icon = "fa-github" 68 | 69 | [[params.social]] 70 | url = "https://gitlab.com/mgjohansen" 71 | fa_icon = "fa-gitlab" 72 | 73 | [[params.social]] 74 | url = "https://twitter.com/mgjohansen" 75 | fa_icon = "fa-twitter" 76 | 77 | [[params.social]] 78 | url = "https://linkedin.com/in/mgjohansen" 79 | fa_icon = "fa-linkedin-square" 80 | 81 | [[params.social]] 82 | url = "/index.xml" 83 | fa_icon = "fa-rss" 84 | 85 | [[params.socialshare]] 86 | url = "https://linkedin.com/in/mgjohansen" 87 | fa_icon = "fa-linkedin-square" 88 | ``` 89 | 90 | ## Build 91 | 92 | ``` 93 | hugo server 94 | ``` 95 | 96 | You can go to localhost:1313 and this theme should be visible. 97 | 98 | ## License 99 | 100 | Hucore is licensed under the [MIT License](LICENSE.md). 101 | 102 | ## Author 103 | 104 | [Morten Johansen](https://github.com/mgjohansen) 105 | 106 | ## Credits 107 | 108 | Hucore is based on [Hemingway2](https://gitlab.com/beli3ver/hemingway2) created by [Malte Kiefer](https://github.com/beli3ver). 109 | -------------------------------------------------------------------------------- /archetypes/default.md: -------------------------------------------------------------------------------- 1 | +++ 2 | title = "{{ replace .TranslationBaseName "-" " " | title }}" 3 | tags = [ ] 4 | draft = true 5 | date = {{ .Date }} 6 | author = "" 7 | +++ 8 | -------------------------------------------------------------------------------- /exampleSite/config.toml: -------------------------------------------------------------------------------- 1 | baseurl = "https://example.com" 2 | languageCode = "en-US" 3 | title = "[Hu]Core" 4 | theme = "Hucore" 5 | copyright = "© 2017 | Follow on Twitter | [Hu]Core theme & Hugo ♥" 6 | disqusShortname = "shortname" 7 | googleAnalytics = "trackingcode" 8 | 9 | [taxonomies] 10 | tag = "tags" 11 | category = "categories" 12 | 13 | [params] 14 | description = "Your description here" 15 | keywords = ["keyword 1", "keyword 2", "keyword 3"] 16 | author = "Morten Johansen" 17 | sharingicons = true 18 | displayauthor = true 19 | 20 | [params.highlight] 21 | style = "github" 22 | languages = ["go", "dockerfile"] 23 | 24 | [[params.social]] 25 | url = "https://github.com/mgjohansen" 26 | fa_icon = "fa-github" 27 | 28 | [[params.social]] 29 | url = "https://gitlab.com/mgjohansen" 30 | fa_icon = "fa-gitlab" 31 | 32 | [[params.social]] 33 | url = "https://twitter.com/mgjohansen" 34 | fa_icon = "fa-twitter" 35 | 36 | [[params.social]] 37 | url = "https://linkedin.com/in/mgjohansen" 38 | fa_icon = "fa-linkedin-square" 39 | 40 | [[params.social]] 41 | url = "/index.xml" 42 | fa_icon = "fa-rss" 43 | 44 | [[params.socialshare]] 45 | url = "https://linkedin.com/in/mgjohansen" 46 | fa_icon = "fa-linkedin-square" -------------------------------------------------------------------------------- /exampleSite/content/about.md: -------------------------------------------------------------------------------- 1 | +++ 2 | title = "About Hugo" 3 | date = "2014-04-09" 4 | menu = "main" 5 | +++ 6 | 7 | Hugo is a static site engine written in Go. 8 | 9 | 10 | It makes use of a variety of open source projects including: 11 | 12 | * [Cobra](https://github.com/spf13/cobra) 13 | * [Viper](https://github.com/spf13/viper) 14 | * [J Walter Weatherman](https://github.com/spf13/jWalterWeatherman) 15 | * [Cast](https://github.com/spf13/cast) 16 | 17 | Learn more and contribute on [GitHub](https://github.com/spf13). 18 | 19 | ## Setup 20 | 21 | Some fun facts about [Hugo](http://gohugo.io/): 22 | 23 | * Built in [Go](http://golang.org/) 24 | * Loosely inspired by [Jekyll](http://jekyllrb.com/) 25 | * Primarily developed by [spf13](http://spf13.com/) on the train while commuting to and from Manhattan. 26 | * Coded in [Vim](http://vim.org) using [spf13-vim](http://vim.spf13.com/) 27 | 28 | Have questions or suggestions? Feel free to [open an issue on GitHub](https://github.com/spf13/hugo/issues/new) or [ask me on Twitter](https://twitter.com/spf13). 29 | 30 | Thanks for reading! 31 | -------------------------------------------------------------------------------- /exampleSite/content/post/creating-a-new-theme.md: -------------------------------------------------------------------------------- 1 | --- 2 | author: "Michael Henderson" 3 | date: 2014-09-28 4 | linktitle: Creating a New Theme 5 | menu: 6 | main: 7 | parent: tutorials 8 | next: /tutorials/github-pages-blog 9 | prev: /tutorials/automated-deployments 10 | title: Creating a New Theme 11 | weight: 10 12 | --- 13 | 14 | 15 | ## Introduction 16 | 17 | This tutorial will show you how to create a simple theme in Hugo. I assume that you are familiar with HTML, the bash command line, and that you are comfortable using Markdown to format content. I'll explain how Hugo uses templates and how you can organize your templates to create a theme. I won't cover using CSS to style your theme. 18 | 19 | We'll start with creating a new site with a very basic template. Then we'll add in a few pages and posts. With small variations on that, you will be able to create many different types of web sites. 20 | 21 | In this tutorial, commands that you enter will start with the "$" prompt. The output will follow. Lines that start with "#" are comments that I've added to explain a point. When I show updates to a file, the ":wq" on the last line means to save the file. 22 | 23 | Here's an example: 24 | 25 | ``` 26 | ## this is a comment 27 | $ echo this is a command 28 | this is a command 29 | 30 | ## edit the file 31 | $vi foo.md 32 | +++ 33 | date = "2014-09-28" 34 | title = "creating a new theme" 35 | +++ 36 | 37 | bah and humbug 38 | :wq 39 | 40 | ## show it 41 | $ cat foo.md 42 | +++ 43 | date = "2014-09-28" 44 | title = "creating a new theme" 45 | +++ 46 | 47 | bah and humbug 48 | $ 49 | ``` 50 | 51 | 52 | ## Some Definitions 53 | 54 | There are a few concepts that you need to understand before creating a theme. 55 | 56 | ### Skins 57 | 58 | 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. 59 | 60 | 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. 61 | 62 | 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? 63 | 64 | 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. 65 | 66 | The rest of this tutorial will call a skin created in the ```themes/``` directory a theme. 67 | 68 | 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. 69 | 70 | ### The Home Page 71 | 72 | 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. 73 | 74 | ### Site Configuration File 75 | 76 | When Hugo runs, it looks for a configuration file that contains settings that override default values for the entire site. The file can use TOML, YAML, or JSON. I prefer to use TOML for my configuration files. If you prefer to use JSON or YAML, you’ll need to translate my examples. You’ll also need to change the name of the file since Hugo uses the extension to determine how to process it. 77 | 78 | Hugo translates Markdown files into HTML. By default, Hugo expects to find Markdown files in your ```content/``` directory and template files in your ```themes/``` directory. It will create HTML files in your ```public/``` directory. You can change this by specifying alternate locations in the configuration file. 79 | 80 | ### Content 81 | 82 | Content is stored in text files that contain two sections. The first section is the “front matter,” which is the meta-information on the content. The second section contains Markdown that will be converted to HTML. 83 | 84 | #### Front Matter 85 | 86 | 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. 87 | 88 | The information in the front matter is passed into the template before the content is rendered into HTML. 89 | 90 | #### Markdown 91 | 92 | 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. 93 | 94 | ### Template Files 95 | 96 | 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. 97 | 98 | 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. 99 | 100 | 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. 101 | 102 | Please note that you can use the front matter to influence Hugo’s choice of templates. 103 | 104 | #### Single Template 105 | 106 | A single template is used to render a single piece of content. For example, an article or post would be a single piece of content and use a single template. 107 | 108 | #### List Template 109 | 110 | A list template renders a group of related content. That could be a summary of recent postings or all articles in a category. List templates can contain multiple groups. 111 | 112 | The homepage template is a special type of list template. Hugo assumes that the home page of your site will act as the portal for the rest of the content in the site. 113 | 114 | #### Partial Template 115 | 116 | A partial template is a template that can be included in other templates. Partial templates must be called using the “partial” template command. They are very handy for rolling up common behavior. For example, your site may have a banner that all pages use. Instead of copying the text of the banner into every single and list template, you could create a partial with the banner in it. That way if you decide to change the banner, you only have to change the partial template. 117 | 118 | ## Create a New Site 119 | 120 | Let's use Hugo to create a new web site. I'm a Mac user, so I'll create mine in my home directory, in the Sites folder. If you're using Linux, you might have to create the folder first. 121 | 122 | The "new site" command will create a skeleton of a site. It will give you the basic directory structure and a useable configuration file. 123 | 124 | ``` 125 | $ hugo new site ~/Sites/zafta 126 | $ cd ~/Sites/zafta 127 | $ ls -l 128 | total 8 129 | drwxr-xr-x 7 quoha staff 238 Sep 29 16:49 . 130 | drwxr-xr-x 3 quoha staff 102 Sep 29 16:49 .. 131 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 archetypes 132 | -rw-r--r-- 1 quoha staff 82 Sep 29 16:49 config.toml 133 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 content 134 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 layouts 135 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 static 136 | $ 137 | ``` 138 | 139 | Take a look in the content/ directory to confirm that it is empty. 140 | 141 | The other directories (archetypes/, layouts/, and static/) are used when customizing a theme. That's a topic for a different tutorial, so please ignore them for now. 142 | 143 | ### Generate the HTML For the New Site 144 | 145 | Running the `hugo` command with no options will read all the available content and generate the HTML files. It will also copy all static files (that's everything that's not content). Since we have an empty site, it won't do much, but it will do it very quickly. 146 | 147 | ``` 148 | $ hugo --verbose 149 | INFO: 2014/09/29 Using config file: config.toml 150 | INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/ 151 | WARN: 2014/09/29 Unable to locate layout: [index.html _default/list.html _default/single.html] 152 | WARN: 2014/09/29 Unable to locate layout: [404.html] 153 | 0 draft content 154 | 0 future content 155 | 0 pages created 156 | 0 tags created 157 | 0 categories created 158 | in 2 ms 159 | $ 160 | ``` 161 | 162 | The "`--verbose`" flag gives extra information that will be helpful when we build the template. Every line of the output that starts with "INFO:" or "WARN:" is present because we used that flag. The lines that start with "WARN:" are warning messages. We'll go over them later. 163 | 164 | We can verify that the command worked by looking at the directory again. 165 | 166 | ``` 167 | $ ls -l 168 | total 8 169 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 archetypes 170 | -rw-r--r-- 1 quoha staff 82 Sep 29 16:49 config.toml 171 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 content 172 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 layouts 173 | drwxr-xr-x 4 quoha staff 136 Sep 29 17:02 public 174 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 static 175 | $ 176 | ``` 177 | 178 | See that new public/ directory? Hugo placed all generated content there. When you're ready to publish your web site, that's the place to start. For now, though, let's just confirm that we have what we'd expect from a site with no content. 179 | 180 | ``` 181 | $ ls -l public 182 | total 16 183 | -rw-r--r-- 1 quoha staff 416 Sep 29 17:02 index.xml 184 | -rw-r--r-- 1 quoha staff 262 Sep 29 17:02 sitemap.xml 185 | $ 186 | ``` 187 | 188 | Hugo created two XML files, which is standard, but there are no HTML files. 189 | 190 | 191 | 192 | ### Test the New Site 193 | 194 | Verify that you can run the built-in web server. It will dramatically shorten your development cycle if you do. Start it by running the "server" command. If it is successful, you will see output similar to the following: 195 | 196 | ``` 197 | $ hugo server --verbose 198 | INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/config.toml 199 | INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/ 200 | WARN: 2014/09/29 Unable to locate layout: [index.html _default/list.html _default/single.html] 201 | WARN: 2014/09/29 Unable to locate layout: [404.html] 202 | 0 draft content 203 | 0 future content 204 | 0 pages created 205 | 0 tags created 206 | 0 categories created 207 | in 2 ms 208 | Serving pages from /Users/quoha/Sites/zafta/public 209 | Web Server is available at http://localhost:1313 210 | Press Ctrl+C to stop 211 | ``` 212 | 213 | Connect to the listed URL (it's on the line that starts with "Web Server"). If everything is working correctly, you should get a page that shows the following: 214 | 215 | ``` 216 | index.xml 217 | sitemap.xml 218 | ``` 219 | 220 | That's a listing of your public/ directory. Hugo didn't create a home page because our site has no content. When there's no index.html file in a directory, the server lists the files in the directory, which is what you should see in your browser. 221 | 222 | Let’s go back and look at those warnings again. 223 | 224 | ``` 225 | WARN: 2014/09/29 Unable to locate layout: [index.html _default/list.html _default/single.html] 226 | WARN: 2014/09/29 Unable to locate layout: [404.html] 227 | ``` 228 | 229 | That second warning is easier to explain. We haven’t created a template to be used to generate “page not found errors.” The 404 message is a topic for a separate tutorial. 230 | 231 | Now for the first warning. It is for the home page. You can tell because the first layout that it looked for was “index.html.” That’s only used by the home page. 232 | 233 | I like that the verbose flag causes Hugo to list the files that it's searching for. For the home page, they are index.html, _default/list.html, and _default/single.html. There are some rules that we'll cover later that explain the names and paths. For now, just remember that Hugo couldn't find a template for the home page and it told you so. 234 | 235 | At this point, you've got a working installation and site that we can build upon. All that’s left is to add some content and a theme to display it. 236 | 237 | ## Create a New Theme 238 | 239 | Hugo doesn't ship with a default theme. There are a few available (I counted a dozen when I first installed Hugo) and Hugo comes with a command to create new themes. 240 | 241 | We're going to create a new theme called "zafta." Since the goal of this tutorial is to show you how to fill out the files to pull in your content, the theme will not contain any CSS. In other words, ugly but functional. 242 | 243 | All themes have opinions on content and layout. For example, Zafta uses "post" over "blog". Strong opinions make for simpler templates but differing opinions make it tougher to use themes. When you build a theme, consider using the terms that other themes do. 244 | 245 | 246 | ### Create a Skeleton 247 | 248 | Use the hugo "new" command to create the skeleton of a theme. This creates the directory structure and places empty files for you to fill out. 249 | 250 | ``` 251 | $ hugo new theme zafta 252 | 253 | $ ls -l 254 | total 8 255 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 archetypes 256 | -rw-r--r-- 1 quoha staff 82 Sep 29 16:49 config.toml 257 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 content 258 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 layouts 259 | drwxr-xr-x 4 quoha staff 136 Sep 29 17:02 public 260 | drwxr-xr-x 2 quoha staff 68 Sep 29 16:49 static 261 | drwxr-xr-x 3 quoha staff 102 Sep 29 17:31 themes 262 | 263 | $ find themes -type f | xargs ls -l 264 | -rw-r--r-- 1 quoha staff 1081 Sep 29 17:31 themes/zafta/LICENSE.md 265 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/archetypes/default.md 266 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/_default/list.html 267 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/_default/single.html 268 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/index.html 269 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/partials/footer.html 270 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/partials/header.html 271 | -rw-r--r-- 1 quoha staff 93 Sep 29 17:31 themes/zafta/theme.toml 272 | $ 273 | ``` 274 | 275 | The skeleton includes templates (the files ending in .html), license file, a description of your theme (the theme.toml file), and an empty archetype. 276 | 277 | Please take a minute to fill out the theme.toml and LICENSE.md files. They're optional, but if you're going to be distributing your theme, it tells the world who to praise (or blame). It's also nice to declare the license so that people will know how they can use the theme. 278 | 279 | ``` 280 | $ vi themes/zafta/theme.toml 281 | author = "michael d henderson" 282 | description = "a minimal working template" 283 | license = "MIT" 284 | name = "zafta" 285 | source_repo = "" 286 | tags = ["tags", "categories"] 287 | :wq 288 | 289 | ## also edit themes/zafta/LICENSE.md and change 290 | ## the bit that says "YOUR_NAME_HERE" 291 | ``` 292 | 293 | Note that the the skeleton's template files are empty. Don't worry, we'll be changing that shortly. 294 | 295 | ``` 296 | $ find themes/zafta -name '*.html' | xargs ls -l 297 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/_default/list.html 298 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/_default/single.html 299 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/index.html 300 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/partials/footer.html 301 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 themes/zafta/layouts/partials/header.html 302 | $ 303 | ``` 304 | 305 | 306 | 307 | ### Update the Configuration File to Use the Theme 308 | 309 | Now that we've got a theme to work with, it's a good idea to add the theme name to the configuration file. This is optional, because you can always add "-t zafta" on all your commands. I like to put it the configuration file because I like shorter command lines. If you don't put it in the configuration file or specify it on the command line, you won't use the template that you're expecting to. 310 | 311 | Edit the file to add the theme, add a title for the site, and specify that all of our content will use the TOML format. 312 | 313 | ``` 314 | $ vi config.toml 315 | theme = "zafta" 316 | baseurl = "" 317 | languageCode = "en-us" 318 | title = "zafta - totally refreshing" 319 | MetaDataFormat = "toml" 320 | :wq 321 | 322 | $ 323 | ``` 324 | 325 | ### Generate the Site 326 | 327 | Now that we have an empty theme, let's generate the site again. 328 | 329 | ``` 330 | $ hugo --verbose 331 | INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/config.toml 332 | INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/themes/zafta/static/ to /Users/quoha/Sites/zafta/public/ 333 | INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/ 334 | WARN: 2014/09/29 Unable to locate layout: [404.html theme/404.html] 335 | 0 draft content 336 | 0 future content 337 | 0 pages created 338 | 0 tags created 339 | 0 categories created 340 | in 2 ms 341 | $ 342 | ``` 343 | 344 | Did you notice that the output is different? The warning message for the home page has disappeared and we have an additional information line saying that Hugo is syncing from the theme's directory. 345 | 346 | Let's check the public/ directory to see what Hugo's created. 347 | 348 | ``` 349 | $ ls -l public 350 | total 16 351 | drwxr-xr-x 2 quoha staff 68 Sep 29 17:56 css 352 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:56 index.html 353 | -rw-r--r-- 1 quoha staff 407 Sep 29 17:56 index.xml 354 | drwxr-xr-x 2 quoha staff 68 Sep 29 17:56 js 355 | -rw-r--r-- 1 quoha staff 243 Sep 29 17:56 sitemap.xml 356 | $ 357 | ``` 358 | 359 | Notice four things: 360 | 361 | 1. Hugo created a home page. This is the file public/index.html. 362 | 2. Hugo created a css/ directory. 363 | 3. Hugo created a js/ directory. 364 | 4. Hugo claimed that it created 0 pages. It created a file and copied over static files, but didn't create any pages. That's because it considers a "page" to be a file created directly from a content file. It doesn't count things like the index.html files that it creates automatically. 365 | 366 | #### The Home Page 367 | 368 | Hugo supports many different types of templates. The home page is special because it gets its own type of template and its own template file. The file, layouts/index.html, is used to generate the HTML for the home page. The Hugo documentation says that this is the only required template, but that depends. Hugo's warning message shows that it looks for three different templates: 369 | 370 | ``` 371 | WARN: 2014/09/29 Unable to locate layout: [index.html _default/list.html _default/single.html] 372 | ``` 373 | 374 | If it can't find any of these, it completely skips creating the home page. We noticed that when we built the site without having a theme installed. 375 | 376 | When Hugo created our theme, it created an empty home page template. Now, when we build the site, Hugo finds the template and uses it to generate the HTML for the home page. Since the template file is empty, the HTML file is empty, too. If the template had any rules in it, then Hugo would have used them to generate the home page. 377 | 378 | ``` 379 | $ find . -name index.html | xargs ls -l 380 | -rw-r--r-- 1 quoha staff 0 Sep 29 20:21 ./public/index.html 381 | -rw-r--r-- 1 quoha staff 0 Sep 29 17:31 ./themes/zafta/layouts/index.html 382 | $ 383 | ``` 384 | 385 | #### The Magic of Static 386 | 387 | Hugo does two things when generating the site. It uses templates to transform content into HTML and it copies static files into the site. Unlike content, static files are not transformed. They are copied exactly as they are. 388 | 389 | Hugo assumes that your site will use both CSS and JavaScript, so it creates directories in your theme to hold them. Remember opinions? Well, Hugo's opinion is that you'll store your CSS in a directory named css/ and your JavaScript in a directory named js/. If you don't like that, you can change the directory names in your theme directory or even delete them completely. Hugo's nice enough to offer its opinion, then behave nicely if you disagree. 390 | 391 | ``` 392 | $ find themes/zafta -type d | xargs ls -ld 393 | drwxr-xr-x 7 quoha staff 238 Sep 29 17:38 themes/zafta 394 | drwxr-xr-x 3 quoha staff 102 Sep 29 17:31 themes/zafta/archetypes 395 | drwxr-xr-x 5 quoha staff 170 Sep 29 17:31 themes/zafta/layouts 396 | drwxr-xr-x 4 quoha staff 136 Sep 29 17:31 themes/zafta/layouts/_default 397 | drwxr-xr-x 4 quoha staff 136 Sep 29 17:31 themes/zafta/layouts/partials 398 | drwxr-xr-x 4 quoha staff 136 Sep 29 17:31 themes/zafta/static 399 | drwxr-xr-x 2 quoha staff 68 Sep 29 17:31 themes/zafta/static/css 400 | drwxr-xr-x 2 quoha staff 68 Sep 29 17:31 themes/zafta/static/js 401 | $ 402 | ``` 403 | 404 | ## The Theme Development Cycle 405 | 406 | When you're working on a theme, you will make changes in the theme's directory, rebuild the site, and check your changes in the browser. Hugo makes this very easy: 407 | 408 | 1. Purge the public/ directory. 409 | 2. Run the built in web server in watch mode. 410 | 3. Open your site in a browser. 411 | 4. Update the theme. 412 | 5. Glance at your browser window to see changes. 413 | 6. Return to step 4. 414 | 415 | I’ll throw in one more opinion: never work on a theme on a live site. Always work on a copy of your site. Make changes to your theme, test them, then copy them up to your site. For added safety, use a tool like Git to keep a revision history of your content and your theme. Believe me when I say that it is too easy to lose both your mind and your changes. 416 | 417 | Check the main Hugo site for information on using Git with Hugo. 418 | 419 | ### Purge the public/ Directory 420 | 421 | When generating the site, Hugo will create new files and update existing ones in the ```public/``` directory. It will not delete files that are no longer used. For example, files that were created in the wrong directory or with the wrong title will remain. If you leave them, you might get confused by them later. I recommend cleaning out your site prior to generating it. 422 | 423 | Note: If you're building on an SSD, you should ignore this. Churning on a SSD can be costly. 424 | 425 | ### Hugo's Watch Option 426 | 427 | Hugo's "`--watch`" option will monitor the content/ and your theme directories for changes and rebuild the site automatically. 428 | 429 | ### Live Reload 430 | 431 | Hugo's built in web server supports live reload. As pages are saved on the server, the browser is told to refresh the page. Usually, this happens faster than you can say, "Wow, that's totally amazing." 432 | 433 | ### Development Commands 434 | 435 | Use the following commands as the basis for your workflow. 436 | 437 | ``` 438 | ## purge old files. hugo will recreate the public directory. 439 | ## 440 | $ rm -rf public 441 | ## 442 | ## run hugo in watch mode 443 | ## 444 | $ hugo server --watch --verbose 445 | ``` 446 | 447 | Here's sample output showing Hugo detecting a change to the template for the home page. Once generated, the web browser automatically reloaded the page. I've said this before, it's amazing. 448 | 449 | 450 | ``` 451 | $ rm -rf public 452 | $ hugo server --watch --verbose 453 | INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/config.toml 454 | INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/themes/zafta/static/ to /Users/quoha/Sites/zafta/public/ 455 | INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/ 456 | WARN: 2014/09/29 Unable to locate layout: [404.html theme/404.html] 457 | 0 draft content 458 | 0 future content 459 | 0 pages created 460 | 0 tags created 461 | 0 categories created 462 | in 2 ms 463 | Watching for changes in /Users/quoha/Sites/zafta/content 464 | Serving pages from /Users/quoha/Sites/zafta/public 465 | Web Server is available at http://localhost:1313 466 | Press Ctrl+C to stop 467 | INFO: 2014/09/29 File System Event: ["/Users/quoha/Sites/zafta/themes/zafta/layouts/index.html": MODIFY|ATTRIB] 468 | Change detected, rebuilding site 469 | 470 | WARN: 2014/09/29 Unable to locate layout: [404.html theme/404.html] 471 | 0 draft content 472 | 0 future content 473 | 0 pages created 474 | 0 tags created 475 | 0 categories created 476 | in 1 ms 477 | ``` 478 | 479 | ## Update the Home Page Template 480 | 481 | The home page is one of a few special pages that Hugo creates automatically. As mentioned earlier, it looks for one of three files in the theme's layout/ directory: 482 | 483 | 1. index.html 484 | 2. _default/list.html 485 | 3. _default/single.html 486 | 487 | We could update one of the default templates, but a good design decision is to update the most specific template available. That's not a hard and fast rule (in fact, we'll break it a few times in this tutorial), but it is a good generalization. 488 | 489 | ### Make a Static Home Page 490 | 491 | Right now, that page is empty because we don't have any content and we don't have any logic in the template. Let's change that by adding some text to the template. 492 | 493 | ``` 494 | $ vi themes/zafta/layouts/index.html 495 | 496 | 497 |
498 |hugo says hello!
499 | 500 | 501 | :wq 502 | 503 | $ 504 | ``` 505 | 506 | Build the web site and then verify the results. 507 | 508 | ``` 509 | $ hugo --verbose 510 | INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/config.toml 511 | INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/themes/zafta/static/ to /Users/quoha/Sites/zafta/public/ 512 | INFO: 2014/09/29 syncing from /Users/quoha/Sites/zafta/static/ to /Users/quoha/Sites/zafta/public/ 513 | WARN: 2014/09/29 Unable to locate layout: [404.html theme/404.html] 514 | 0 draft content 515 | 0 future content 516 | 0 pages created 517 | 0 tags created 518 | 0 categories created 519 | in 2 ms 520 | 521 | $ find public -type f -name '*.html' | xargs ls -l 522 | -rw-r--r-- 1 quoha staff 78 Sep 29 21:26 public/index.html 523 | 524 | $ cat public/index.html 525 | 526 | 527 | 528 |hugo says hello!
529 | 530 | ``` 531 | 532 | #### Live Reload 533 | 534 | Note: If you're running the server with the `--watch` option, you'll see different content in the file: 535 | 536 | ``` 537 | $ cat public/index.html 538 | 539 | 540 | 541 |hugo says hello!
542 | 546 | 547 | ``` 548 | 549 | When you use `--watch`, the Live Reload script is added by Hugo. Look for live reload in the documentation to see what it does and how to disable it. 550 | 551 | ### Build a "Dynamic" Home Page 552 | 553 | "Dynamic home page?" Hugo's a static web site generator, so this seems an odd thing to say. I mean let's have the home page automatically reflect the content in the site every time Hugo builds it. We'll use iteration in the template to do that. 554 | 555 | #### Create New Posts 556 | 557 | Now that we have the home page generating static content, let's add some content to the site. We'll display these posts as a list on the home page and on their own page, too. 558 | 559 | Hugo has a command to generate a skeleton post, just like it does for sites and themes. 560 | 561 | ``` 562 | $ hugo --verbose new post/first.md 563 | INFO: 2014/09/29 Using config file: /Users/quoha/Sites/zafta/config.toml 564 | INFO: 2014/09/29 attempting to create post/first.md of post 565 | INFO: 2014/09/29 curpath: /Users/quoha/Sites/zafta/themes/zafta/archetypes/default.md 566 | ERROR: 2014/09/29 Unable to Castmy first post
814 | 815 | 816 | 817 | 818 | $ cat public/post/second/index.html 819 | 820 | 821 | 822 |my second post
827 | 828 | 829 | 830 | $ 831 | ``` 832 | 833 | Notice that the posts now have content. You can go to localhost:1313/post/first to verify. 834 | 835 | ### Linking to Content 836 | 837 | The posts are on the home page. Let's add a link from there to the post. Since this is the home page, we'll update its template. 838 | 839 | ``` 840 | $ vi themes/zafta/layouts/index.html 841 | 842 | 843 | 844 | {{ range first 10 .Data.Pages }} 845 |