├── archetypes ├── default.md └── post.md ├── .github └── FUNDING.yml ├── images ├── tn.png └── screenshot.png ├── static ├── img │ └── bg-blog.jpg └── css │ └── blog.css ├── layouts ├── 404.html ├── _default │ ├── baseof.html │ ├── single.html │ └── rss.xml ├── partials │ ├── widget-archives.html │ ├── widget-tags.html │ ├── widget-recent.html │ ├── widget-related.html │ ├── footer.html │ └── header.html ├── tags │ └── list.html ├── taxonomy │ ├── tag.html │ └── archive.html ├── archives │ └── list.html ├── post │ └── list.html └── index.html ├── exampleSite ├── config.toml └── content │ ├── about.md │ └── post │ ├── hugoisforlovers.md │ ├── migrate-from-jekyll.md │ ├── goisforlovers.md │ └── creating-a-new-theme.md ├── theme.toml ├── LICENSE └── README.md /archetypes/default.md: -------------------------------------------------------------------------------- 1 | +++ 2 | +++ 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: ['Tazeg'] 2 | custom: ['https://keybase.io/jeffprod'] 3 | -------------------------------------------------------------------------------- /images/tn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tazeg/hugo-blog-jeffprod/HEAD/images/tn.png -------------------------------------------------------------------------------- /images/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tazeg/hugo-blog-jeffprod/HEAD/images/screenshot.png -------------------------------------------------------------------------------- /static/img/bg-blog.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tazeg/hugo-blog-jeffprod/HEAD/static/img/bg-blog.jpg -------------------------------------------------------------------------------- /layouts/404.html: -------------------------------------------------------------------------------- 1 | {{ define "main" }} 2 | 3 |
4 |
5 | Page not found... 6 |
7 |
8 | 9 | {{ end }} 10 | -------------------------------------------------------------------------------- /archetypes/post.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "{{ replace .Name "-" " " | title }}" 3 | date: {{ .Date }} 4 | archives: "{{ dateFormat "2006" now }}" 5 | tags: [] 6 | author: John SMITH 7 | --- 8 | -------------------------------------------------------------------------------- /layouts/_default/baseof.html: -------------------------------------------------------------------------------- 1 | {{ partial "header.html" . }} 2 | 3 |
4 |
5 | {{ block "main" . }}{{ end }} 6 |
7 |
8 | 9 | {{ partial "footer.html" . }} -------------------------------------------------------------------------------- /exampleSite/config.toml: -------------------------------------------------------------------------------- 1 | baseurl = "https://example.com" 2 | title = "Hugo Theme" 3 | author = "@JeffProd" 4 | copyright = "Copyright © 2008–2018, @JeffProd" 5 | canonifyurls = true 6 | paginate = 3 7 | 8 | theme = "hugo-blog-jeffprod" 9 | 10 | [taxonomies] 11 | tag = "tags" 12 | archive = "archives" 13 | -------------------------------------------------------------------------------- /static/css/blog.css: -------------------------------------------------------------------------------- 1 | html,body { 2 | font-family: 'Open Sans', sans-serif; 3 | background: #F0F2F4; 4 | } 5 | .hero-body { 6 | background-position: center; 7 | background-size: cover; 8 | background-repeat: no-repeat; 9 | } 10 | .mysocial { color: hsl(0, 0%, 100%);} 11 | .mysocial:hover { color: hsl(0, 0%, 71%) } 12 | -------------------------------------------------------------------------------- /layouts/partials/widget-archives.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Archives

4 | {{ range (where .Site.RegularPages "Section" "post").GroupByDate "2006" }} 5 | {{ .Key }} ({{ len .Pages }})
6 | {{ end }} 7 |
8 |
9 | -------------------------------------------------------------------------------- /layouts/partials/widget-tags.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Tags

4 |
5 | {{ range $name, $taxonomy := .Site.Taxonomies.tags }} 6 | {{ $name }} 7 | {{ end }} 8 |
9 |
10 |
-------------------------------------------------------------------------------- /layouts/partials/widget-recent.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Recent posts

4 | {{ range first 5 (where .Site.RegularPages "Section" "post").ByPublishDate.Reverse }} 5 |

{{ .Title }}

6 | 7 | {{ end }} 8 |
9 |
10 | -------------------------------------------------------------------------------- /exampleSite/content/about.md: -------------------------------------------------------------------------------- 1 | +++ 2 | title = "About Hugo" 3 | date = "2014-04-09" 4 | menu = "main" 5 | +++ 6 | 7 | Hugo is the **world’s fastest framework for building websites**. It is written in Go. 8 | 9 | It makes use of a variety of open source projects including: 10 | 11 | * https://github.com/russross/blackfriday 12 | * https://github.com/alecthomas/chroma 13 | * https://github.com/muesli/smartcrop 14 | * https://github.com/spf13/cobra 15 | * https://github.com/spf13/viper 16 | 17 | Learn more and contribute on [GitHub](https://github.com/gohugoio). 18 | 19 | -------------------------------------------------------------------------------- /layouts/_default/single.html: -------------------------------------------------------------------------------- 1 | {{ define "main" }} 2 | 3 |
4 |
5 |
6 |
7 | {{ .Content }} 8 |
9 |
10 |
11 |
12 | {{ partial "widget-tags.html" . }}
13 | {{ partial "widget-recent.html" . }}
14 | {{ partial "widget-related.html" . }}
15 | {{ partial "widget-archives.html" . }} 16 |
17 |
18 | 19 | {{ end }} 20 | -------------------------------------------------------------------------------- /theme.toml: -------------------------------------------------------------------------------- 1 | # theme.toml template for a Hugo theme 2 | # See https://github.com/gohugoio/hugoThemes#themetoml for an example 3 | 4 | name = "Jeffprod" 5 | license = "MIT" 6 | licenselink = "https://github.com/Tazeg/hugo-blog-jeffprod/blob/master/LICENSE" 7 | description = "A new theme blog for HUGO built with Bulma CSS. Including archives and tags widgets." 8 | homepage = "https://github.com/Tazeg/hugo-blog-jeffprod" 9 | tags = ["simple","blog","theme","pagination","archives","tags","bulma","personal"] 10 | features = ["pagination","archives","tags"] 11 | min_version = "0.41" 12 | 13 | [author] 14 | name = "@JeffProd" 15 | homepage = "https://jeffprod.com" 16 | -------------------------------------------------------------------------------- /layouts/partials/widget-related.html: -------------------------------------------------------------------------------- 1 | {{ range first 1 (where (where .Site.Pages ".Params.tags" "intersect" .Params.tags) "Permalink" "!=" .Permalink) }} 2 | {{ $.Scratch.Set "has_related" true }} 3 | {{ end }} 4 | 5 | {{ if $.Scratch.Get "has_related" }} 6 |
7 |
8 |

Related posts

9 | {{ $num_to_show := .Site.Params.related_content_limit | default 7 }} 10 | {{ range first $num_to_show (where (where .Site.Pages ".Params.tags" "intersect" .Params.tags) "Permalink" "!=" .Permalink) }} 11 |

{{ .Title }}

12 | 13 | {{ end }} 14 |
15 |
16 | {{ end }} 17 | 18 | -------------------------------------------------------------------------------- /layouts/partials/footer.html: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 @JeffProd 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HUGO blog theme by @JeffProd 2 | 3 | A free blog theme for [HUGO](https://gohugo.io/), with tags, archives, last posts... Using [Bulma CSS framework](https://bulma.io/). 4 | 5 | ![HUGO blog theme by JeffProd.com](images/screenshot.png) 6 | 7 | # Install 8 | 9 | Install HUGO () then : 10 | 11 | ``` 12 | hugo new site myblog 13 | cd myblog 14 | git clone https://github.com/Tazeg/hugo-blog-jeffprod.git themes/jeffprod 15 | ``` 16 | In the file `config.toml` add the lines : 17 | ``` 18 | theme = "jeffprod" 19 | 20 | [permalinks] 21 | post = "/:year/:filename" 22 | 23 | [taxonomies] 24 | tag = "tags" 25 | archive = "archives" 26 | ``` 27 | 28 | ### Write blog posts 29 | 30 | ``` 31 | hugo new post/my-first-post.md 32 | ``` 33 | And edit this new file `content/post/my-first-post.md`. You can use [HUGO shortcodes](https://gohugo.io/content-management/shortcodes/) and [Markdown](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet). 34 | 35 | ### Render 36 | 37 | ``` 38 | hugo server 39 | ``` 40 | Then go to 41 | 42 | ### Create the web site 43 | 44 | ``` 45 | hugo 46 | ``` 47 | 48 | All files to publish are in `public/` directory. 49 | 50 | # Donate 51 | 52 | 53 | 54 | # Credits 55 | 56 | Background image by https://pixabay.com 57 | -------------------------------------------------------------------------------- /layouts/tags/list.html: -------------------------------------------------------------------------------- 1 | {{ define "main" }} 2 | 3 | {{ $tag := lower .Title }} 4 | 5 |
6 |
7 |
8 |
9 | {{ range $key, $value := .Site.Taxonomies.tags }}{{ if eq $key $tag }}{{ range $value.Pages }} 10 |
11 |
12 |
13 |

{{ .LinkTitle }}

14 |

15 | Published at {{ .Date.Format "January 2, 2006" }} · 16 |  {{.ReadingTime}} min read 17 |

18 |

{{ .Summary }}...

19 |
20 |
21 |
22 |
23 | {{ end }}{{ end }}{{ end }} 24 |
25 |
26 |
27 |
28 | {{ partial "widget-tags.html" . }}
29 | {{ partial "widget-recent.html" . }}
30 | {{ partial "widget-archives.html" . }} 31 |
32 |
33 | 34 | {{ end }} 35 | -------------------------------------------------------------------------------- /layouts/taxonomy/tag.html: -------------------------------------------------------------------------------- 1 | {{ define "main" }} 2 | 3 | {{ $tag := lower .Title }} 4 | 5 |
6 |
7 |
8 |
9 | {{ range $key, $value := .Site.Taxonomies.tags }}{{ if eq $key $tag }}{{ range $value.Pages }} 10 |
11 |
12 |
13 |

{{ .LinkTitle }}

14 |

15 | Published at {{ .Date.Format "January 2, 2006" }} · 16 |  {{.ReadingTime}} min read 17 |

18 |

{{ .Summary }}...

19 |
20 |
21 |
22 |
23 | {{ end }}{{ end }}{{ end }} 24 |
25 |
26 |
27 |
28 | {{ partial "widget-tags.html" . }}
29 | {{ partial "widget-recent.html" . }}
30 | {{ partial "widget-archives.html" . }} 31 |
32 |
33 | 34 | {{ end }} 35 | -------------------------------------------------------------------------------- /layouts/archives/list.html: -------------------------------------------------------------------------------- 1 | {{ define "main" }} 2 | {{ $archive := lower .Title }} 3 | 4 |
5 |
6 |
7 |
8 | {{ range $key, $value := .Site.Taxonomies.archives }}{{ if eq $key $archive }}{{ range $value.Pages }} 9 |
10 |
11 |
12 |

{{ .LinkTitle }}

13 |

14 | Published at {{ .Date.Format "January 2, 2006" }} · 15 |  {{.ReadingTime}} min read 16 |

17 |

{{ .Summary }}...

18 |
19 |
20 |
21 |
22 | {{ end }}{{ end }}{{ end }} 23 |
24 |
25 |
26 |
27 | {{ partial "widget-tags.html" . }}
28 | {{ partial "widget-recent.html" . }}
29 | {{ partial "widget-archives.html" . }} 30 |
31 |
32 | 33 | 34 | {{ end }} -------------------------------------------------------------------------------- /layouts/taxonomy/archive.html: -------------------------------------------------------------------------------- 1 | {{ define "main" }} 2 | {{ $archive := lower .Title }} 3 | 4 |
5 |
6 |
7 |
8 | {{ range $key, $value := .Site.Taxonomies.archives }}{{ if eq $key $archive }}{{ range $value.Pages }} 9 |
10 |
11 |
12 |

{{ .LinkTitle }}

13 |

14 | Published at {{ .Date.Format "January 2, 2006" }} · 15 |  {{.ReadingTime}} min read 16 |

17 |

{{ .Summary }}...

18 |
19 |
20 |
21 |
22 | {{ end }}{{ end }}{{ end }} 23 |
24 |
25 |
26 |
27 | {{ partial "widget-tags.html" . }}
28 | {{ partial "widget-recent.html" . }}
29 | {{ partial "widget-archives.html" . }} 30 |
31 |
32 | 33 | 34 | {{ end }} -------------------------------------------------------------------------------- /layouts/post/list.html: -------------------------------------------------------------------------------- 1 | {{ define "main" }} 2 | {{ $archive := lower .Title }} 3 | 4 |
5 |
6 |
7 |
8 | {{ range $key, $value := .Site.Taxonomies.archives }}{{ if eq $key $archive }}{{ range $value.Pages }} 9 |
10 |
11 |
12 |

{{ .LinkTitle }}

13 |

14 | Published at {{ .Date.Format "January 2, 2006" }} · 15 |  {{.ReadingTime}} min read 16 |

17 |

{{ .Summary }}...

18 |
19 |
20 |
21 |
22 | {{ end }}{{ end }}{{ end }} 23 |
24 |
25 |
26 |
27 | {{ partial "widget-tags.html" . }}
28 | {{ partial "widget-recent.html" . }}
29 | {{ partial "widget-related.html" . }}
30 | {{ partial "widget-archives.html" . }} 31 |
32 |
33 | 34 | 35 | {{ end }} -------------------------------------------------------------------------------- /layouts/_default/rss.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | {{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }} 4 | {{ .Permalink }} 5 | Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }} 6 | Hugo -- gohugo.io{{ with .Site.LanguageCode }} 7 | {{.}}{{end}}{{ with .Site.Author.email }} 8 | {{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}}{{ with .Site.Author.email }} 9 | {{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}}{{ with .Site.Copyright }} 10 | {{.}}{{end}}{{ if not .Date.IsZero }} 11 | {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}{{ end }} 12 | {{ with .OutputFormats.Get "RSS" }} 13 | {{ printf "" .Permalink .MediaType | safeHTML }} 14 | {{ end }} 15 | {{ range .Pages }} 16 | 17 | {{ .Title }} 18 | {{ .Permalink }} 19 | {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }} 20 | {{ with .Site.Author.email }}{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}} 21 | {{ .Permalink }} 22 | {{ .Summary | html }} 23 | 24 | {{ end }} 25 | 26 | 27 | -------------------------------------------------------------------------------- /layouts/partials/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {{ .Site.Title }} {{ with .Title }} | {{ . }}{{ end }} 7 | 8 | 9 | 10 | 11 | 12 | 13 | {{ with .OutputFormats.Get "rss" -}} 14 | {{ printf `` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} 15 | {{ end -}} 16 | 17 | 18 | 19 | 20 | 25 | 26 | 27 | 28 |
29 |
30 |
31 |
32 |

33 | {{ if eq .Type "tags" }} 34 | #{{ .Title }} 35 | {{ else if eq .Type "archives" }} 36 | Archive {{ .Title }} 37 | {{ else }} 38 | {{ .Title }} 39 | {{ end }} 40 |

41 | {{ if eq .Type "article" }} 42 | {{ .Date.Format "January 2, 2006" }} · {{ .ReadingTime }} min read 43 | {{ end }} 44 |
45 |
46 |
47 | -------------------------------------------------------------------------------- /layouts/index.html: -------------------------------------------------------------------------------- 1 | {{ define "main" }} 2 | {{ $paginator := .Paginate (where .Site.RegularPages "Section" "post").ByPublishDate.Reverse }} 3 | 4 |
5 |
6 |
7 |
8 |

Welcome to my blog !

9 |
10 | {{ range $paginator.Pages }} 11 |
12 |
13 |
14 |

{{ .LinkTitle }}

15 |

16 | Published at {{ .Date.Format "January 2, 2006" }} · 17 |  {{.ReadingTime}} min read 18 |

19 |

{{ .Summary }}...

20 |
21 |
22 |
23 | {{ end }} 24 |
25 |
26 |
27 |
28 | {{ partial "widget-tags.html" . }}
29 | {{ partial "widget-recent.html" . }}
30 | {{ partial "widget-archives.html" . }} 31 |
32 |
33 |
34 |
35 | 46 |
47 |
48 | 49 | {{ end }} 50 | -------------------------------------------------------------------------------- /exampleSite/content/post/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 | archives = "2014" 12 | categories = [ 13 | "Development", 14 | "golang", 15 | ] 16 | menu = "main" 17 | +++ 18 | 19 | ## Step 1. Install Hugo 20 | 21 | Go to [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 [Install Hugo](https://gohugo.io/getting-started/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/post/migrate-from-jekyll.md: -------------------------------------------------------------------------------- 1 | --- 2 | date: 2014-03-10 3 | archives: "2014" 4 | linktitle: Migrating from Jekyll 5 | menu: 6 | main: 7 | parent: tutorials 8 | prev: /tutorials/mathjax 9 | title: Migrate to Hugo from Jekyll 10 | weight: 10 11 | --- 12 | 13 | ## Move static content to `static` 14 | 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. 15 | With Jekyll, something that looked like 16 | 17 | ▾ / 18 | ▾ images/ 19 | logo.png 20 | 21 | should become 22 | 23 | ▾ / 24 | ▾ static/ 25 | ▾ images/ 26 | logo.png 27 | 28 | Additionally, you'll want any files that should reside at the root (such as `CNAME`) to be moved to `static`. 29 | 30 | ## Create your Hugo configuration file 31 | 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. 32 | 33 | ## Set your configuration publish folder to `_site` 34 | 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: 35 | 36 | 1. Change your submodule to point to map `gh-pages` to public instead of `_site` (recommended). 37 | 38 | git submodule deinit _site 39 | git rm _site 40 | git submodule add -b gh-pages git@github.com:your-username/your-repo.git public 41 | 42 | 2. Or, change the Hugo configuration to use `_site` instead of `public`. 43 | 44 | { 45 | .. 46 | "publishdir": "_site", 47 | .. 48 | } 49 | 50 | ## Convert Jekyll templates to Hugo templates 51 | 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. 52 | 53 | As a single reference data point, converting my templates for [heyitsalex.net](http://heyitsalex.net/) took me no more than a few hours. 54 | 55 | ## Convert Jekyll plugins to Hugo shortcodes 56 | Jekyll has [plugins](http://jekyllrb.com/docs/plugins/); Hugo has [shortcodes](/doc/shortcodes/). It's fairly trivial to do a port. 57 | 58 | ### Implementation 59 | 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. 60 | 61 | Jekyll's plugin: 62 | 63 | module Jekyll 64 | class ImageTag < Liquid::Tag 65 | @url = nil 66 | @caption = nil 67 | @class = nil 68 | @link = nil 69 | // Patterns 70 | IMAGE_URL_WITH_CLASS_AND_CAPTION = 71 | IMAGE_URL_WITH_CLASS_AND_CAPTION_AND_LINK = /(\w+)(\s+)((https?:\/\/|\/)(\S+))(\s+)"(.*?)"(\s+)->((https?:\/\/|\/)(\S+))(\s*)/i 72 | IMAGE_URL_WITH_CAPTION = /((https?:\/\/|\/)(\S+))(\s+)"(.*?)"/i 73 | IMAGE_URL_WITH_CLASS = /(\w+)(\s+)((https?:\/\/|\/)(\S+))/i 74 | IMAGE_URL = /((https?:\/\/|\/)(\S+))/i 75 | def initialize(tag_name, markup, tokens) 76 | super 77 | if markup =~ IMAGE_URL_WITH_CLASS_AND_CAPTION_AND_LINK 78 | @class = $1 79 | @url = $3 80 | @caption = $7 81 | @link = $9 82 | elsif markup =~ IMAGE_URL_WITH_CLASS_AND_CAPTION 83 | @class = $1 84 | @url = $3 85 | @caption = $7 86 | elsif markup =~ IMAGE_URL_WITH_CAPTION 87 | @url = $1 88 | @caption = $5 89 | elsif markup =~ IMAGE_URL_WITH_CLASS 90 | @class = $1 91 | @url = $3 92 | elsif markup =~ IMAGE_URL 93 | @url = $1 94 | end 95 | end 96 | def render(context) 97 | if @class 98 | source = "
" 99 | else 100 | source = "
" 101 | end 102 | if @link 103 | source += "" 104 | end 105 | source += "" 106 | if @link 107 | source += "" 108 | end 109 | source += "
#{@caption}
" if @caption 110 | source += "
" 111 | source 112 | end 113 | end 114 | end 115 | Liquid::Template.register_tag('image', Jekyll::ImageTag) 116 | 117 | is written as this Hugo shortcode: 118 | 119 | 120 |
121 | {{ with .Get "link"}}{{ end }} 122 | 123 | {{ if .Get "link"}}{{ end }} 124 | {{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}} 125 |
{{ if isset .Params "title" }} 126 | {{ .Get "title" }}{{ end }} 127 | {{ if or (.Get "caption") (.Get "attr")}}

128 | {{ .Get "caption" }} 129 | {{ with .Get "attrlink"}} {{ end }} 130 | {{ .Get "attr" }} 131 | {{ if .Get "attrlink"}} {{ end }} 132 |

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

{{ index .Params "title" }}

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

{{ . }}

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