diff --git a/README.md b/README.md index fd77853ed..7afd97aad 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ and [friends](http://github.com/spf13/hugo/graphs/contributors) in Go. Hugo is a static site generator written in Go. It is optimized for speed, easy use and configurability. Hugo takes a directory with content and -templates and renders them into a full html website. +templates and renders them into a full HTML website. -Hugo makes use of markdown files with front matter for meta data. +Hugo makes use of Markdown files with front matter for meta data. A typical website of moderate size can be rendered in a fraction of a second. A good rule of thumb is that Hugo @@ -26,21 +26,21 @@ kind of website including blogs, tumbles and docs. ## Installing Hugo -Hugo is written in Go with support for Windows, Linux, FreeBSD and OSX. +Hugo is written in Go with support for Windows, Linux, FreeBSD and OS X. The latest release can be found at [hugo releases](https://github.com/spf13/hugo/releases). -We currently build for Windows, Linux, FreeBSD and OS X for x64 -and 386 architectures. +We currently build for Windows, Linux, FreeBSD and OS X for x64 +and i386 architectures. ### Installing Hugo (binary) Installation is very easy. Simply download the appropriate version for your -platform from [hugo releases](https://github.com/spf13/hugo/releases). -Once downloaded it can be run from anywhere. You don't need to install +platform from [Hugo Releases](https://github.com/spf13/hugo/releases). +Once downloaded, it can be run from anywhere. You don't need to install it into a global location. This works well for shared hosts and other systems where you don't have a privileged account. -Ideally you should install it somewhere in your path for easy use. `/usr/local/bin` +Ideally, you should install it somewhere in your path for easy use. `/usr/local/bin` is the most probable location. *The Hugo executable has no external dependencies.* @@ -60,17 +60,17 @@ is the most probable location. cd hugo go get -Because go expects all of your libraries to be found in either $GOROOT or $GOPATH, +Because Go expects all of your libraries to be found in either $GOROOT or $GOPATH, it's helpful to symlink the project to one of the following paths: - * ln -s /path/to/your/hugo $GOPATH/src/github.com/spf13/hugo - * ln -s /path/to/your/hugo $GOROOT/src/pkg/github.com/spf13/hugo + * `ln -s /path/to/your/hugo $GOPATH/src/github.com/spf13/hugo` + * `ln -s /path/to/your/hugo $GOROOT/src/pkg/github.com/spf13/hugo` -#### Get directly from Github: +#### Get directly from GitHub: If you only want to build from source, it's even easier. - go get github.com/spf13/hugo + go get -v github.com/spf13/hugo #### Building Hugo @@ -93,7 +93,7 @@ We welcome your contributions. To make the process as seamless as possible, we * Have test cases for the new code. If you have questions about how to do it, please ask in your pull request. * Run `go fmt` * Squash your commits into a single commit. `git rebase -i`. It's okay to force update your pull request. - * Make sure `go test ./...` passes, and go build completes. Our Travis CI loop will catch most things that are missing. The exception: Windows. We run on windows from time to time, but if you have access please check on a Windows machine too. + * Make sure `go test ./...` passes, and go build completes. Our Travis CI loop will catch most things that are missing. The exception: Windows. We run on Windows from time to time, but if you have access, please check on a Windows machine too. **Complete documentation is available at [Hugo Documentation](http://hugo.spf13.com).** diff --git a/docs/content/content/archetypes.md b/docs/content/content/archetypes.md index 9004542ef..5c0743120 100644 --- a/docs/content/content/archetypes.md +++ b/docs/content/content/archetypes.md @@ -29,9 +29,9 @@ I use ‘tags’ and ‘categories’ for my taxonomies. +++ -## using archetypes +## Using archetypes -If I wanted to create a new post in the `posts` section I would run the following command... +If I wanted to create a new post in the `posts` section, I would run the following command: `hugo new posts/my-new-post.md` @@ -49,7 +49,7 @@ Hugo would create the file with the following contents: ## Using a different front matter format -By default the front matter will be created in the TOML format +By default, the front matter will be created in the TOML format regardless of what format the archetype is using. You can specify a different default format in your config file using @@ -60,15 +60,15 @@ the `MetaDataFormat` directive. Possible values are `toml`, `yaml` and `json`. The following rules apply: -* If an archetype with a filename that matches the content type being created it will be used. -* If no match is found `archetypes/default.md` will be used. -* If neither are present and a theme is in use then within the theme... - * If an archetype with a filename that matches the content type being created it will be used. - * If no match is found `archetypes/default.md` will be used. -* If no archetype files are present then the one that ships with hugo will be used. +* If an archetype with a filename that matches the content type being created, it will be used. +* If no match is found, `archetypes/default.md` will be used. +* If neither are present and a theme is in use, then within the theme: + * If an archetype with a filename that matches the content type being created, it will be used. + * If no match is found, `archetypes/default.md` will be used. +* If no archetype files are present, then the one that ships with Hugo will be used. Hugo provides a simple archetype which sets the title (based on the -file name) and the date based on now(). +file name) and the date based on `now()`. Content type is automatically detected based on the path. You are welcome to declare which type to create using the `--kind` flag during creation. diff --git a/docs/content/content/example.md b/docs/content/content/example.md index d4934871c..ff008308a 100644 --- a/docs/content/content/example.md +++ b/docs/content/content/example.md @@ -13,9 +13,9 @@ title: Example Content File weight: 70 --- -Somethings are better shown than explained. The following is a very basic example of a content file: +Some things are better shown than explained. The following is a very basic example of a content file: -**mysite/project/nitro.md <- http://mysite.com/project/nitro.html** +**mysite/project/nitro.md ← http://mysite.com/project/nitro.html** --- Title: "Nitro : A quick and simple profiler for Go" diff --git a/docs/content/content/front-matter.md b/docs/content/content/front-matter.md index 26fef3b40..c0ad1514c 100644 --- a/docs/content/content/front-matter.md +++ b/docs/content/content/front-matter.md @@ -13,12 +13,13 @@ weight: 20 The front matter is one of the features that gives Hugo its strength. It enables you to include the meta data of the content right with it. Hugo supports a few -different formats each with their own identifying tokens. +different formats, each with their own identifying tokens. -Supported formats:
- **YAML**, identified by '\-\-\-'.
- **TOML**, indentified with '+++'.
- **JSON**, a single JSON object which is surrounded by '{' and '}' each on their own line. +Supported formats: + + * **YAML**, identified by '`---`'. + * **TOML**, identified with '`+++`'. + * **JSON**, a single JSON object which is surrounded by '`{`' and '`}`', each on their own line. ### YAML Example @@ -68,7 +69,7 @@ Supported formats:
There are a few predefined variables that Hugo is aware of and utilizes. The user can also create any variable they want to. These will be placed into the `.Params` variable available to the templates. -Field names are always normalized to lowercase (eg. `camelCase: true` is available as `.Params.camelcase`). +Field names are always normalized to lowercase (e.g. `camelCase: true` is available as `.Params.camelcase`). ### Required diff --git a/docs/content/content/ordering.md b/docs/content/content/ordering.md index 009f6101a..5190d777b 100644 --- a/docs/content/content/ordering.md +++ b/docs/content/content/ordering.md @@ -13,15 +13,15 @@ weight: 60 Hugo provides you with all the flexibility you need to organize how your content is ordered. By default, content is ordered by weight, then by date with the most -recent date first, but alternative sorting (by title and linktitle) is -also available. The order the content will appear will be specified in +recent date first, but alternative sorting (by `title` and `linktitle`) is +also available. The order the content would appear is specified in the [list template](/templates/list). -_Both the date and weight fields are optional._ +_Both the `date` and `weight` fields are optional._ Unweighted pages appear at the end of the list. If no weights are provided (or -if weights are the same) date will be used to sort. If neither are provided -content will be ordered based on how it's read off the disk and no order is +if weights are the same), `date` will be used to sort. If neither is provided, +content will be ordered based on how it's read off the disk, and no order is guaranteed. ## Assigning weight to content @@ -36,4 +36,4 @@ guaranteed. ## Ordering Content Within Taxonomies -Please see the [Taxonomy Ordering Documentation](/taxonomies/ordering/) +Please see the [Taxonomy Ordering Documentation](/taxonomies/ordering/). diff --git a/docs/content/content/types.md b/docs/content/content/types.md index 2e8a3c8ce..ef259d2ff 100644 --- a/docs/content/content/types.md +++ b/docs/content/content/types.md @@ -14,7 +14,7 @@ Hugo has full support for different types of content. A content type can have a unique set of meta data, template and can be automatically created by the new command through using content [archetypes](/content/archetypes). -A good example of when multiple types are needed is to look at Tumblr. A piece +A good example of when multiple types are needed is to look at [Tumblr](https://www.tumblr.com/). A piece of content could be a photo, quote or post, each with different meta data and rendered differently. @@ -22,7 +22,7 @@ rendered differently. Hugo assumes that your site will be organized into [sections](/content/sections) and each section will use the corresponding type. If you are taking advantage of -this then each new piece of content you place into a section will automatically +this, then each new piece of content you place into a section will automatically inherit the type. Alternatively you can set the type in the meta data under the key "type". @@ -34,11 +34,11 @@ Hugo has the ability to create a new content file and populate the front matter with the data set corresponding to that type. Hugo does this by utilizing [archetypes](/content/archetypes). -To create a new piece of content use: +To create a new piece of content, use: hugo new relative/path/to/content.md -For example if I wanted to create a new post inside the post section I would type: +For example, if I wanted to create a new post inside the post section, I would type: hugo new post/my-newest-post.md @@ -53,13 +53,13 @@ whenever a specific file is not present. *Remember, all of the following are optional:* ### Create Type Directory -Create a directory with the name of the type in layouts.Type is always singular. *Eg /layouts/post*. +Create a directory with the name of the type in layouts. Type is always singular. *Eg /layouts/post*. ### Create single template Create a file called single.html inside your directory. *Eg /layouts/post/single.html*. ### Create list template -Create a file called list.html inside your directory *Eg /layouts/post/list.html*. +Create a file called list.html inside your directory. *Eg /layouts/post/list.html*. ### Create views Many sites support rendering content in a few different ways, for diff --git a/docs/content/extras/aliases.md b/docs/content/extras/aliases.md index 936666983..1822135e2 100644 --- a/docs/content/extras/aliases.md +++ b/docs/content/extras/aliases.md @@ -13,7 +13,7 @@ title: Aliases weight: 10 --- -For people migrating existing published content to Hugo there's a good chance +For people migrating existing published content to Hugo, there's a good chance you need a mechanism to handle redirecting old URLs. Luckily, this can be handled easily with aliases in Hugo. @@ -27,7 +27,7 @@ Luckily, this can be handled easily with aliases in Hugo. - /2010/even-earlier-url.html --- -Now when you go to any of the aliases locations they +Now when you go to any of the aliases locations, they will redirect to the page. ## Important Behaviors diff --git a/docs/content/extras/comments.md b/docs/content/extras/comments.md index 2b8cce7c4..9f7040f86 100644 --- a/docs/content/extras/comments.md +++ b/docs/content/extras/comments.md @@ -33,7 +33,7 @@ Simply include the following line where you want your comments to appear ## Configuring Disqus -That template requires you to set a single value in your site config file, eg. config.yaml. +That template requires you to set a single value in your site config file, e.g. config.yaml. disqusShortname = "XYW" @@ -73,7 +73,7 @@ Notice that there is a simple if statement that detects when you are running on Now reference the partial template from your page template: - {{ template "partials/disqus.html" . }} + {{ partial "disqus.html" . }} # Alternatives diff --git a/docs/content/extras/highlighting.md b/docs/content/extras/highlighting.md index 89391f6f6..7c5ce3fa3 100644 --- a/docs/content/extras/highlighting.md +++ b/docs/content/extras/highlighting.md @@ -15,13 +15,13 @@ Hugo provides the ability for you to highlight source code in two different ways — either pre-processed server side from your content, or to defer the processing to the client side, using a JavaScript library. The advantage of server side is that it doesn’t depend on a JavaScript library and consequently -works very well when read from an rss feed. The advantage of client side is that +works very well when read from an RSS feed. The advantage of client side is that it doesn’t cost anything when building your site and some of the highlighting -scripts available cover more languages than pygments does. +scripts available cover more languages than Pygments does. For the pre-processed approach, Highlighting is performed by an external -python based program called [pygments](http://pygments.org) and is triggered -via an embedded shortcode. If pygments is absent from the path, it will +Python-based program called [Pygments](http://pygments.org) and is triggered +via an embedded shortcode. If Pygments is absent from the path, it will silently simply pass the content along unhighlighted. ## Server-side @@ -83,7 +83,7 @@ a library and a corresponding theme. Some popular libraries are: This example uses the popular [Highlight.js] library, hosted by [Yandex], a popular Russian search engine. -In your `./layouts/chrome/` folder, depending on your specific theme, there +In your `./layouts/partials/` (or `./layouts/chrome/`) folder, depending on your specific theme, there will be a snippet that will be included in every generated HTML page, such as `header.html` or `header.includes.html`. Simply add: @@ -98,4 +98,4 @@ You can of course use your own copy of these files, typically in `./static/`. [Google Prettify]: https://code.google.com/p/google-code-prettify/ [Yandex]: http://yandex.ru/ -Please see individual libraries documentation for how to implement the JavaScript based libraries. +Please see individual libraries documentation for how to implement the JavaScript-based libraries. diff --git a/docs/content/extras/menus.md b/docs/content/extras/menus.md index 6e06f4e42..3647e3977 100644 --- a/docs/content/extras/menus.md +++ b/docs/content/extras/menus.md @@ -22,7 +22,7 @@ Some of the features of Hugo Menus: ## What is a menu? A menus is a named array of menu entries accessible on the site under -`.Site.Menus` by name. For example if I have a menu called `main` I would +`.Site.Menus` by name. For example, if I have a menu called `main`, I would access it via `.Site.Menus.main`. A menu entry has the following properties: @@ -89,7 +89,7 @@ available. You can also add entries to menus that aren’t attached to a piece of content. This takes place in the site wide [config file](http://hugo.spf13.com/overview/configuration). -Here’s an example (in toml): +Here’s an example (in TOML): [[menu.main]] name = "about hugo" @@ -101,7 +101,7 @@ Here’s an example (in toml): pre = "" weight = -100 -Here’s an example (in yaml): +Here’s an example (in YAML): --- menu: diff --git a/docs/content/extras/permalinks.md b/docs/content/extras/permalinks.md index 4018b37ed..ed95612e0 100644 --- a/docs/content/extras/permalinks.md +++ b/docs/content/extras/permalinks.md @@ -21,7 +21,7 @@ internal "canonical" location, such that template references to `.RelPermalink` will honour the adjustments made as a result of the mappings in this option. -For instance, if one of your sections is called `post` and you want to adjust +For instance, if one of your sections is called `post`, and you want to adjust the canonical path to be hierarchical based on the year and month, then you might use: @@ -36,18 +36,18 @@ A file named `content/post/sample-entry` which contains a line appearing at `public/2013/11/sample-entry/index.html` and be reachable via the URL . -The following is a list of values that can be used in a permalink definition, -all references to time are dependent on the content's date. +The following is a list of values that can be used in a permalink definition. +All references to time are dependent on the content's date. -**:year** the 4 digit year
-**:month** the 2 digit month
-**:monthname** the name of the month
-**:day** the 2 digit day
-**:weekday** the 1 digit day of the week (Sunday = 0)
-**:weekdayname** the name of the day of the week
-**:yearday** the 1-3 digit day of the year
-**:section** the content's section
-**:title** the content's title
-**:slug** the content's slug (or title if no slug)
-**:filename** the content's filename (without extension)
+ * **:year** the 4-digit year + * **:month** the 2-digit month + * **:monthname** the name of the month + * **:day** the 2-digit day + * **:weekday** the 1-digit day of the week (Sunday = 0) + * **:weekdayname** the name of the day of the week + * **:yearday** the 1- to 3-digit day of the year + * **:section** the content's section + * **:title** the content's title + * **:slug** the content's slug (or title if no slug) + * **:filename** the content's filename (without extension) diff --git a/docs/content/extras/toc.md b/docs/content/extras/toc.md index bd21545f7..68376e117 100644 --- a/docs/content/extras/toc.md +++ b/docs/content/extras/toc.md @@ -26,12 +26,12 @@ Hugo will take this Markdown and create a table of contents stored in the This is example code of a [single.html template](/layout/content). - {{ template "partials/header.html" . }} + {{ partial "header.html" . }}
{{ .TableOfContents }}

{{ .Title }}

{{ .Content }} - {{ template "partials/footer.html" . }} + {{ partial "footer.html" . }} diff --git a/docs/content/overview/configuration.md b/docs/content/overview/configuration.md index 4a499ca63..3b52c43ca 100644 --- a/docs/content/overview/configuration.md +++ b/docs/content/overview/configuration.md @@ -14,11 +14,11 @@ weight: 40 --- The directory structure and templates provide the majority of the -configuration for a site. In fact a config file isn't even needed for many +configuration for a site. In fact, a config file isn't even needed for many websites since the defaults follow commonly used patterns. Hugo expects to find the config file in the root of the source directory and -will look there first for a `config.toml` file. If none is present it will +will look there first for a `config.toml` file. If none is present, it will then look for a `config.yaml` file, followed by a `config.json` file. The config file is a site-wide config. The config file provides directions to diff --git a/docs/content/overview/introduction.md b/docs/content/overview/introduction.md index 0d409e332..4ac2ee337 100644 --- a/docs/content/overview/introduction.md +++ b/docs/content/overview/introduction.md @@ -12,17 +12,17 @@ weight: 5 ## What is Hugo? Hugo is a general-purpose website framework. Technically speaking, Hugo is -a static site generator. This means that unlike systems like WordPress, -Ghost and Drupal which run on your web server expensively building a page +a static site generator. This means that, unlike systems like WordPress, +Ghost and Drupal, which run on your web server expensively building a page every time a visitor requests one, Hugo does the building when you create your content. Since websites are viewed far more often then they are edited, Hugo is optimized for website viewing while providing a great writing experience. Sites built with Hugo are extremely fast and very secure. Hugo sites can -be hosted anywhere including Heroku, GoDaddy, GitHub pages, S3 -and Cloudfront and work well with CDNs. Hugo sites run without dependencies -on expensive run times like Ruby, Python or PHP and without dependencies +be hosted anywhere, including Heroku, GoDaddy, GitHub Pages, Amazon S3 +and CloudFront, and work well with CDNs. Hugo sites run without dependencies +on expensive runtimes like Ruby, Python or PHP and without dependencies on any databases. We think of Hugo as the ideal website creation tool. With nearly instant @@ -32,7 +32,7 @@ designing websites, but also very useful when creating content. ## What does Hugo do? -In technical terms Hugo takes a source directory of Markdown files and +In technical terms, Hugo takes a source directory of Markdown files and templates and uses these as input to create a complete website. Hugo boasts the following features: @@ -77,7 +77,7 @@ Hugo boasts the following features: * Support for Go and [Amber](https://github.com/eknkc/amber) templates * Syntax [highlighting](/extras/highlighting) powered by pygments -See what's coming next in the [roadmap](/meta/roadmap) +See what's coming next in the [roadmap](/meta/roadmap). ## Who should use Hugo? @@ -94,23 +94,23 @@ pages. ## Why did you write Hugo? -I wrote Hugo ultimately for a few reasons. First I was disappointed with +I wrote Hugo ultimately for a few reasons. First, I was disappointed with WordPress, my then website solution. It rendered slowly. I couldn't create content as efficiently as I wanted to and needed to be online to write posts. The constant security updates and the horror stories of people's hacked blogs. I hated how content was written in HTML instead of the much -simpler Markdown. Overall I felt like it got in my way more than it helped -my from writing great content. +simpler Markdown. Overall, I felt like it got in my way more than it helped +me from writing great content. I looked at existing static site generators like Jekyll, Middleman and nanoc. All had complicated dependencies to install and took far longer to render my blog with hundreds of posts than I felt was acceptable. I wanted a framework to be able to get rapid feedback while making changes to the -templates and the 5+-minute render times was just too slow. In general +templates, and the 5+-minute render times was just too slow. In general, they were also very blog minded and didn't have the ability to have different content types and flexible URLs. -I wanted to develop a fast and full featured website framework without +I wanted to develop a fast and full-featured website framework without dependencies. The Go language seemed to have all of the features I needed in a language. I began developing Hugo in Go and fell in love with the language. I hope you will enjoy using (and contributing to) Hugo as much diff --git a/docs/content/overview/source-directory.md b/docs/content/overview/source-directory.md index ea0623e4b..0c3db7f3e 100644 --- a/docs/content/overview/source-directory.md +++ b/docs/content/overview/source-directory.md @@ -25,7 +25,7 @@ The top level of a source directory will typically have the following elements: ▸ themes/ config.toml -Learn more about the different directories and what their purpose is +Learn more about the different directories and what their purpose is: * [config](/overview/configuration) * [archetypes](/content/archetypes) @@ -85,6 +85,6 @@ An example directory may look like: This directory structure tells us a lot about this site: -1. the website intends to have two different types of content, posts and quotes. -2. It will also apply two different indexes to that content, categories and tags. -3. It will be displaying content in 3 different views, a list, a summary and a full page view. +1. The website intends to have two different types of content: posts and quotes. +2. It will also apply two different indexes to that content: categories and tags. +3. It will be displaying content in 3 different views: a list, a summary and a full page view. diff --git a/docs/content/overview/usage.md b/docs/content/overview/usage.md index 1e65a6b56..bdebad445 100644 --- a/docs/content/overview/usage.md +++ b/docs/content/overview/usage.md @@ -54,7 +54,7 @@ Make sure either hugo is in your path or provide a path to it. Use "hugo help [command]" for more information about that command. -## Common Usage Example: +## Common Usage Example The most common use is probably to run hugo with your current directory being the input directory. diff --git a/docs/content/templates/404.md b/docs/content/templates/404.md index dcf0cab34..1591782fc 100644 --- a/docs/content/templates/404.md +++ b/docs/content/templates/404.md @@ -28,8 +28,8 @@ all site content accessible from .Data.Pages ## 404.html This is a basic example of a 404.html template: - {{ template "chrome/header.html" . }} - {{ template "chrome/subheader.html" . }} + {{ partial "header.html" . }} + {{ partial "subheader.html" . }}
@@ -37,5 +37,5 @@ This is a basic example of a 404.html template:
- {{ template "chrome/footer.html" }} + {{ partial "footer.html" }} diff --git a/docs/content/templates/content.md b/docs/content/templates/content.md index 30778735a..14d613cb8 100644 --- a/docs/content/templates/content.md +++ b/docs/content/templates/content.md @@ -12,22 +12,22 @@ title: Single Content Template weight: 30 --- -The primary view of content in hugo is the single view. Hugo for every -markdown file provided hugo will render it with a single template. +The primary view of content in Hugo is the single view. Hugo, for every +Markdown file provided, will render it with a single template. ## Which Template will be rendered? Hugo uses a set of rules to figure out which template to use when rendering a specific page. -Hugo will use the following prioritized list. If a file isn’t present -than the next one in the list will be used. This enables you to craft +Hugo will use the following prioritized list. If a file isn’t present, +then the next one in the list will be used. This enables you to craft specific layouts when you want to without creating more templates -then necessary. For most sites only the \_default file at the end of +than necessary. For most sites only the \_default file at the end of the list will be needed. Users can specify the `type` and `layout` in the [front-matter](/content/front-matter). `Section` -is determined based on the content file’s location. If `type` is provide +is determined based on the content file’s location. If `type` is provide, it will be used instead of `section`. ### Single @@ -50,7 +50,7 @@ a default content type. The default content template to be used in the event that a specific template has not been provided for that type. The default type works the -same as the other types but the directory must be called "\_default". +same as the other types, but the directory must be called "\_default". ▾ layouts/ ▾ _default/ diff --git a/docs/content/templates/functions.md b/docs/content/templates/functions.md index adf7b2d85..9f17ba8fe 100644 --- a/docs/content/templates/functions.md +++ b/docs/content/templates/functions.md @@ -28,19 +28,19 @@ Go documentation for the built-in functions can be found [here](http://golang.or Return true if the parameter is set. Takes either a slice, array or channel and an index or a map and a key as input. -eg. {{ if isset .Params "project_url" }} {{ index .Params "project_url" }}{{ end }} +e.g. {{ if isset .Params "project_url" }} {{ index .Params "project_url" }}{{ end }} ### echoParam If parameter is set, then echo it. -eg. {{echoParam .Params "project_url" }} +e.g. {{echoParam .Params "project_url" }} ### first Slices an array to only the first X elements. Works on [lists](/templates/list/), [taxonomies](/taxonomies/displaying/), [terms](/templates/terms/), [groups](/templates/list/) -eg. +e.g. {{ range first 10 .Data.Pages }} {{ .Render "summary"}} {{ end }} @@ -50,7 +50,7 @@ Filters an array to only elements containing a matching value for a given field. Works on [lists](/templates/list/), [taxonomies](/taxonomies/displaying/), [terms](/templates/terms/), [groups](/templates/list/) -eg. +e.g. {{ range where .Data.Pages "Section" "post" }} {{ .Content}} @@ -58,7 +58,7 @@ eg. *where and first can be stacked* -eg. +e.g. {{ range first 5 (where .Data.Pages "Section" "post") }} {{ .Content}} @@ -70,61 +70,61 @@ eg. ### add Adds two integers. -eg {{add 1 2}} -> 3 +e.g. {{add 1 2}} → 3 ### sub Subtracts two integers. -eg {{sub 3 2}} -> 1 +e.g. {{sub 3 2}} → 1 ### div Divides two integers. -eg {{div 6 3}} -> 2 +e.g. {{div 6 3}} → 2 ### mul Multiplies two integers. -eg {{mul 2 3}} -> 6 +e.g. {{mul 2 3}} → 6 ### mod Modulus of two integers. -eg {{mod 15 3}} -> 0 +e.g. {{mod 15 3}} → 0 ### modBool Boolean of modulus of two integers. true if modulus is 0. -eg {{modBool 15 3}} -> true +e.g. {{modBool 15 3}} → true ## Strings ### urlize -Takes a string and sanitizes it for usage in urls, converts spaces to "-". +Takes a string and sanitizes it for usage in URLs, converts spaces to "-". -eg. <a href="/tags/{{ . | urlize }}">{{ . }}</a> +e.g. <a href="/tags/{{ . | urlize }}">{{ . }}</a> ### safeHtml -Declares the provided string as "safe" so go templates will not filter it. +Declares the provided string as "safe" so Go templates will not filter it. -eg. {{ .Params.CopyrightHTML | safeHtml }} +e.g. {{ .Params.CopyrightHTML | safeHtml }} ### lower Convert all characters in string to lowercase. -eg {{lower "BatMan"}} -> "batman" +e.g. {{lower "BatMan"}} → "batman" ### upper Convert all characters in string to uppercase. -eg {{upper "BatMan"}} -> "BATMAN" +e.g. {{upper "BatMan"}} → "BATMAN" ### title Convert all characters in string to titlecase. -eg {{title "BatMan"}} -> "Batman" +e.g. {{title "BatMan"}} → "Batman" ### highlight -Take a string of code and a language, uses pygments to return the syntax -highlighted code in html. Used in the [highlight shortcode](/extras/highlighting). +Take a string of code and a language, uses Pygments to return the syntax +highlighted code in HTML. Used in the [highlight shortcode](/extras/highlighting). diff --git a/docs/content/templates/go-templates.md b/docs/content/templates/go-templates.md index 23f91c906..0ee6624fd 100644 --- a/docs/content/templates/go-templates.md +++ b/docs/content/templates/go-templates.md @@ -34,8 +34,8 @@ details can be found in the [Go docs][gohtmltemplate]. ## Basic Syntax -Go lang templates are html files with the addition of variables and -functions. +Go lang templates are HTML files with the addition of variables and +functions. **Go variables and functions are accessible within {{ }}** @@ -45,7 +45,7 @@ Accessing a predefined variable "foo": **Parameters are separated using spaces** -Calling the add function with input of 1, 2: +Calling the `add` function with input of 1, 2: {{ add 1 2 }} @@ -62,7 +62,7 @@ Accessing the Page Parameter "bar" ## Variables -Each Go template has a struct (object) made available to it. In Hugo each +Each Go template has a struct (object) made available to it. In Hugo, each template is passed either a page or a node struct depending on which type of page you are rendering. More details are available on the [variables](/layout/variables) page. @@ -79,13 +79,13 @@ Variables can also be defined and referenced. ## Functions -Go template ship with a few functions which provide basic functionality. The go +Go template ships with a few functions which provide basic functionality. The Go template system also provides a mechanism for applications to extend the available functions with their own. [Hugo template functions](/layout/functions) provide some additional functionality we believe are useful for building websites. Functions are called by using their name followed by the required parameters separated by spaces. Template -functions cannot be added without recompiling hugo. +functions cannot be added without recompiling Hugo. **Example:** @@ -93,86 +93,91 @@ functions cannot be added without recompiling hugo. ## Includes -When including another template you will pass to it the data it will be -able to access. To pass along the current context please remember to +When including another template, you will pass to it the data it will be +able to access. To pass along the current context, please remember to include a trailing dot. The templates location will always be starting at the /layout/ directory within Hugo. **Example:** - {{ template "chrome/header.html" . }} + {{ template "partials/header.html" . }} + +And, starting with Hugo v0.12, you may also use the `partial` call +for [partial templates](/templates/partials/): + + {{ partial "header.html" . }} ## Logic Go templates provide the most basic iteration and conditional logic. -### Iteration +### Iteration -Just like in Go, the Go templates make heavy use of range to iterate over +Just like in Go, the Go templates make heavy use of `range` to iterate over a map, array or slice. The following are different examples of how to use range. **Example 1: Using Context** - {{ range array }} + {{ range array }} {{ . }} {{ end }} **Example 2: Declaring value variable name** - {{range $element := array}} - {{ $element }} + {{range $element := array}} + {{ $element }} {{ end }} **Example 2: Declaring key and value variable name** {{range $index, $element := array}} - {{ $index }} - {{ $element }} + {{ $index }} + {{ $element }} {{ end }} -### Conditionals +### Conditionals -If, else, with, or, & and provide the framework for handling conditional -logic in Go Templates. Like range, each statement is closed with `end`. +`if`, `else`, `with`, `or` & `and` provide the framework for handling conditional +logic in Go Templates. Like `range`, each statement is closed with `end`. -Go Templates treat the following values as false: +Go Templates treat the following values as false: * false -* 0 +* 0 * any array, slice, map, or string of length zero -**Example 1: If** +**Example 1: `if`** {{ if isset .Params "title" }}

{{ index .Params "title" }}

{{ end }} -**Example 2: If -> Else** +**Example 2: `if` … `else`** - {{ if isset .Params "alt" }} + {{ if isset .Params "alt" }} {{ index .Params "alt" }} {{else}} {{ index .Params "caption" }} {{ end }} -**Example 3: And & Or** +**Example 3: `and` & `or`** {{ if and (or (isset .Params "title") (isset .Params "caption")) (isset .Params "attr")}} -**Example 4: With** +**Example 4: `with`** -An alternative way of writing "if" and then referencing the same value -is to use "with" instead. With rebinds the context `.` within its scope, +An alternative way of writing "`if`" and then referencing the same value +is to use "`with`" instead. `with` rebinds the context `.` within its scope, and skips the block if the variable is absent. The first example above could be simplified as: {{ with .Params.title }}

{{ . }}

{{ end }} -**Example 5: If -> Else If** +**Example 5: `if` … `else if`** - {{ if isset .Params "alt" }} + {{ if isset .Params "alt" }} {{ index .Params "alt" }} {{ else if isset .Params "caption" }} {{ index .Params "caption" }} @@ -182,48 +187,48 @@ The first example above could be simplified as: One of the most powerful components of Go templates is the ability to stack actions one after another. This is done by using pipes. Borrowed -from unix pipes, the concept is simple, each pipeline's output becomes the -input of the following pipe. +from Unix pipes, the concept is simple, each pipeline's output becomes the +input of the following pipe. Because of the very simple syntax of Go templates, the pipe is essential to being able to chain together function calls. One limitation of the pipes is that they only can work with a single value and that value -becomes the last parameter of the next pipeline. +becomes the last parameter of the next pipeline. A few simple examples should help convey how to use the pipe. -**Example 1 :** +**Example 1:** {{ if eq 1 1 }} Same {{ end }} -is the same as +is the same as {{ eq 1 1 | if }} Same {{ end }} It does look odd to place the if at the end, but it does provide a good illustration of how to use the pipes. -**Example 2 :** +**Example 2:** {{ index .Params "disqus_url" | html }} Access the page parameter called "disqus_url" and escape the HTML. -**Example 3 :** +**Example 3:** {{ if or (or (isset .Params "title") (isset .Params "caption")) (isset .Params "attr")}} Stuff Here {{ end }} -Could be rewritten as +Could be rewritten as {{ isset .Params "caption" | or isset .Params "title" | or isset .Params "attr" | if }} - Stuff Here + Stuff Here {{ end }} ### Internet Explorer conditional comments using Pipes -By default Go Templates remove HTML comments from output. This has the unfortunate side effect of removing Internet Explorer conditional comments. As a workaround, use something like this: +By default, Go Templates remove HTML comments from output. This has the unfortunate side effect of removing Internet Explorer conditional comments. As a workaround, use something like this: {{ "