├── exampleSite ├── content │ ├── contact.md │ ├── _index.md │ ├── about.md │ └── posts │ │ ├── 2015-01-04-first-post.md │ │ ├── hugoisforlovers.md │ │ ├── migrate-from-jekyll.md │ │ ├── goisforlovers.md │ │ └── creating-a-new-theme.md └── config.toml ├── images ├── tn.png ├── screenshot.png └── screenshot2.png ├── .gitignore ├── layouts ├── 404.html ├── _default │ ├── single.html │ ├── baseof.html │ └── list.html ├── partials │ ├── head_custom.html │ ├── single.html │ ├── header.html │ ├── footer.html │ ├── head.html │ └── post_meta.html └── index.html ├── resources └── _gen │ └── assets │ └── css │ └── css │ ├── style.css_d3f53f09220d597dac26fe7840c31fc9.json │ └── style.css_d3f53f09220d597dac26fe7840c31fc9.content ├── theme.toml ├── README.md ├── assets └── css │ └── style.css └── LICENSE.md /exampleSite/content/contact.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Contact" 3 | --- 4 | 5 | Contact me! -------------------------------------------------------------------------------- /images/tn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/simple-hugo-theme/master/images/tn.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /public 2 | exampleSite/themes 3 | exampleSite/public 4 | exampleSite/resources -------------------------------------------------------------------------------- /layouts/404.html: -------------------------------------------------------------------------------- 1 | {{ define "main"}} 2 | 3 |

404 Page not found

4 | 5 | {{ end }} -------------------------------------------------------------------------------- /images/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/simple-hugo-theme/master/images/screenshot.png -------------------------------------------------------------------------------- /layouts/_default/single.html: -------------------------------------------------------------------------------- 1 | {{ define "main" }} 2 | 3 | {{ partial "single" . }} 4 | 5 | {{ end }} -------------------------------------------------------------------------------- /images/screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xzya/simple-hugo-theme/master/images/screenshot2.png -------------------------------------------------------------------------------- /resources/_gen/assets/css/css/style.css_d3f53f09220d597dac26fe7840c31fc9.json: -------------------------------------------------------------------------------- 1 | {"Target":"css/style.min.css","MediaType":"text/css","Data":{}} -------------------------------------------------------------------------------- /layouts/partials/head_custom.html: -------------------------------------------------------------------------------- 1 | {{/* Create /layouts/partials/head-custom.html to overwrite this empty template and put custom code into the section. */}} -------------------------------------------------------------------------------- /layouts/partials/single.html: -------------------------------------------------------------------------------- 1 |
2 |

3 | {{- .Title | markdownify -}} 4 |

5 | {{ partial "post_meta.html" . }} 6 |
7 |
8 | {{ .Content }} 9 |
-------------------------------------------------------------------------------- /layouts/index.html: -------------------------------------------------------------------------------- 1 | {{ define "main" }} 2 | 3 |
4 |

5 | {{- .Title | markdownify -}} 6 |

