diff options
author | de-souza <43355143+de-souza@users.noreply.github.com> | 2019-08-26 18:12:43 +0300 |
---|---|---|
committer | de-souza <43355143+de-souza@users.noreply.github.com> | 2019-08-26 18:12:43 +0300 |
commit | be83bdde2a09451f8e32b087b51e95e094c453a0 (patch) | |
tree | dfd143290f8f71692c62908f8db89538c95882a9 | |
parent | 56c53a763ad0d846bae13469b10d973f7d9498cd (diff) |
Add documentation on shortcode pre-rendering
-rw-r--r-- | layouts/_default/baseof.html | 8 | ||||
-rw-r--r-- | layouts/index.html | 7 |
2 files changed, 12 insertions, 3 deletions
diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 36ba1f4..9f1256f 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -3,10 +3,10 @@ <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> + {{ hugo.Generator }} {{ if site.Params.schema }}{{ template "_internal/schema.html" . }}{{ end }} {{ if site.Params.opengraph }}{{ template "_internal/opengraph.html" . }}{{ end }} {{ if site.Params.twittercards }}{{ template "_internal/twitter_cards.html" . }}{{ end }} - {{ hugo.Generator }} <title> {{ if eq .Title site.Title }} {{ site.Title }} @@ -18,8 +18,12 @@ {{ range .AlternativeOutputFormats }} {{ printf "<link rel=%q type=%q href=%q title=%q>" .Rel .MediaType.Type .Permalink site.Title | safeHTML }} {{ end }} - {{ block "loadresources" . }}{{ with .Content }}{{ end }}{{ end }} {{ resources.Get "css/base.temp.css" | resources.ExecuteAsTemplate "css/base.css" . | minify | fingerprint | .Page.Scratch.SetInMap "css" "base" }} + {{/* In the following block, Hugo is forced to stop and pre-render the + content of the current page with all its shortcodes. Thanks to this + pre-render, shortcodes can be used to load additional resources + through the .Scratch variable. */}} + {{ block "loadshortcodes" . }}{{ with .Content }}{{ end }}{{ end }} {{ range .Scratch.GetSortedMapValues "css" }} <link rel="stylesheet" href="{{ .Permalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous"> {{ end }} diff --git a/layouts/index.html b/layouts/index.html index 28a77a8..b2a2cea 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -1,5 +1,10 @@ -{{ define "loadresources" }} +{{ define "loadshortcodes" }} +{{/* Here Hugo is forced to cycle through all the items that will appear + on the page, and pre-render their contents with all their shortcodes. + If these shortcodes are used to load additional resources, these + resources are then transferred from the local .Scratch variables to + the globally available .Scratch variable. */}} {{ $paginator := where site.RegularPages "Type" "in" site.Params.mainSections | .Paginate }} {{ range $paginator.Pages }} {{ with .Content }}{{ end }} |