From 052ba991d6dffbb3c952a07644947026563a3673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 27 Nov 2019 13:42:36 +0100 Subject: [PATCH] Add render template hooks for links and images This commit also revises the change detection for templates used by content files in server mode. Fixes #6545 Fixes #4663 Closes #6043 --- deps/deps.go | 4 + docs/README.md | 8 +- docs/content/en/_index.md | 2 +- .../image-processing/index.md | 3 +- .../content-management/syntax-highlighting.md | 18 +- docs/content/en/content-management/toc.md | 8 +- docs/content/en/getting-started/_index.md | 3 +- .../en/getting-started/configuration.md | 4 +- .../external-learning-resources/hia.jpg | Bin 0 -> 228017 bytes .../external-learning-resources/index.md | 29 ++ docs/content/en/getting-started/installing.md | 2 + .../content/en/getting-started/quick-start.md | 4 +- .../en/hosting-and-deployment/hugo-deploy.md | 6 +- docs/content/en/hugo-modules/use-modules.md | 4 +- docs/content/en/news/0.60.0-relnotes/index.md | 15 +- .../news/0.60.0-relnotes/poster-featured.png | Bin 0 -> 31907 bytes .../en/news/0.60.1-relnotes/featured-061.png | Bin 0 -> 28841 bytes docs/content/en/news/0.60.1-relnotes/index.md | 3 - .../news/0.61.0-relnotes/hugo-61-featured.png | Bin 0 -> 79929 bytes docs/content/en/news/0.61.0-relnotes/index.md | 6 +- docs/content/en/templates/introduction.md | 2 - docs/content/en/templates/output-formats.md | 12 +- docs/content/en/tools/search.md | 2 +- docs/data/docs.json | 3 +- docs/data/homepagetweets.toml | 7 + docs/netlify.toml | 8 +- ...ba6c3f_31907_480x0_resize_catmullrom_2.png | Bin 0 -> 16638 bytes ...ba6c3f_31907_640x0_resize_catmullrom_2.png | Bin 0 -> 24934 bytes ...0d3e6e_28841_480x0_resize_catmullrom_2.png | Bin 0 -> 22201 bytes ...0d3e6e_28841_640x0_resize_catmullrom_2.png | Bin 0 -> 31765 bytes ...aa169c_79929_480x0_resize_catmullrom_2.png | Bin 0 -> 32540 bytes ...aa169c_79929_640x0_resize_catmullrom_2.png | Bin 0 -> 53655 bytes helpers/content.go | 4 +- helpers/general_test.go | 3 +- hugolib/content_render_hooks_test.go | 244 ++++++++++++++ hugolib/filesystems/basefs.go | 49 ++- hugolib/hugo_modules_test.go | 3 + hugolib/hugo_sites.go | 39 ++- hugolib/hugo_sites_build.go | 2 +- hugolib/page.go | 184 ++++++++++- hugolib/page__content.go | 3 +- hugolib/page__meta.go | 36 ++- hugolib/page__new.go | 24 +- hugolib/page__output.go | 69 ++-- hugolib/page__per_output.go | 303 +++++++++++------- hugolib/page_test.go | 7 +- hugolib/page_unwrap_test.go | 1 + hugolib/pagebundler_test.go | 1 + hugolib/pagecollections.go | 10 - hugolib/shortcode.go | 19 +- hugolib/shortcode_page.go | 19 ++ hugolib/shortcode_test.go | 7 +- hugolib/site.go | 123 +++---- hugolib/site_benchmark_new_test.go | 30 ++ hugolib/template_test.go | 87 +++++ hugolib/testhelpers_test.go | 9 +- identity/identity.go | 131 ++++++++ identity/identity_test.go | 42 +++ markup/asciidoc/convert.go | 5 + markup/blackfriday/convert.go | 5 + markup/converter/converter.go | 13 +- markup/converter/hooks/hooks.go | 57 ++++ markup/goldmark/convert.go | 112 +++++-- markup/goldmark/convert_test.go | 15 +- markup/goldmark/render_link.go | 208 ++++++++++++ markup/mmark/convert.go | 5 + markup/org/convert.go | 6 + markup/pandoc/convert.go | 5 + markup/rst/convert.go | 5 + output/layout.go | 34 +- output/layout_test.go | 3 + public/categories/index.xml | 13 + public/index.xml | 13 + public/sitemap.xml | 17 + public/tags/index.xml | 13 + resources/page/page.go | 5 +- resources/page/page_nop.go | 8 +- resources/page/testhelpers_test.go | 6 +- scripts/fork_go_templates/main.go | 1 + .../go_templates/texttemplate/exec.go | 2 +- .../texttemplate/hugo_template.go | 104 +++++- .../texttemplate/hugo_template_test.go | 22 +- tpl/partials/partials.go | 6 +- tpl/template.go | 39 ++- tpl/template_info.go | 52 ++- tpl/tplimpl/shortcodes.go | 4 +- tpl/tplimpl/shortcodes_test.go | 8 +- tpl/tplimpl/template.go | 175 ++++++---- tpl/tplimpl/templateProvider.go | 9 +- tpl/tplimpl/template_ast_transformers.go | 166 +++++++--- tpl/tplimpl/template_ast_transformers_test.go | 66 ++-- tpl/tplimpl/template_funcs.go | 24 +- tpl/tplimpl/template_info_test.go | 7 +- 93 files changed, 2257 insertions(+), 578 deletions(-) create mode 100644 docs/content/en/getting-started/external-learning-resources/hia.jpg create mode 100644 docs/content/en/getting-started/external-learning-resources/index.md create mode 100644 docs/content/en/news/0.60.0-relnotes/poster-featured.png create mode 100644 docs/content/en/news/0.60.1-relnotes/featured-061.png create mode 100644 docs/content/en/news/0.61.0-relnotes/hugo-61-featured.png create mode 100644 docs/resources/_gen/images/news/0.60.0-relnotes/poster-featured_hu88aba11293facef11feec48164ba6c3f_31907_480x0_resize_catmullrom_2.png create mode 100644 docs/resources/_gen/images/news/0.60.0-relnotes/poster-featured_hu88aba11293facef11feec48164ba6c3f_31907_640x0_resize_catmullrom_2.png create mode 100644 docs/resources/_gen/images/news/0.60.1-relnotes/featured-061_hu55b86d71cf1e6f4fec276be0fe0d3e6e_28841_480x0_resize_catmullrom_2.png create mode 100644 docs/resources/_gen/images/news/0.60.1-relnotes/featured-061_hu55b86d71cf1e6f4fec276be0fe0d3e6e_28841_640x0_resize_catmullrom_2.png create mode 100644 docs/resources/_gen/images/news/0.61.0-relnotes/hugo-61-featured_huc7cf44fd2ae7c41ccbb87bf5c4aa169c_79929_480x0_resize_catmullrom_2.png create mode 100644 docs/resources/_gen/images/news/0.61.0-relnotes/hugo-61-featured_huc7cf44fd2ae7c41ccbb87bf5c4aa169c_79929_640x0_resize_catmullrom_2.png create mode 100644 hugolib/content_render_hooks_test.go create mode 100644 identity/identity.go create mode 100644 identity/identity_test.go create mode 100644 markup/converter/hooks/hooks.go create mode 100644 markup/goldmark/render_link.go create mode 100644 public/categories/index.xml create mode 100644 public/index.xml create mode 100644 public/sitemap.xml create mode 100644 public/tags/index.xml diff --git a/deps/deps.go b/deps/deps.go index ecbba2e5619..557f036f1fa 100644 --- a/deps/deps.go +++ b/deps/deps.go @@ -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. diff --git a/docs/README.md b/docs/README.md index 7ca9d734c07..a2c767b7b21 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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 diff --git a/docs/content/en/_index.md b/docs/content/en/_index.md index bfebd8b2fc7..b4e602438c6 100644 --- a/docs/content/en/_index.md +++ b/docs/content/en/_index.md @@ -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. diff --git a/docs/content/en/content-management/image-processing/index.md b/docs/content/en/content-management/image-processing/index.md index 9ec0734cc9f..53e72bee1ee 100644 --- a/docs/content/en/content-management/image-processing/index.md +++ b/docs/content/en/content-management/image-processing/index.md @@ -98,11 +98,12 @@ Tags: {{ range $k, $v := .Tags }} TAG: {{ $k }}: {{ $v }} {{ end }} +{{ end }} ``` #### Exif fields -Data +Date : "photo taken" date/time Lat diff --git a/docs/content/en/content-management/syntax-highlighting.md b/docs/content/en/content-management/syntax-highlighting.md index a4359e05dda..1220a06c83c 100644 --- a/docs/content/en/content-management/syntax-highlighting.md +++ b/docs/content/en/content-management/syntax-highlighting.md @@ -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 >}} @@ -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 +``` ```` @@ -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) } } ``` diff --git a/docs/content/en/content-management/toc.md b/docs/content/en/content-management/toc.md index 31326746c08..fbb2df06596 100644 --- a/docs/content/en/content-management/toc.md +++ b/docs/content/en/content-management/toc.md @@ -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 `` is going to start at `

` 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 `` was going to start at `

` 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 @@ -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 `