diff options
author | de-souza <43355143+de-souza@users.noreply.github.com> | 2020-03-17 03:55:49 +0300 |
---|---|---|
committer | de-souza <43355143+de-souza@users.noreply.github.com> | 2020-03-17 03:55:49 +0300 |
commit | f8c2c331776ce561f4fb7932f6510408417e71c3 (patch) | |
tree | f979f778de3da2ada7e49902cd4e0e0246afcd55 | |
parent | ec129606276926de1a35d9156abb5bc4b0f40157 (diff) |
Simplify code and add partials
-rw-r--r-- | layouts/_default/baseof.html | 44 | ||||
-rw-r--r-- | layouts/_default/home.html | 72 | ||||
-rw-r--r-- | layouts/_default/list.html | 18 | ||||
-rw-r--r-- | layouts/_default/terms.html | 8 | ||||
-rw-r--r-- | layouts/partials/assets.html | 7 | ||||
-rw-r--r-- | layouts/partials/banner.html | 8 | ||||
-rw-r--r-- | layouts/partials/comments.html | 6 | ||||
-rw-r--r-- | layouts/partials/footer.html | 12 | ||||
-rw-r--r-- | layouts/partials/heading.html | 6 | ||||
-rw-r--r-- | layouts/partials/link.html | 5 | ||||
-rw-r--r-- | layouts/partials/load_site_assets.html | 24 | ||||
-rw-r--r-- | layouts/partials/meta.html | 30 | ||||
-rw-r--r-- | layouts/partials/pagination.html | 21 | ||||
-rw-r--r-- | layouts/partials/tags.html | 34 | ||||
-rw-r--r-- | layouts/partials/title.html | 7 | ||||
-rw-r--r-- | layouts/shortcodes/contact.html | 9 | ||||
-rw-r--r-- | layouts/shortcodes/soundcloud.html | 2 |
17 files changed, 183 insertions, 130 deletions
diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index bdf23c1..bc7f809 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,44 +1,17 @@ <!DOCTYPE html> <html lang="{{ site.LanguageCode }}"> + <head> {{ partial "meta.html" . }} - <title> - {{ if eq .Title site.Title }} - {{ site.Title }} - {{ else }} - {{ with .Title }}{{ . }} | {{ end }}{{ site.Title }} - {{ end }} - </title> - <link rel="canonical" href="{{ .RelPermalink }}"> - {{ range .AlternativeOutputFormats }} - {{ printf "<link rel=%q type=%q href=%q title=%q>" .Rel .MediaType .RelPermalink site.Title | safeHTML }} - {{ end }} - {{ $basecss := resources.Get "css/base.tpl.css" | resources.ExecuteAsTemplate "css/base.css" . }} - {{ with site.Params.css }} - {{ $customcss := slice $basecss }} - {{ range . }}{{ $customcss = $customcss | append (readFile . | resources.FromString (printf "custom/%s" .)) }}{{ end }} - {{ $basecss = $customcss | resources.Concat "css/base.css" }} - {{ end }} - {{ $basecss | minify | fingerprint | .Page.Scratch.SetInMap "css" "base" }} - {{ with site.Params.js }} - {{ $customjs := slice }} - {{ range . }}{{ $customjs = $customjs | append (readFile . | resources.FromString (printf "custom/%s" .)) }}{{ end }} - {{ $customjs | resources.Concat "js/base.js" | minify | fingerprint | $.Page.Scratch.SetInMap "js" "base" }} - {{ end }} - {{/* - 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 CSS and JS - resources to specific pages of the website. - */}} - {{ block "loadshortcodes" . }}{{ with .Content }}{{ end }}{{ end }} - {{ range .Scratch.GetSortedMapValues "css" }} - <link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous"> - {{ end }} - {{ range .Scratch.GetSortedMapValues "js" }} - <script defer src="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous"></script> + {{ partial "title.html" . }} + {{ partial "link.html" . }} + {{ partial "load_site_assets.html" . }} + {{ block "load_page_assets" . }} + {{ with .Content }}{{ end }} {{ end }} + {{ partial "assets.html" . }} </head> + <body> {{ partialCached "banner.html" . }} <main> @@ -50,4 +23,5 @@ </main> {{ partialCached "footer.html" . }} </body> + </html> diff --git a/layouts/_default/home.html b/layouts/_default/home.html index 30673ff..02bbee5 100644 --- a/layouts/_default/home.html +++ b/layouts/_default/home.html @@ -1,39 +1,51 @@ -{{ define "loadshortcodes" }} +{{ define "load_page_assets" }} -{{ $pag := where site.RegularPages "Type" "in" site.Params.mainSections | .Paginate }} -{{ range $pag.Pages }} -{{ with .Content }}{{ end }} -{{ with .Scratch.Get "css" }} -{{ . | merge ($.Scratch.Get "css") | $.Scratch.Set "css" }} -{{ end }} -{{ with .Scratch.Get "js" }} -{{ . | merge ($.Scratch.Get "js") | $.Scratch.Set "js" }} -{{ end }} -{{ end }} -{{ .Scratch.Set "paginator" $pag }} + {{ $pages := where site.RegularPages "Type" "in" site.Params.mainSections }} + + {{ $paginator := .Paginate $pages }} + + {{ range $paginator.Pages }} + {{ with .Content }}{{ end }} + {{ $page_css := .Scratch.Get "css" }} + {{ with $page_css }} + {{ $css_list := $.Scratch.Get "css" }} + {{ . | merge $css_list | $.Scratch.Set "css" }} + {{ end }} + {{ $page_js := .Scratch.Get "js" }} + {{ with $page_js }} + {{ $js_list := $.Scratch.Get "js" }} + {{ . | merge $js_list | $.Scratch.Set "js" }} + {{ end }} + {{ end }} + + {{ $paginator | .Scratch.Set "paginator" }} {{ end }} {{ define "main" }} -{{ $pag := .Scratch.Get "paginator" }} -{{ range $pag.Pages }} -<article> - {{ partial "heading.html" . }} - {{ if site.Params.summaries }} - {{ .Summary }} - {{ if .Truncated }} - <p> - <a class="u-clickable" href="{{ .RelPermalink }}">Read More…</a> - </p> - {{ end }} - {{ else }} - {{ .Content }} + {{ $paginator := .Scratch.Get "paginator" }} + + {{ range $paginator.Pages }} + <article> + {{ partial "heading.html" . }} + {{ if site.Params.summaries }} + {{ .Summary }} + {{ if .Truncated }} + <p> + <a class="u-clickable" href="{{ .RelPermalink }}">Read More…</a> + </p> + {{ end }} + {{ else }} + {{ .Content }} + {{ end }} + {{ partial "tags.html" . }} + </article> + {{ with site.Params.divider }} + <div class="Divider"></div> + {{ end }} {{ end }} - {{ partial "tags.html" . }} -</article> -{{ with site.Params.divider }}<div class="Divider"></div>{{ end }} -{{ end }} -{{ partial "pagination.html" . }} + + {{ partial "pagination.html" . }} {{ end }} diff --git a/layouts/_default/list.html b/layouts/_default/list.html index df22814..a6b13fb 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,16 +1,18 @@ {{ define "main" }} {{ partial "heading.html" . }} + {{ .Content }} + {{ range .Pages.GroupByPublishDate "2006" }} -<h3>{{ .Key }}</h3> -<ul> - {{ range .Pages }} - <li> - {{ .PublishDate.Format "2006-01-02" }} – <a href="{{ .RelPermalink }}">{{ .Title }}</a> - </li> - {{ end }} -</ul> + <h3>{{ .Key }}</h3> + <ul> + {{ range .Pages }} + <li> + {{ .PublishDate.Format "2006-01-02" }} – <a href="{{ .RelPermalink }}">{{ .Title }}</a> + </li> + {{ end }} + </ul> {{ end }} {{ end }} diff --git a/layouts/_default/terms.html b/layouts/_default/terms.html index 22db1d5..5e1ab66 100644 --- a/layouts/_default/terms.html +++ b/layouts/_default/terms.html @@ -1,12 +1,14 @@ {{ define "main" }} {{ partial "heading.html" . }} + {{ .Content }} + <ul class="Tags"> {{ range .Pages }} - <li class="Tags-item u-background"> - <a class="Tags-link u-clickable" href="{{ .RelPermalink }}">{{ .Title }}</a> - </li> + <li class="Tags-item u-background"> + <a class="Tags-link u-clickable" href="{{ .RelPermalink }}">{{ .Title }}</a> + </li> {{ end }} </ul> diff --git a/layouts/partials/assets.html b/layouts/partials/assets.html new file mode 100644 index 0000000..f3beafb --- /dev/null +++ b/layouts/partials/assets.html @@ -0,0 +1,7 @@ +{{ range .Scratch.GetSortedMapValues "css" }} + <link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous"> +{{ end }} + +{{ range .Scratch.GetSortedMapValues "js" }} + <script defer src="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous"></script> +{{ end }} diff --git a/layouts/partials/banner.html b/layouts/partials/banner.html index e3bf21f..839cddf 100644 --- a/layouts/partials/banner.html +++ b/layouts/partials/banner.html @@ -2,12 +2,12 @@ <div class="u-wrapper"> <ul class="Banner"> <li class="Banner-item Banner-item--title"> - <a class="Banner-link u-clickable" href="{{ "" | relURL }}">{{ site.Title }}</a> + <a class="Banner-link u-clickable" href="{{ relURL "" }}">{{ site.Title }}</a> </li> {{ range site.Menus.nav }} - <li class="Banner-item"> - <a class="Banner-link u-clickable" href="{{ .URL | relURL }}">{{ .Name }}</a> - </li> + <li class="Banner-item"> + <a class="Banner-link u-clickable" href="{{ relURL .URL }}">{{ .Name }}</a> + </li> {{ end }} </ul> </div> diff --git a/layouts/partials/comments.html b/layouts/partials/comments.html index 447116a..24f778e 100644 --- a/layouts/partials/comments.html +++ b/layouts/partials/comments.html @@ -1,5 +1,5 @@ {{ with site.Params.utterances }} -{{ if in site.Params.mainSections $.Type | and .repo }} -<script src="https://utteranc.es/client.js" repo="{{ .repo }}" issue-term="{{ .issueterm }}" theme="{{ .theme }}" crossorigin="anonymous" async></script> -{{end}} + {{ if in site.Params.mainSections $.Type | and .repo }} + <script src="https://utteranc.es/client.js" repo="{{ .repo }}" issue-term="{{ .issueterm }}" theme="{{ .theme }}" crossorigin="anonymous" async></script> + {{end}} {{end}} diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index d90ae09..177c092 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -1,9 +1,9 @@ {{ with site.Params.footer }} -<footer class="Footer"> - <div class="u-wrapper"> - <div class="u-padding"> - {{ . | safeHTML }} + <footer class="Footer"> + <div class="u-wrapper"> + <div class="u-padding"> + {{ safeHTML . }} + </div> </div> - </div> -</footer> + </footer> {{ end }} diff --git a/layouts/partials/heading.html b/layouts/partials/heading.html index 4888478..e603f69 100644 --- a/layouts/partials/heading.html +++ b/layouts/partials/heading.html @@ -3,8 +3,8 @@ <a class="Heading-link u-clickable" href="{{ .RelPermalink }}" rel="bookmark">{{ .Title }}</a> </h2> {{ with .PublishDate | default nil }} - <time datetime="{{ .Format "2006-01-02T15:04:05Z07:00" }}"> - {{ .Format "2 January, 2006" }} - </time> + <time datetime="{{ .Format "2006-01-02T15:04:05Z07:00" }}"> + {{- .Format "2 January, 2006" -}} + </time> {{ end }} </header> diff --git a/layouts/partials/link.html b/layouts/partials/link.html new file mode 100644 index 0000000..f982f7c --- /dev/null +++ b/layouts/partials/link.html @@ -0,0 +1,5 @@ +<link rel="canonical" href="{{ .RelPermalink }}"> + +{{ range .AlternativeOutputFormats }} + {{ printf "<link rel=%q type=%q href=%q title=%q>" .Rel .MediaType .RelPermalink site.Title | safeHTML }} +{{ end }} diff --git a/layouts/partials/load_site_assets.html b/layouts/partials/load_site_assets.html new file mode 100644 index 0000000..29d6924 --- /dev/null +++ b/layouts/partials/load_site_assets.html @@ -0,0 +1,24 @@ +{{ $base_css := resources.Get "css/base.tpl.css" }} + +{{ $site_css := $base_css | resources.ExecuteAsTemplate "css/base.css" . }} + +{{ with site.Params.css }} + {{ $css_list := slice $site_css }} + {{ range . }} + {{ $custom_css := resources.Get . }} + {{ $css_list = $css_list | append $custom_css }} + {{ end }} + {{ $site_css = $css_list | resources.Concat "css/base.css" }} +{{ end }} + +{{ minify $site_css | fingerprint | .Page.Scratch.SetInMap "css" "base" }} + +{{ with site.Params.js }} + {{ $js_list := slice }} + {{ range . }} + {{ $custom_js := resources.Get . }} + {{ $js_list = $js_list | append $custom_js }} + {{ end }} + {{ $site_js := $js_list | resources.Concat "js/base.js" }} + {{ minify $site_js | fingerprint | $.Page.Scratch.SetInMap "js" "base" }} +{{ end }} diff --git a/layouts/partials/meta.html b/layouts/partials/meta.html index 696e244..9af6cf9 100644 --- a/layouts/partials/meta.html +++ b/layouts/partials/meta.html @@ -1,17 +1,29 @@ <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + {{ with .Description }} -<meta name="description" content="{{ . }}"> + <meta name="description" content="{{ . }}"> {{ else }} -{{ if .IsPage }} -<meta name="description" content="{{ .Summary }}"> -{{ else }} -{{ with .Site.Params.description }} -<meta name="description" content="{{ . }}"> + {{ if .IsPage }} + <meta name="description" content="{{ .Summary }}"> + {{ else }} + {{ with site.Params.description }} + <meta name="description" content="{{ . }}"> + {{ end }} + {{ end }} +{{ end }} + +{{ 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 }} -{{ 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 }} diff --git a/layouts/partials/pagination.html b/layouts/partials/pagination.html index 058e948..4b82f51 100644 --- a/layouts/partials/pagination.html +++ b/layouts/partials/pagination.html @@ -1,11 +1,12 @@ -{{ $pag := .Scratch.Get "paginator" }} -{{ if gt $pag.TotalPages 1 }} -<nav> - {{ if $pag.HasNext }} - <a class="Pagination u-clickable" href="{{ $pag.Next.URL }}" rel="prev">« Previous</a> - {{ end }} - {{ if $pag.HasPrev }} - <a class="Pagination Pagination--right u-clickable" href="{{ $pag.Prev.URL }}" rel="next">Next »</a> - {{ end }} -</nav> +{{ $paginator := .Scratch.Get "paginator" }} + +{{ if gt $paginator.TotalPages 1 }} + <nav> + {{ with $paginator.Next }} + <a class="Pagination u-clickable" href="{{ .URL }}" rel="prev">« Previous</a> + {{ end }} + {{ with $paginator.Prev }} + <a class="Pagination Pagination--right u-clickable" href="{{ .URL }}" rel="next">Next »</a> + {{ end }} + </nav> {{ end }} diff --git a/layouts/partials/tags.html b/layouts/partials/tags.html index d56540f..38d0446 100644 --- a/layouts/partials/tags.html +++ b/layouts/partials/tags.html @@ -1,19 +1,23 @@ -{{ $taxonomies := slice }} +{{ $taxonomy_list := slice }} + {{ range $taxonomy, $pages := site.Taxonomies }} -{{ $taxonomies = $taxonomies | append $taxonomy }} + {{ $taxonomy_list = $taxonomy_list | append $taxonomy_list }} {{ end }} -{{ if true | in (apply $taxonomies "isset" .Params ".") }} -<footer> - {{ range $taxonomy := $taxonomies }} - {{ if isset $.Params $taxonomy }} - <ul class="Tags"> - {{ range $.GetTerms $taxonomy }} - <li class="Tags-item u-background"> - <a class="Tags-link u-clickable" href="{{ .RelPermalink }}" rel="tag">{{ .LinkTitle }}</a> - </li> + +{{ $taxonomy_is_used_list := apply $taxonomy_list "isset" .Params "." }} + +{{ if true | in $taxonomy_is_used_list }} + <footer> + {{ range $taxonomy := $taxonomy_list }} + {{ if isset $.Params $taxonomy }} + <ul class="Tags"> + {{ range $.GetTerms $taxonomy }} + <li class="Tags-item u-background"> + <a class="Tags-link u-clickable" href="{{ .RelPermalink }}" rel="tag">{{ .LinkTitle }}</a> + </li> + {{ end }} + </ul> + {{ end }} {{ end }} - </ul> - {{ end }} - {{ end }} -</footer> + </footer> {{ end }} diff --git a/layouts/partials/title.html b/layouts/partials/title.html new file mode 100644 index 0000000..e0bc325 --- /dev/null +++ b/layouts/partials/title.html @@ -0,0 +1,7 @@ +<title> + {{- if eq .Title site.Title -}} + {{ site.Title }} + {{- else -}} + {{ with .Title }}{{ . }} | {{ end }}{{ site.Title }} + {{- end -}} +</title> diff --git a/layouts/shortcodes/contact.html b/layouts/shortcodes/contact.html index 7a4694d..f6d800a 100644 --- a/layouts/shortcodes/contact.html +++ b/layouts/shortcodes/contact.html @@ -1,11 +1,12 @@ {{ resources.Get "css/contact.css" | minify | fingerprint | .Page.Scratch.SetInMap "css" "contact" }} + <form class="Contact" name="contact" method="POST" data-netlify="true"{{ if site.Params.netlify.honeypot }} data-netlify-honeypot="bot"{{ end }}{{ if site.Params.netlify.recaptcha }} data-netlify-recaptcha="true"{{ end }}{{ with .Get 0 }} action="{{ . }}"{{ end }}> <ul class="Contact-group"> {{ if site.Params.netlify.honeypot }} - <li class="Contact-hidden"> - <label>Don’t fill this out if you're human:</label> - <input name="bot"> - </li> + <li class="Contact-hidden"> + <label>Don’t fill this out if you're human:</label> + <input name="bot"> + </li> {{ end }} <li class="Contact-item"> <label class="Contact-label" for="Contact-name">Name:</label> diff --git a/layouts/shortcodes/soundcloud.html b/layouts/shortcodes/soundcloud.html index 6c9c0bc..b3d2801 100644 --- a/layouts/shortcodes/soundcloud.html +++ b/layouts/shortcodes/soundcloud.html @@ -1,3 +1,5 @@ {{ resources.Get "css/soundcloud.css" | minify | fingerprint | .Page.Scratch.SetInMap "css" "soundcloud" }} + {{ resources.Get "js/soundcloud.js" | minify | fingerprint | .Page.Scratch.SetInMap "js" "soundcloud" }} + <div class="Soundcloud" data-id="{{ .Get 0 }}"></div> |