7 |
8 |
9 | {{ .Content }} 10 |
11 | 12 | {{ end }} -------------------------------------------------------------------------------- /exampleSite/content/_index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Simple Hugo Theme 3 | --- 4 | 5 | This is a very simple and lightweight Hugo Theme inspired by the geniuses behind [bettermotherfuckingwebsite.com](http://bettermotherfuckingwebsite.com/). 6 | -------------------------------------------------------------------------------- /layouts/_default/baseof.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | {{ partial "head.html" . }} 4 | 5 | 6 | {{- partial "header.html" . -}} 7 |
8 | {{- block "main" . }}{{- end }} 9 |
10 | {{- partial "footer.html" . -}} 11 | 12 | 13 | -------------------------------------------------------------------------------- /resources/_gen/assets/css/css/style.css_d3f53f09220d597dac26fe7840c31fc9.content: -------------------------------------------------------------------------------- 1 | body{margin:40px auto;max-width:650px;line-height:1.6;font-size:18px;color:#444;padding:0 10px}h1,h2,h3{line-height:1.2}div.header h1{padding-top:0;padding-bottom:8px;margin-bottom:24px;font-size:18px;font-weight:400;border-bottom:1px solid}.header-menu{float:right}ul.pagination{list-style-type:none;text-align:center;padding:0}ul.pagination>li{padding:0 8px;display:inline-block}div.footer{border-top:1px solid;text-align:center} -------------------------------------------------------------------------------- /exampleSite/content/about.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "About Hugo" 3 | --- 4 | 5 | Hugo is the **world’s fastest framework for building websites**. It is written in Go. 6 | 7 | It makes use of a variety of open source projects including: 8 | 9 | * https://github.com/russross/blackfriday 10 | * https://github.com/alecthomas/chroma 11 | * https://github.com/muesli/smartcrop 12 | * https://github.com/spf13/cobra 13 | * https://github.com/spf13/viper 14 | 15 | Learn more and contribute on [GitHub](https://github.com/gohugoio). 16 | -------------------------------------------------------------------------------- /layouts/_default/list.html: -------------------------------------------------------------------------------- 1 | {{ define "main" }} 2 | 3 | {{/* Display _index.md if available */}} 4 | {{ if .Content }} 5 | {{ partial "single" . }} 6 | {{ end }} 7 | 8 | {{/* List all pages */}} 9 | 19 | 20 | {{/* Display paginator */}} 21 | {{ template "_internal/pagination.html" . }} 22 | 23 | {{ end }} -------------------------------------------------------------------------------- /layouts/partials/header.html: -------------------------------------------------------------------------------- 1 | {{ block "header" . }} 2 |
3 |

4 | {{- .Site.Title -}} 5 |
6 | {{- range .Site.Menus.main -}} 7 | {{ if eq (hasPrefix .URL "mailto:") true }} 8 | {{- .Name -}} 9 | {{ else }} 10 | {{- .Name -}} 11 | {{- end -}} 12 | {{ end }} 13 |
14 |

15 |
16 | {{ end }} -------------------------------------------------------------------------------- /theme.toml: -------------------------------------------------------------------------------- 1 | name = "Simple Hugo Theme" 2 | license = "MIT" 3 | licenselink = "https://github.com/Xzya/simple-hugo-theme/blob/master/LICENSE.md" 4 | description = "A very simple and lightweight Hugo Theme inspired by the geniuses behind [bettermotherfuckingwebsite.com](http://bettermotherfuckingwebsite.com/)." 5 | homepage = "https://github.com/Xzya/simple-hugo-theme" 6 | tags = ["blog", "minimal", "clean", "light"] 7 | features = ["small page size", "fast", "tags", "google analytics", "pagination"] 8 | min_version = "0.41" 9 | 10 | [author] 11 | name = "Mihail Cristian Dumitru" 12 | homepage = "https://github.com/Xzya" 13 | -------------------------------------------------------------------------------- /layouts/partials/footer.html: -------------------------------------------------------------------------------- 1 | {{ block "footer" . }} 2 | 23 | {{ end }} -------------------------------------------------------------------------------- /layouts/partials/head.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {{- block "title" . -}} 7 | {{ .Title}}{{ if ne .Title .Site.Title }} | {{ .Site.Title }}{{ end }} 8 | {{- end -}} 9 | 10 | 11 | {{ $styles := resources.Get "css/style.css" | minify -}} 12 | 15 | 16 | {{- if .RSSLink }} 17 | 18 | {{- end -}} 19 | 20 | {{ template "_internal/google_analytics_async.html" . }} 21 | 22 | {{ partial "head_custom" . }} 23 | -------------------------------------------------------------------------------- /exampleSite/content/posts/2015-01-04-first-post.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: First post! 3 | date: 2015-01-05 4 | tags: ["demo"] 5 | --- 6 | 7 | This is my first post, how exciting! 8 | 9 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. 10 | 11 | 12 | 13 | Nullam at magna blandit, bibendum massa non, tincidunt turpis. Phasellus convallis lorem quis leo vulputate posuere. Nullam sit amet mattis lorem. Praesent et dolor feugiat, fringilla mauris iaculis, fringilla purus. Duis a finibus justo. Praesent tincidunt malesuada quam, ornare euismod sem vulputate vitae. Suspendisse consectetur ut felis vel tempor. Ut a viverra quam, quis luctus lorem. Pellentesque dolor ipsum, euismod vitae felis sit amet, fermentum consequat mi. Pellentesque eget mauris eu mi suscipit consequat. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hugo Simple Theme 2 | 3 | This is a very simple and lightweight Hugo Theme inspired by the geniuses behind [bettermotherfuckingwebsite.com](http://bettermotherfuckingwebsite.com/). 4 | 5 | ## Screenshots 6 | 7 | ![preview](https://raw.githubusercontent.com/Xzya/simple-hugo-theme/master/images/screenshot.png) 8 | ![preview](https://raw.githubusercontent.com/Xzya/simple-hugo-theme/master/images/screenshot2.png) 9 | 10 | ## Configuration 11 | 12 | Check `exampleSite/config.toml` for an example configuration. 13 | 14 | ## Menu 15 | 16 | The navbar displays the `main` menus by default. You can find more details about how to configure it [here](https://gohugo.io/templates/menu-templates/), as well as in the `exampleSite`. 17 | 18 | ## License 19 | 20 | Open sourced under the [MIT license](./LICENSE.md). -------------------------------------------------------------------------------- /layouts/partials/post_meta.html: -------------------------------------------------------------------------------- 1 | {{ $dateFormat := default "Jan 2, 2006" (index .Site.Params "datefmt") }} 2 | 3 |
4 | {{/* Display the date if set */}} 5 | {{- if not .Date.IsZero -}} 6 | Date [ 7 | 8 | ] 9 | {{- end -}} 10 | 11 | {{/* Display taxonomies */}} 12 | {{- range $taxo, $taxonomy := .Site.Taxonomies }} 13 | {{- $elems := $.Param $taxo }} 14 | {{- if $elems }} 15 | {{ $taxo | humanize }} [ 16 | {{- range $name := $elems }} 17 | {{- with $.Site.GetPage (lower (printf "/%s/%s" $taxo (urlize $name))) }} 18 | {{ $name }} 19 | {{- end }} 20 | {{- end }} 21 | ] 22 | {{- end }} 23 | {{- end }} 24 |
-------------------------------------------------------------------------------- /assets/css/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 40px auto; 3 | max-width: 650px; 4 | line-height: 1.6; 5 | font-size: 18px; 6 | color: #444; 7 | padding: 0 10px; 8 | } 9 | 10 | h1, 11 | h2, 12 | h3 { 13 | line-height: 1.2 14 | } 15 | 16 | div.header h1 { 17 | padding-top: 0; 18 | padding-bottom: 8px; 19 | margin-bottom: 24px; 20 | font-size: 18px; 21 | font-weight: 400; 22 | border-bottom: 1px solid; 23 | } 24 | 25 | .header-menu { 26 | float: right; 27 | } 28 | 29 | ul.pagination { 30 | list-style-type: none; 31 | text-align: center; 32 | padding: 0; 33 | } 34 | 35 | ul.pagination > li { 36 | padding: 0 8px; 37 | display: inline-block; 38 | } 39 | 40 | div.footer { 41 | border-top: 1px solid; 42 | text-align: center; 43 | } 44 | 45 | img { 46 | max-width: 100%; 47 | max-height: 100%; 48 | display: block; 49 | margin-left: auto; 50 | margin-right: auto; 51 | } 52 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 Mihail Cristian Dumitru 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | 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, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /exampleSite/config.toml: -------------------------------------------------------------------------------- 1 | baseurl = "https://example.com/" 2 | title = "simple demo" 3 | languageCode = "en-us" 4 | 5 | # Theme to use 6 | theme = "simple-hugo-theme" 7 | 8 | # Pagination 9 | paginate = 3 10 | paginatePath = "page" 11 | 12 | # Google analytics 13 | # googleAnalytics = "" 14 | 15 | # Copyright 16 | copyright = "© 2019 — Some Author — All rights reserved." 17 | 18 | # Highlighting 19 | pygmentsCodefences = true 20 | pygmentsCodeFencesGuessSyntax = true 21 | pygmentsoptions = "linenos=table" 22 | pygmentsStyle = "vs" 23 | 24 | # Taxonomies 25 | [taxonomies] 26 | tag = "tags" 27 | category = "categories" 28 | 29 | # Menu 30 | [menu] 31 | # Header 32 | [[menu.main]] 33 | url = "/posts/" 34 | name = "blog" 35 | weight = 1 36 | [[menu.main]] 37 | url = "/about/" 38 | name = "about" 39 | weight = 2 40 | [[menu.main]] 41 | url = "/contact/" 42 | name = "contact" 43 | weight = 3 44 | 45 | # Footer 46 | [[menu.footer]] 47 | url = "https://github.com/Xzya" 48 | name = "GitHub" 49 | weight = 1 50 | [[menu.footer]] 51 | url = "/posts/index.xml" 52 | name = "RSS" 53 | weight = 2 54 | [[menu.footer]] 55 | url = "mailto:foo@bar.com" 56 | name = "Contact" 57 | weight = 3 58 | 59 | 60 | # Links format 61 | [permalinks] 62 | posts = "/posts/:year/:month/:title/" 63 | 64 | [params] 65 | # Date format (default: Jan 2, 2006) 66 | # datefmt = "Jan 2, 2006" 67 | -------------------------------------------------------------------------------- /exampleSite/content/posts/hugoisforlovers.md: -------------------------------------------------------------------------------- 1 | +++ 2 | title = "Getting Started with Hugo" 3 | description = "" 4 | tags = [ 5 | "go", 6 | "golang", 7 | "hugo", 8 | "development", 9 | ] 10 | date = "2014-04-02" 11 | categories = [ 12 | "Development", 13 | "golang", 14 | ] 15 | author = "John Doe" 16 | language = "en" 17 | +++ 18 | 19 | ## Step 1. Install Hugo 20 | 21 | Goto [hugo releases](https://github.com/spf13/hugo/releases) and download the 22 | appropriate version for your os and architecture. 23 | 24 | Save it somewhere specific as we will be using it in the next step. 25 | 26 | More complete instructions are available at [installing hugo](/overview/installing/) 27 | 28 | ## Step 2. Build the Docs 29 | 30 | Hugo has its own example site which happens to also be the documentation site 31 | you are reading right now. 32 | 33 | Follow the following steps: 34 | 35 | 1. Clone the [hugo repository](http://github.com/spf13/hugo) 36 | 2. Go into the repo 37 | 3. Run hugo in server mode and build the docs 38 | 4. Open your browser to http://localhost:1313 39 | 40 | Corresponding pseudo commands: 41 | 42 | git clone https://github.com/spf13/hugo 43 | cd hugo 44 | /path/to/where/you/installed/hugo server --source=./docs 45 | > 29 pages created 46 | > 0 tags index created 47 | > in 27 ms 48 | > Web Server is available at http://localhost:1313 49 | > Press ctrl+c to stop 50 | 51 | Once you've gotten here, follow along the rest of this page on your local build. 52 | 53 | ## Step 3. Change the docs site 54 | 55 | Stop the Hugo process by hitting ctrl+c. 56 | 57 | Now we are going to run hugo again, but this time with hugo in watch mode. 58 | 59 | /path/to/hugo/from/step/1/hugo server --source=./docs --watch 60 | > 29 pages created 61 | > 0 tags index created 62 | > in 27 ms 63 | > Web Server is available at http://localhost:1313 64 | > Watching for changes in /Users/spf13/Code/hugo/docs/content 65 | > Press ctrl+c to stop 66 | 67 | 68 | Open your [favorite editor](http://vim.spf13.com) and change one of the source 69 | content pages. How about changing this very file to *fix the typo*. How about changing this very file to *fix the typo*. 70 | 71 | Content files are found in `docs/content/`. Unless otherwise specified, files 72 | are located at the same relative location as the url, in our case 73 | `docs/content/overview/quickstart.md`. 74 | 75 | Change and save this file.. Notice what happened in your terminal. 76 | 77 | > Change detected, rebuilding site 78 | 79 | > 29 pages created 80 | > 0 tags index created 81 | > in 26 ms 82 | 83 | Refresh the browser and observe that the typo is now fixed. 84 | 85 | Notice how quick that was. Try to refresh the site before it's finished building.. I double dare you. 86 | Having nearly instant feedback enables you to have your creativity flow without waiting for long builds. 87 | 88 | ## Step 4. Have fun 89 | 90 | The best way to learn something is to play with it. 91 | -------------------------------------------------------------------------------- /exampleSite/content/posts/migrate-from-jekyll.md: -------------------------------------------------------------------------------- 1 | --- 2 | date: 2014-03-10 3 | linktitle: Migrating from Jekyll 4 | prev: /tutorials/mathjax 5 | title: Migrate to Hugo from Jekyll 6 | weight: 10 7 | --- 8 | 9 | ## Move static content to `static` 10 | Jekyll has a rule that any directory not starting with `_` will be copied as-is to the `_site` output. Hugo keeps all static content under `static`. You should therefore move it all there. 11 | With Jekyll, something that looked like 12 | 13 | ▾ / 14 | ▾ images/ 15 | logo.png 16 | 17 | should become 18 | 19 | ▾ / 20 | ▾ static/ 21 | ▾ images/ 22 | logo.png 23 | 24 | Additionally, you'll want any files that should reside at the root (such as `CNAME`) to be moved to `static`. 25 | 26 | ## Create your Hugo configuration file 27 | Hugo can read your configuration as JSON, YAML or TOML. Hugo supports parameters custom configuration too. Refer to the [Hugo configuration documentation](/overview/configuration/) for details. 28 | 29 | ## Set your configuration publish folder to `_site` 30 | The default is for Jekyll to publish to `_site` and for Hugo to publish to `public`. If, like me, you have [`_site` mapped to a git submodule on the `gh-pages` branch](http://blog.blindgaenger.net/generate_github_pages_in_a_submodule.html), you'll want to do one of two alternatives: 31 | 32 | 1. Change your submodule to point to map `gh-pages` to public instead of `_site` (recommended). 33 | 34 | git submodule deinit _site 35 | git rm _site 36 | git submodule add -b gh-pages git@github.com:your-username/your-repo.git public 37 | 38 | 2. Or, change the Hugo configuration to use `_site` instead of `public`. 39 | 40 | { 41 | .. 42 | "publishdir": "_site", 43 | .. 44 | } 45 | 46 | ## Convert Jekyll templates to Hugo templates 47 | That's the bulk of the work right here. The documentation is your friend. You should refer to [Jekyll's template documentation](http://jekyllrb.com/docs/templates/) if you need to refresh your memory on how you built your blog and [Hugo's template](/layout/templates/) to learn Hugo's way. 48 | 49 | As a single reference data point, converting my templates for [heyitsalex.net](http://heyitsalex.net/) took me no more than a few hours. 50 | 51 | ## Convert Jekyll plugins to Hugo shortcodes 52 | Jekyll has [plugins](http://jekyllrb.com/docs/plugins/); Hugo has [shortcodes](/doc/shortcodes/). It's fairly trivial to do a port. 53 | 54 | ### Implementation 55 | As an example, I was using a custom [`image_tag`](https://github.com/alexandre-normand/alexandre-normand/blob/74bb12036a71334fdb7dba84e073382fc06908ec/_plugins/image_tag.rb) plugin to generate figures with caption when running Jekyll. As I read about shortcodes, I found Hugo had a nice built-in shortcode that does exactly the same thing. 56 | 57 | Jekyll's plugin: 58 | 59 | module Jekyll 60 | class ImageTag < Liquid::Tag 61 | @url = nil 62 | @caption = nil 63 | @class = nil 64 | @link = nil 65 | // Patterns 66 | IMAGE_URL_WITH_CLASS_AND_CAPTION = 67 | IMAGE_URL_WITH_CLASS_AND_CAPTION_AND_LINK = /(\w+)(\s+)((https?:\/\/|\/)(\S+))(\s+)"(.*?)"(\s+)->((https?:\/\/|\/)(\S+))(\s*)/i 68 | IMAGE_URL_WITH_CAPTION = /((https?:\/\/|\/)(\S+))(\s+)"(.*?)"/i 69 | IMAGE_URL_WITH_CLASS = /(\w+)(\s+)((https?:\/\/|\/)(\S+))/i 70 | IMAGE_URL = /((https?:\/\/|\/)(\S+))/i 71 | def initialize(tag_name, markup, tokens) 72 | super 73 | if markup =~ IMAGE_URL_WITH_CLASS_AND_CAPTION_AND_LINK 74 | @class = $1 75 | @url = $3 76 | @caption = $7 77 | @link = $9 78 | elsif markup =~ IMAGE_URL_WITH_CLASS_AND_CAPTION 79 | @class = $1 80 | @url = $3 81 | @caption = $7 82 | elsif markup =~ IMAGE_URL_WITH_CAPTION 83 | @url = $1 84 | @caption = $5 85 | elsif markup =~ IMAGE_URL_WITH_CLASS 86 | @class = $1 87 | @url = $3 88 | elsif markup =~ IMAGE_URL 89 | @url = $1 90 | end 91 | end 92 | def render(context) 93 | if @class 94 | source = "
" 95 | else 96 | source = "
" 97 | end 98 | if @link 99 | source += "" 100 | end 101 | source += "" 102 | if @link 103 | source += "" 104 | end 105 | source += "
#{@caption}
" if @caption 106 | source += "
" 107 | source 108 | end 109 | end 110 | end 111 | Liquid::Template.register_tag('image', Jekyll::ImageTag) 112 | 113 | is written as this Hugo shortcode: 114 | 115 | 116 |
117 | {{ with .Get "link"}}{{ end }} 118 | 119 | {{ if .Get "link"}}{{ end }} 120 | {{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}} 121 |
{{ if isset .Params "title" }} 122 | {{ .Get "title" }}{{ end }} 123 | {{ if or (.Get "caption") (.Get "attr")}}

124 | {{ .Get "caption" }} 125 | {{ with .Get "attrlink"}} {{ end }} 126 | {{ .Get "attr" }} 127 | {{ if .Get "attrlink"}} {{ end }} 128 |

{{ end }} 129 |
130 | {{ end }} 131 |
132 | 133 | 134 | ### Usage 135 | I simply changed: 136 | 137 | {% image full http://farm5.staticflickr.com/4136/4829260124_57712e570a_o_d.jpg "One of my favorite touristy-type photos. I secretly waited for the good light while we were "having fun" and took this. Only regret: a stupid pole in the top-left corner of the frame I had to clumsily get rid of at post-processing." ->http://www.flickr.com/photos/alexnormand/4829260124/in/set-72157624547713078/ %} 138 | 139 | to this (this example uses a slightly extended version named `fig`, different than the built-in `figure`): 140 | 141 | {{%/* fig class="full" src="http://farm5.staticflickr.com/4136/4829260124_57712e570a_o_d.jpg" title="One of my favorite touristy-type photos. I secretly waited for the good light while we were having fun and took this. Only regret: a stupid pole in the top-left corner of the frame I had to clumsily get rid of at post-processing." link="http://www.flickr.com/photos/alexnormand/4829260124/in/set-72157624547713078/" */%}} 142 | 143 | As a bonus, the shortcode named parameters are, arguably, more readable. 144 | 145 | ## Finishing touches 146 | ### Fix content 147 | Depending on the amount of customization that was done with each post with Jekyll, this step will require more or less effort. There are no hard and fast rules here except that `hugo server --watch` is your friend. Test your changes and fix errors as needed. 148 | 149 | ### Clean up 150 | You'll want to remove the Jekyll configuration at this point. If you have anything else that isn't used, delete it. 151 | 152 | ## A practical example in a diff 153 | [Hey, it's Alex](http://heyitsalex.net/) was migrated in less than a _father-with-kids day_ from Jekyll to Hugo. You can see all the changes (and screw-ups) by looking at this [diff](https://github.com/alexandre-normand/alexandre-normand/compare/869d69435bd2665c3fbf5b5c78d4c22759d7613a...b7f6605b1265e83b4b81495423294208cc74d610). 154 | -------------------------------------------------------------------------------- /exampleSite/content/posts/goisforlovers.md: -------------------------------------------------------------------------------- 1 | +++ 2 | title = "(Hu)go Template Primer" 3 | description = "" 4 | tags = [ 5 | "go", 6 | "golang", 7 | "templates", 8 | "themes", 9 | "development", 10 | "demo", 11 | ] 12 | date = "2014-04-02" 13 | categories = [ 14 | "Development", 15 | "golang", 16 | ] 17 | +++ 18 | 19 | Hugo uses the excellent [go][] [html/template][gohtmltemplate] library for 20 | its template engine. It is an extremely lightweight engine that provides a very 21 | small amount of logic. In our experience that it is just the right amount of 22 | logic to be able to create a good static website. If you have used other 23 | template systems from different languages or frameworks you will find a lot of 24 | similarities in go templates. 25 | 26 | This document is a brief primer on using go templates. The [go docs][gohtmltemplate] 27 | provide more details. 28 | 29 | # Introduction to Go Templates 30 | 31 | Go templates provide an extremely simple template language. It adheres to the 32 | belief that only the most basic of logic belongs in the template or view layer. 33 | One consequence of this simplicity is that go templates parse very quickly. 34 | 35 | A unique characteristic of go templates is they are content aware. Variables and 36 | content will be sanitized depending on the context of where they are used. More 37 | details can be found in the [go docs][gohtmltemplate]. 38 | 39 | ## Basic Syntax 40 | 41 | Go lang templates are html files with the addition of variables and 42 | functions. 43 | 44 | **Go variables and functions are accessible within {{ }}** 45 | 46 | Accessing a predefined variable "foo": 47 | 48 | {{ foo }} 49 | 50 | **Parameters are separated using spaces** 51 | 52 | Calling the add function with input of 1, 2: 53 | 54 | {{ add 1 2 }} 55 | 56 | **Methods and fields are accessed via dot notation** 57 | 58 | Accessing the Page Parameter "bar" 59 | 60 | {{ .Params.bar }} 61 | 62 | **Parentheses can be used to group items together** 63 | 64 | {{ if or (isset .Params "alt") (isset .Params "caption") }} Caption {{ end }} 65 | 66 | 67 | ## Variables 68 | 69 | Each go template has a struct (object) made available to it. In hugo each 70 | template is passed either a page or a node struct depending on which type of 71 | page you are rendering. More details are available on the 72 | [variables](/layout/variables) page. 73 | 74 | A variable is accessed by referencing the variable name. 75 | 76 | {{ .Title }} 77 | 78 | Variables can also be defined and referenced. 79 | 80 | {{ $address := "123 Main St."}} 81 | {{ $address }} 82 | 83 | 84 | ## Functions 85 | 86 | Go template ship with a few functions which provide basic functionality. The go 87 | template system also provides a mechanism for applications to extend the 88 | available functions with their own. [Hugo template 89 | functions](/layout/functions) provide some additional functionality we believe 90 | are useful for building websites. Functions are called by using their name 91 | followed by the required parameters separated by spaces. Template 92 | functions cannot be added without recompiling hugo. 93 | 94 | **Example:** 95 | 96 | {{ add 1 2 }} 97 | 98 | ## Includes 99 | 100 | When including another template you will pass to it the data it will be 101 | able to access. To pass along the current context please remember to 102 | include a trailing dot. The templates location will always be starting at 103 | the /layout/ directory within Hugo. 104 | 105 | **Example:** 106 | 107 | {{ template "chrome/header.html" . }} 108 | 109 | 110 | ## Logic 111 | 112 | Go templates provide the most basic iteration and conditional logic. 113 | 114 | ### Iteration 115 | 116 | Just like in go, the go templates make heavy use of range to iterate over 117 | a map, array or slice. The following are different examples of how to use 118 | range. 119 | 120 | **Example 1: Using Context** 121 | 122 | {{ range array }} 123 | {{ . }} 124 | {{ end }} 125 | 126 | **Example 2: Declaring value variable name** 127 | 128 | {{range $element := array}} 129 | {{ $element }} 130 | {{ end }} 131 | 132 | **Example 2: Declaring key and value variable name** 133 | 134 | {{range $index, $element := array}} 135 | {{ $index }} 136 | {{ $element }} 137 | {{ end }} 138 | 139 | ### Conditionals 140 | 141 | If, else, with, or, & and provide the framework for handling conditional 142 | logic in Go Templates. Like range, each statement is closed with `end`. 143 | 144 | 145 | Go Templates treat the following values as false: 146 | 147 | * false 148 | * 0 149 | * any array, slice, map, or string of length zero 150 | 151 | **Example 1: If** 152 | 153 | {{ if isset .Params "title" }}

{{ index .Params "title" }}

{{ end }} 154 | 155 | **Example 2: If -> Else** 156 | 157 | {{ if isset .Params "alt" }} 158 | {{ index .Params "alt" }} 159 | {{else}} 160 | {{ index .Params "caption" }} 161 | {{ end }} 162 | 163 | **Example 3: And & Or** 164 | 165 | {{ if and (or (isset .Params "title") (isset .Params "caption")) (isset .Params "attr")}} 166 | 167 | **Example 4: With** 168 | 169 | An alternative way of writing "if" and then referencing the same value 170 | is to use "with" instead. With rebinds the context `.` within its scope, 171 | and skips the block if the variable is absent. 172 | 173 | The first example above could be simplified as: 174 | 175 | {{ with .Params.title }}

{{ . }}

{{ end }} 176 | 177 | **Example 5: If -> Else If** 178 | 179 | {{ if isset .Params "alt" }} 180 | {{ index .Params "alt" }} 181 | {{ else if isset .Params "caption" }} 182 | {{ index .Params "caption" }} 183 | {{ end }} 184 | 185 | ## Pipes 186 | 187 | One of the most powerful components of go templates is the ability to 188 | stack actions one after another. This is done by using pipes. Borrowed 189 | from unix pipes, the concept is simple, each pipeline's output becomes the 190 | input of the following pipe. 191 | 192 | Because of the very simple syntax of go templates, the pipe is essential 193 | to being able to chain together function calls. One limitation of the 194 | pipes is that they only can work with a single value and that value 195 | becomes the last parameter of the next pipeline. 196 | 197 | A few simple examples should help convey how to use the pipe. 198 | 199 | **Example 1 :** 200 | 201 | {{ if eq 1 1 }} Same {{ end }} 202 | 203 | is the same as 204 | 205 | {{ eq 1 1 | if }} Same {{ end }} 206 | 207 | It does look odd to place the if at the end, but it does provide a good 208 | illustration of how to use the pipes. 209 | 210 | **Example 2 :** 211 | 212 | {{ index .Params "disqus_url" | html }} 213 | 214 | Access the page parameter called "disqus_url" and escape the HTML. 215 | 216 | **Example 3 :** 217 | 218 | {{ if or (or (isset .Params "title") (isset .Params "caption")) (isset .Params "attr")}} 219 | Stuff Here 220 | {{ end }} 221 | 222 | Could be rewritten as 223 | 224 | {{ isset .Params "caption" | or isset .Params "title" | or isset .Params "attr" | if }} 225 | Stuff Here 226 | {{ end }} 227 | 228 | 229 | ## Context (aka. the dot) 230 | 231 | The most easily overlooked concept to understand about go templates is that {{ . }} 232 | always refers to the current context. In the top level of your template this 233 | will be the data set made available to it. Inside of a iteration it will have 234 | the value of the current item. When inside of a loop the context has changed. . 235 | will no longer refer to the data available to the entire page. If you need to 236 | access this from within the loop you will likely want to set it to a variable 237 | instead of depending on the context. 238 | 239 | **Example:** 240 | 241 | {{ $title := .Site.Title }} 242 | {{ range .Params.tags }} 243 |
  • {{ . }} - {{ $title }}
  • 244 | {{ end }} 245 | 246 | Notice how once we have entered the loop the value of {{ . }} has changed. We 247 | have defined a variable outside of the loop so we have access to it from within 248 | the loop. 249 | 250 | # Hugo Parameters 251 | 252 | Hugo provides the option of passing values to the template language 253 | through the site configuration (for sitewide values), or through the meta 254 | data of each specific piece of content. You can define any values of any 255 | type (supported by your front matter/config format) and use them however 256 | you want to inside of your templates. 257 | 258 | 259 | ## Using Content (page) Parameters 260 | 261 | In each piece of content you can provide variables to be used by the 262 | templates. This happens in the [front matter](/content/front-matter). 263 | 264 | An example of this is used in this documentation site. Most of the pages 265 | benefit from having the table of contents provided. Sometimes the TOC just 266 | doesn't make a lot of sense. We've defined a variable in our front matter 267 | of some pages to turn off the TOC from being displayed. 268 | 269 | Here is the example front matter: 270 | 271 | ``` 272 | --- 273 | title: "Permalinks" 274 | date: "2013-11-18" 275 | aliases: 276 | - "/doc/permalinks/" 277 | groups: ["extras"] 278 | groups_weight: 30 279 | notoc: true 280 | --- 281 | ``` 282 | 283 | Here is the corresponding code inside of the template: 284 | 285 | {{ if not .Params.notoc }} 286 |
    287 | {{ .TableOfContents }} 288 |
    289 | {{ end }} 290 | 291 | 292 | 293 | ## Using Site (config) Parameters 294 | In your top-level configuration file (eg, `config.yaml`) you can define site 295 | parameters, which are values which will be available to you in chrome. 296 | 297 | For instance, you might declare: 298 | 299 | ```yaml 300 | params: 301 | CopyrightHTML: "Copyright © 2013 John Doe. All Rights Reserved." 302 | TwitterUser: "spf13" 303 | SidebarRecentLimit: 5 304 | ``` 305 | 306 | Within a footer layout, you might then declare a `