Skip to content

Commit

Permalink
Add render template hooks for links and images
Browse files Browse the repository at this point in the history
This commit also revises the change detection for templates used by content files in server mode.

Fixes gohugoio#6545
Fixes gohugoio#4663
Closes gohugoio#6043
  • Loading branch information
bep committed Dec 18, 2019
1 parent 92c7f7a commit 052ba99
Show file tree
Hide file tree
Showing 93 changed files with 2,257 additions and 578 deletions.
4 changes: 4 additions & 0 deletions deps/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ func (d Deps) ForLanguage(cfg DepsCfg, onCreated func(d *Deps) error) (*Deps, er
return nil, err
}

if err != nil {
return nil, err
}

d.Site = cfg.Site

// The resource cache is global so reuse.
Expand Down
8 changes: 4 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ Note that this repository contains solely the documentation for Hugo. For contri

*Pull requests shall **only** contain changes to the actual documentation. However, changes on the code base of Hugo **and** the documentation shall be a single, atomic pull request in the [hugo](https://github.com/gohugoio/hugo) repository.*

Spelling fixes are most welcomed, and if you want to contribute longer sections to the documentation, it would be great if you had these in mind when writing:
Spelling fixes are most welcomed, and if you want to contribute longer sections to the documentation, it would be great if you had the following criteria in mind when writing:

* Short is good. People go to the library to read novels. If there is more than one way to _do a thing_ in Hugo, describe the current _best practice_ (avoid "… but you can also do …" and "… in older versions of Hugo you had to …".
* For examples, try to find short snippets that teaches people about the concept. If the example is also useful as-is (copy and paste), then great, but don't list long and similar examples just so people can use them on their sites.
* Hugo has users from all over the world, so an easy to understand and [simple English](https://simple.wikipedia.org/wiki/Basic_English) is good.
* For example, try to find short snippets that teaches people about the concept. If the example is also useful as-is (copy and paste), then great. Don't list long and similar examples just so people can use them on their sites.
* Hugo has users from all over the world, so easy to understand and [simple English](https://simple.wikipedia.org/wiki/Basic_English) is good.

## Branches

* The `master` branch is where the site is automatically built from, and is the place to put changes relevant to the current Hugo version.
* The `next` branch is where we store changes that is related to the next Hugo release. This can be previewed here: https://next--gohugoio.netlify.com/
* The `next` branch is where we store changes that are related to the next Hugo release. This can be previewed here: https://next--gohugoio.netlify.com/

## Build

Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sections:
link: templates/
color_classes: bg-primary-color-light black
image: /images/home-page-templating-example.png
copy: "Hugo's Go-based templating provides just the right amount of logic to build anything from the simple to complex. If you prefer Jade/Pug-like syntax, you can also use Amber, Ace, or any combination of the three."
copy: "Hugo's Go-based templating provides just the right amount of logic to build anything from the simple to complex."
---

Hugo is one of the most popular open-source static site generators. With its amazing speed and flexibility, Hugo makes building websites fun again.
3 changes: 2 additions & 1 deletion docs/content/en/content-management/image-processing/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ Tags:
{{ range $k, $v := .Tags }}
TAG: {{ $k }}: {{ $v }}
{{ end }}
{{ end }}
```

#### Exif fields

Data
Date
: "photo taken" date/time

Lat
Expand Down
18 changes: 5 additions & 13 deletions docs/content/en/content-management/syntax-highlighting.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,9 @@ func GetTitleFunc(style string) func(s string) string {
case "go":
return strings.Title
case "chicago":
tc := transform.NewTitleConverter(transform.ChicagoStyle)
return tc.Title
return transform.NewTitleConverter(transform.ChicagoStyle)
default:
tc := transform.NewTitleConverter(transform.APStyle)
return tc.Title
return transform.NewTitleConverter(transform.APStyle)
}
}
{{< / highlight >}}
Expand All @@ -93,14 +91,10 @@ See [Highlight](/functions/highlight/).

Highlighting in code fences is enabled by default.{{< new-in "0.60.0" >}}

````
```go-html-template{hl_lines=[3,"5-6"],linenos=true}
```
````

````
```go {linenos=table,hl_lines=[8,"15-17"],linenostart=199}
// ... code
```
````


Expand All @@ -122,11 +116,9 @@ func GetTitleFunc(style string) func(s string) string {
case "go":
return strings.Title
case "chicago":
tc := transform.NewTitleConverter(transform.ChicagoStyle)
return tc.Title
return transform.NewTitleConverter(transform.ChicagoStyle)
default:
tc := transform.NewTitleConverter(transform.APStyle)
return tc.Title
return transform.NewTitleConverter(transform.APStyle)
}
}
```
Expand Down
8 changes: 6 additions & 2 deletions docs/content/en/content-management/toc.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ toc: true
---

{{% note "TOC Heading Levels are Fixed" %}}
Currently, the `{{.TableOfContents}}` [page variable](/variables/page/) does not allow you to specify which heading levels you want the TOC to render. [See the related GitHub discussion (#1778)](https://github.com/gohugoio/hugo/issues/1778). As such, the resulting `<nav id="TableOfContents"><ul></ul></nav>` is going to start at `<h1>` when pulling from `{{.Content}}`.

Previously, there was no out-of-the-box way to specify which heading levels you want the TOC to render. [See the related GitHub discussion (#1778)](https://github.com/gohugoio/hugo/issues/1778). As such, the resulting `<nav id="TableOfContents"><ul></ul></nav>` was going to start at `<h1>` when pulling from `{{.Content}}`.

Hugo [v0.60.0](https://github.com/gohugoio/hugo/releases/tag/v0.60.0) made a switch to [Goldmark](https://github.com/yuin/goldmark/) as the default library for Markdown which has improved and configurable implementation of TOC. Take a look at [how to configure TOC](/getting-started/configuration-markup/#table-of-contents) for Goldmark renderer.

{{% /note %}}

## Usage
Expand All @@ -43,7 +47,7 @@ A collection of textile samples lay spread out on the table - Samsa was a travel

Hugo will take this Markdown and create a table of contents from `## Introduction`, `## My Heading`, and `### My Subheading` and then store it in the [page variable][pagevars]`.TableOfContents`.

The built-in `.TableOfContents` variables outputs a `<nav id="TableOfContents">` element with a child `<ul>`, whose child `<li>` elements begin with any `<h1>`'s (i.e., `#` in markdown) inside your content.'
The built-in `.TableOfContents` variables outputs a `<nav id="TableOfContents">` element with a child `<ul>`, whose child `<li>` elements begin with appropriate HTML headings. See [the available settings](/getting-started/configuration-markup/#table-of-contents) to configure what heading levels you want to include in TOC.

{{% note "Table of contents not available for MMark" %}}
Hugo documents created in the [MMark](/content-management/formats/#mmark) Markdown dialect do not currently display TOCs. TOCs are, however, compatible with all other supported Markdown formats.
Expand Down
3 changes: 2 additions & 1 deletion docs/content/en/getting-started/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ aliases: [/overview/introduction/]
toc: false
---

If this is your first time using Hugo and you've [already installed Hugo on your machine][installed], we recommend the [quick start][].
If this is your first time using Hugo and you've [already installed Hugo on your machine][installed], we recommend the [quick start][]. You can also use [external learning resources][] to learn Hugo.

[installed]: /getting-started/installing/
[quick start]: /getting-started/quick-start/
[external learning resources]: /getting-started/external-learning-resources/
4 changes: 2 additions & 2 deletions docs/content/en/getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ To set config params, prefix the name with `HUGO_PARAMS_`
Test and document setting params via JSON env var.
{{< /todo >}}

## Ignore Files When Rendering
## Ignore Content Files When Rendering

The following statement inside `./config.toml` will cause Hugo to ignore files ending with `.foo` and `.boo` when rendering:
The following statement inside `./config.toml` will cause Hugo to ignore content files ending with `.foo` and `.boo` when rendering:

```
ignoreFiles = [ "\\.foo$", "\\.boo$" ]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: External Learning Resources
linktitle: External Learning Resources
description: A list of tutorials and books on Hugo.
date: 2019-10-20
publishdate: 2019-10-20
lastmod: 2019-10-20
keywords: [books,tutorials,learning,usage]
menu:
docs:
parent: "getting-started"
weight: 70
weight: 70
sections_weight: 70
draft: false
toc: false
---

## Books
### Hugo In Action
[![Hugo In Action](hia.jpg)](https://www.manning.com/books/hugo-in-action)

Hugo in Action is a step-by-step guide to using Hugo to create static websites. Working with a complete example website and source code samples, you’ll learn how to build and host a low-maintenance, high-performance site that will wow your users and stay stable without relying on a third-party server.

[Hugo In Action Home Page](https://www.manning.com/books/hugo-in-action)

## Video tutorials
### Video Playlist by Mike Dane
Mike Dane expains the various features of via dedicated tutorials on [Youtube](https://www.youtube.com/watch?list=PLLAZ4kZ9dFpOnyRlyS-liKL5ReHDcj4G3&v=qtIqKaDlqXo).
2 changes: 2 additions & 0 deletions docs/content/en/getting-started/installing.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,8 @@ Hugo installed via Snap can write only inside the user’s `$HOME` directory---a

This installs the "extended" Sass/SCSS version.

This option is not recommended because the Hugo in Linux package managers for Debian and Ubuntu is usually a few versions behind as described [here](https://github.com/gcushen/hugo-academic/issues/703)

### Arch Linux

You can also install Hugo from the Arch Linux [community](https://www.archlinux.org/packages/community/x86_64/hugo/) repository. Applies also to derivatives such as Manjaro.
Expand Down
4 changes: 3 additions & 1 deletion docs/content/en/getting-started/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ toc: true
{{% note %}}
This quick start uses `macOS` in the examples. For instructions about how to install Hugo on other operating systems, see [install](/getting-started/installing).

It is recommended to have [Git](https://git-scm.com/downloads) installed to run this tutorial.
It is recommended to have [Git installed](https://git-scm.com/downloads) to run this tutorial.

For other approaches learning Hugo like book or a video tutorial refer to the [external learning resources](/getting-started/external-learning-resources/) page.
{{% /note %}}


Expand Down
6 changes: 3 additions & 3 deletions docs/content/en/hosting-and-deployment/hugo-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ cloudFrontDistributionID = <ID>
# Samples:
[[deployment.matchers]]
# Cache static assets for 20 years.
# Cache static assets for 1 year.
pattern = "^.+\\.(js|css|svg|ttf)$"
cacheControl = "max-age=630720000, no-transform, public"
cacheControl = "max-age=31536000, no-transform, public"
gzip = true
[[deployment.matchers]]
pattern = "^.+\\.(png|jpg)$"
cacheControl = "max-age=630720000, no-transform, public"
cacheControl = "max-age=31536000, no-transform, public"
gzip = false
[[deployment.matchers]]
Expand Down
4 changes: 2 additions & 2 deletions docs/content/en/hugo-modules/use-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ aliases: [/themes/usage/,/themes/installing/,/installing-and-using-themes/]
toc: true
---

## Prerequisites
## Prerequisite

{{% gomodules-info %}}
{{< gomodules-info >}}



Expand Down
15 changes: 12 additions & 3 deletions docs/content/en/news/0.60.0-relnotes/index.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@

---
date: 2019-11-27
title: "0.60.0"
description: "0.60.0"
title: "Now CommonMark Compliant!"
description: "Goldmark -- CommonMark compliant, GitHub flavored, fast and flexible -- is the new default library for Markdown in Hugo."
categories: ["Releases"]
---

[Goldmark](https://github.com/yuin/goldmark/) by [@yuin](https://github.com/yuin) is now the new default library used for Markdown in Hugo. It's CommonMark compliant and GitHub flavored, and both fast and flexible. Blackfriday, the old default, has served us well, but there have been formatting and portability issues that were hard to work around. The "CommonMark compliant" part is the main selling feature of Goldmark, but with that you also get attribute syntax on headers and code blocks (for code blocks you can turn on/off line numbers and highlight line ranges), strikethrough support and an improved and configurable implementation of `TableOfContents`. See [Markup Configuration](https://gohugo.io/getting-started/configuration-markup/) for an overview of extensions.
[Goldmark](https://github.com/yuin/goldmark/) by [@yuin](https://github.com/yuin) is now the new default library used for Markdown in Hugo. It's CommonMark compliant and GitHub flavored, and both fast and flexible. Blackfriday, the old default, has served us well, but there have been formatting and portability issues that were hard to work around. The "CommonMark compliant" part is the main selling feature of Goldmark, but with that you also get attribute syntax on headers and code blocks (for code blocks you can turn on/off line numbers and highlight line ranges), strikethrough support and an improved and configurable implementation of `TableOfContents`. See [Markup Configuration](https://gohugo.io/getting-started/configuration-markup/) for an overview of extensions.

Please read the [Notes Section](#notes) and the updated documentation. We suggest you start with [List of content formats in Hugo](https://gohugo.io/content-management/formats/#list-of-content-formats). Goldmark is better, but the feature set is not fully comparable and it may be more stricter in some areas (there are 17 rules for how a [headline](https://spec.commonmark.org/0.29/#emphasis-and-strong-emphasis) should look like); if you have any problems you cannot work around, see [Configure Markup](https://gohugo.io/getting-started/configuration-markup/#configure-markup) for a way to change the default Markdown handler.

Also, if you have lots of inline HTML in your Markdown files, you may have to enable the `unsafe` mode:

{{< code-toggle file="config" >}}
markup:
goldmark:
renderer:
unsafe: true
{{< /code-toggle >}}

This release represents **62 contributions by 10 contributors** to the main Hugo code base. [@bep](https://github.com/bep) leads the Hugo development with a significant amount of contributions, but also a big shoutout to [@anthonyfok](https://github.com/anthonyfok), [@max-arnold](https://github.com/max-arnold), and [@trimbo](https://github.com/trimbo) for their ongoing contributions.
And a big thanks to [@digitalcraftsman](https://github.com/digitalcraftsman) and [@onedrawingperday](https://github.com/onedrawingperday) for their relentless work on keeping the themes site in pristine condition and to [@kaushalmodi](https://github.com/kaushalmodi) and [@davidsneighbour](https://github.com/davidsneighbour) for great work on the documentation site.

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions docs/content/en/news/0.60.1-relnotes/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ date: 2019-11-29
title: "Hugo 0.60.1: A couple of Bug Fixes"
description: "This version fixes a couple of bugs introduced in 0.60.0."
categories: ["Releases"]
images:
- images/blog/hugo-bug-poster.png

---


Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/content/en/news/0.61.0-relnotes/index.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

---
date: 2019-12-11
title: "0.61.0"
description: "0.61.0"
title: "40K GitHub Stars Edition"
description: "40K stars on GitHub is a good enough reason to release a new version of Hugo!"
categories: ["Releases"]
---

This is the [40K GitHub Stars Edition](https://github.com/gohugoio/hugo/stargazers). It's mostly a bug fix release, and an important note is the deprecation of Amber and Ace as template engines. See [#6609](https://github.com/gohugoio/hugo/issues/6609) for more information.
This is the [40K GitHub Stars Edition](https://github.com/gohugoio/hugo/stargazers). It's mostly a bug fix release, and an important note is the deprecation of Amber and Ace as template engines. See [#6609](https://github.com/gohugoio/hugo/issues/6609) for more information.

This release represents **10 contributions by 3 contributors** to the main Hugo code base.

Expand Down
2 changes: 0 additions & 2 deletions docs/content/en/templates/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ The following is only a primer on Go Templates. For an in-depth look into Go Tem

Go Templates provide an extremely simple template language that adheres to the belief that only the most basic of logic belongs in the template or view layer.

{{< youtube gnJbPO-GFIw >}}

## Basic Syntax

Go Templates are HTML files with the addition of [variables][variables] and [functions][functions]. Go Template variables and functions are accessible within `{{ }}`.
Expand Down
12 changes: 6 additions & 6 deletions docs/content/en/templates/output-formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ linktitle: Custom Output Formats
description: Hugo can output content in multiple formats, including calendar events, e-book formats, Google AMP, and JSON search indexes, or any custom text format.
date: 2017-03-22
publishdate: 2017-03-22
lastmod: 2017-03-22
lastmod: 2019-12-11
categories: [templates]
keywords: ["amp","outputs","rss"]
menu:
Expand All @@ -31,7 +31,7 @@ This is the full set of built-in media types in Hugo:
**Note:**

* It is possible to add custom media types or change the defaults; e.g., if you want to change the suffix for `text/html` to `asp`.
* The `Suffix` is the value that will be used for URLs and filenames for that media type in Hugo.
* `Suffixes` are the values that will be used for URLs and filenames for that media type in Hugo.
* The `Type` is the identifier that must be used when defining new/custom `Output Formats` (see below).
* The full set of media types will be registered in Hugo's built-in development server to make sure they are recognized by the browser.

Expand All @@ -40,9 +40,9 @@ To add or modify a media type, define it in a `mediaTypes` section in your [site
{{< code-toggle file="config" >}}
[mediaTypes]
[mediaTypes."text/enriched"]
suffix = "enr"
suffixes = ["enr"]
[mediaTypes."text/html"]
suffix = "asp"
suffixes = ["asp"]
{{</ code-toggle >}}

The above example adds one new media type, `text/enriched`, and changes the suffix for the built-in `text/html` media type.
Expand All @@ -52,7 +52,7 @@ The above example adds one new media type, `text/enriched`, and changes the suff
```toml
[mediaTypes]
[mediaTypes."text/html"]
suffix = "htm"
suffixes = ["htm"]

# Redefine HTML to update its media type.
[outputFormats]
Expand Down Expand Up @@ -221,7 +221,7 @@ From content files, you can use the [`ref` or `relref` shortcodes](/content-mana
A new output format needs a corresponding template in order to render anything useful.

{{% note %}}
The key distinction for Hugo versions 0.20 and newer is that Hugo looks at an output format's `Name` and MediaType's `Suffix` when choosing the template used to render a given `Page`.
The key distinction for Hugo versions 0.20 and newer is that Hugo looks at an output format's `Name` and MediaType's `Suffixes` when choosing the template used to render a given `Page`.
{{% /note %}}

The following table shows examples of different output formats, the suffix used, and Hugo's respective template [lookup order][]. All of the examples in the table can:
Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/tools/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ aliases: []
toc: true
---

A static website with a dynamic search function? Yes. As alternatives to embeddable scripts from Google or other search engines, you can provide your visitors a custom search by indexing your content files directly.
A static website with a dynamic search function? Yes, Hugo provides an alternative to embeddable scripts from Google or other search engines for static websites. Hugo allows you to provide your visitors with a custom search function by indexing your content files directly.

* [GitHub Gist for Hugo Workflow](https://gist.github.com/sebz/efddfc8fdcb6b480f567). This gist contains a simple workflow to create a search index for your static website. It uses a simple Grunt script to index all your content files and [lunr.js](https://lunrjs.com/) to serve the search results.
* [hugo-elasticsearch](https://www.npmjs.com/package/hugo-elasticsearch). Generate [Elasticsearch](https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html) indexes for Hugo static sites by parsing front matter. Hugo-Elasticsearch will generate a newline delimited JSON (NDJSON) file that can be bulk uploaded into Elasticsearch using any one of the available [clients](https://www.elastic.co/guide/en/elasticsearch/client/index.html).
Expand Down
3 changes: 1 addition & 2 deletions docs/data/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1387,8 +1387,7 @@
},
"tableOfContents": {
"startLevel": 2,
"endLevel": 3,
"ordered": false
"endLevel": 3
},
"goldmark": {
"renderer": {
Expand Down
7 changes: 7 additions & 0 deletions docs/data/homepagetweets.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[[tweet]]
name = "Heinrich Hartmann"
twitter_handle = "@heinrichhartman"
quote = "Working with @GoHugoIO is such a joy. Having worked with #Jekyll in the past, the near instant preview is a big win! Did not expect this to make such a huge difference."
link = "https://twitter.com/heinrichhartman/status/1199736512264462341"
date = 2019-11-12T00:00:00Z

[[tweet]]
name = "Joshua Steven‏‏"
twitter_handle = "@jscarto"
Expand Down
Loading

0 comments on commit 052ba99

Please sign in to comment.