Skip to content

Commit

Permalink
Use site function instead of .Site or $.Site
Browse files Browse the repository at this point in the history
- The site function provides global access to the same data as the .Site page method.
- Current context (`.`) is never considered.
  • Loading branch information
adityatelange committed Mar 27, 2022
1 parent 975972e commit 575cc0c
Show file tree
Hide file tree
Showing 23 changed files with 115 additions and 115 deletions.
2 changes: 1 addition & 1 deletion layouts/_default/archives.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h1>{{ .Title }}</h1>

{{- $pages := where site.RegularPages "Type" "in" site.Params.mainSections }}

{{- if .Site.Params.ShowAllPagesInArchive }}
{{- if site.Params.ShowAllPagesInArchive }}
{{- $pages = site.RegularPages }}
{{- end }}

Expand Down
4 changes: 2 additions & 2 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="{{ .Site.Language }}" dir="{{ .Language.LanguageDirection | default "auto" }}">
<html lang="{{ site.Language }}" dir="{{ .Language.LanguageDirection | default "auto" }}">

<head>
{{- partial "head.html" . }}
Expand All @@ -9,7 +9,7 @@
{{- if (or (ne .Kind `page` ) (eq .Layout `archives`) (eq .Layout `search`)) -}}
{{- print "list" -}}
{{- end -}}
{{- if eq $.Site.Params.defaultTheme `dark` -}}
{{- if eq site.Params.defaultTheme `dark` -}}
{{- print " dark" }}
{{- end -}}
" id="top">
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/index.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- $.Scratch.Add "index" slice -}}
{{- range .Site.RegularPages -}}
{{- range site.RegularPages -}}
{{- if and (not .Params.searchHidden) (ne .Layout `archives`) (ne .Layout `search`) }}
{{- $.Scratch.Add "index" (dict "title" .Title "content" .Plain "permalink" .Permalink "summary" .Summary) -}}
{{- end }}
Expand Down
8 changes: 4 additions & 4 deletions layouts/_default/list.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- define "main" }}

{{- if (and .Site.Params.profileMode.enabled .IsHome) }}
{{- if (and site.Params.profileMode.enabled .IsHome) }}
{{- partial "index_profile.html" . }}
{{- else }} {{/* if not profileMode */}}

Expand Down Expand Up @@ -32,7 +32,7 @@ <h1>{{ .Title }}</h1>

{{- $paginator := .Paginate $pages }}

{{- if and .IsHome .Site.Params.homeInfoParams (eq $paginator.PageNumber 1) }}
{{- if and .IsHome site.Params.homeInfoParams (eq $paginator.PageNumber 1) }}
{{- partial "home_info.html" . }}
{{- end }}

Expand All @@ -41,15 +41,15 @@ <h1>{{ .Title }}</h1>

{{- $class := "post-entry" }}

{{- $user_preferred := or .Site.Params.disableSpecial1stPost .Site.Params.homeInfoParams }}
{{- $user_preferred := or site.Params.disableSpecial1stPost site.Params.homeInfoParams }}
{{- if (and $.IsHome (eq $paginator.PageNumber 1) (eq $index 0) (not $user_preferred)) }}
{{- $class = "first-entry" }}
{{- else if $term }}
{{- $class = "post-entry tag-entry" }}
{{- end }}

<article class="{{ $class }}">
{{- $isHidden := (.Site.Params.cover.hidden | default .Site.Params.cover.hiddenInList) }}
{{- $isHidden := (site.Params.cover.hidden | default site.Params.cover.hiddenInList) }}
{{- partial "cover.html" (dict "cxt" . "IsHome" true "isHidden" $isHidden) }}
<header class="entry-header">
<h2>
Expand Down
22 changes: 11 additions & 11 deletions layouts/_default/rss.xml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{{- $pctx := . -}}
{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}}
{{- if .IsHome -}}{{ $pctx = site }}{{- end -}}
{{- $pages := slice -}}
{{- if or $.IsHome $.IsSection -}}
{{- $pages = $pctx.RegularPages -}}
{{- else -}}
{{- $pages = $pctx.Pages -}}
{{- end -}}
{{- $limit := .Site.Config.Services.RSS.Limit -}}
{{- $limit := site.Config.Services.RSS.Limit -}}
{{- if ge $limit 1 -}}
{{- $pages = $pages | first $limit -}}
{{- end -}}
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title>
<title>{{ if eq .Title site.Title }}{{ site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ site.Title }}{{ end }}</title>
<link>{{ .Permalink }}</link>
<description>Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }}</description>
{{- with $.Site.Params.images }}
<description>Recent content {{ if ne .Title site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ site.Title }}</description>
{{- with site.Params.images }}
<image>
<url>{{ index . 0 | absURL }}</url>
<link>{{ index . 0 | absURL }}</link>
</image>
{{- end }}
<generator>Hugo -- gohugo.io</generator>{{ with .Site.LanguageCode }}
<language>{{.}}</language>{{end}}{{ with .Site.Author.email }}
<managingEditor>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}{{ with .Site.Author.email }}
<webMaster>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}{{ with .Site.Copyright }}
<generator>Hugo -- gohugo.io</generator>{{ with site.LanguageCode }}
<language>{{.}}</language>{{end}}{{ with site.Author.email }}
<managingEditor>{{.}}{{ with site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}{{ with site.Author.email }}
<webMaster>{{.}}{{ with site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}{{ with site.Copyright }}
<copyright>{{.}}</copyright>{{end}}{{ if not .Date.IsZero }}
<lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
{{- with .OutputFormats.Get "RSS" -}}
Expand All @@ -37,10 +37,10 @@
<title>{{ .Title }}</title>
<link>{{ .Permalink }}</link>
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
{{ with .Site.Author.email }}<author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}}
{{ with site.Author.email }}<author>{{.}}{{ with site.Author.name }} ({{.}}){{end}}</author>{{end}}
<guid>{{ .Permalink }}</guid>
<description>{{ with .Description | html }}{{ . }}{{ else }}{{ .Summary | html }}{{ end -}}</description>
{{- if .Site.Params.ShowFullTextinRSS }}
{{- if site.Params.ShowFullTextinRSS }}
<content:encoded>{{ (printf "<![CDATA[%s]]>" .Content) | safeHTML }}</content:encoded>
{{- end }}
</item>
Expand Down
4 changes: 2 additions & 2 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h1 class="post-title">
</div>
{{- end }}
</header>
{{- $isHidden := .Params.cover.hidden | default .Site.Params.cover.hiddenInSingle | default .Site.Params.cover.hidden }}
{{- $isHidden := .Params.cover.hidden | default site.Params.cover.hiddenInSingle | default site.Params.cover.hidden }}
{{- partial "cover.html" (dict "cxt" . "IsHome" false "isHidden" $isHidden) }}
{{- if (.Param "ShowToc") }}
{{- partial "toc.html" . }}
Expand All @@ -46,7 +46,7 @@ <h1 class="post-title">
{{- if (.Param "ShowPostNavLinks") }}
{{- partial "post_nav_links.html" . }}
{{- end }}
{{- if (and .Site.Params.ShowShareButtons (ne .Params.disableShare true)) }}
{{- if (and site.Params.ShowShareButtons (ne .Params.disableShare true)) }}
{{- partial "share_icons.html" . -}}
{{- end }}
</footer>
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/terms.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h1>{{ .Title }}</h1>
{{- range $key, $value := .Data.Terms.Alphabetical }}
{{- $name := .Name }}
{{- $count := .Count }}
{{- with $.Site.GetPage (printf "/%s/%s" $type $name) }}
{{- with site.GetPage (printf "/%s/%s" $type $name) }}
<li>
<a href="{{ .Permalink }}">{{ .Name }} <sup><strong><sup>{{ $count }}</sup></strong></sup> </a>
</li>
Expand Down
4 changes: 2 additions & 2 deletions layouts/partials/author.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if or .Params.author .Site.Params.author }}
{{- $author := (.Params.author | default .Site.Params.author) }}
{{- if or .Params.author site.Params.author }}
{{- $author := (.Params.author | default site.Params.author) }}
{{- $author_type := (printf "%T" $author) }}
{{- if (or (eq $author_type "[]string") (eq $author_type "[]interface {}")) }}
{{- (delimit $author ", " ) }}
Expand Down
4 changes: 2 additions & 2 deletions layouts/partials/breadcrumbs.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{{- if (.Param "ShowBreadCrumbs") -}}
<div class="breadcrumbs">
{{- $url := replace .Parent.Permalink (printf "%s" .Site.BaseURL) "" }}
{{- $url := replace .Parent.Permalink (printf "%s" site.BaseURL) "" }}
{{- $lang_url := strings.TrimPrefix (printf "%s/" .Lang) $url -}}

<a href="{{ "" | absLangURL }}">{{ i18n "home" | default "Home" }}</a>
{{- $scratch := newScratch }}
{{- range $index, $element := split $lang_url "/" }}

{{- $scratch.Add "path" (printf "%s/" $element )}}
{{- $bc_pg := $.Site.GetPage ($scratch.Get "path") -}}
{{- $bc_pg := site.GetPage ($scratch.Get "path") -}}

{{- if (and ($bc_pg) (gt (len . ) 0))}}
{{- print "&nbsp;»&nbsp;" | safeHTML -}}<a href="{{ $bc_pg.Permalink }}">{{ $bc_pg.Name }}</a>
Expand Down
6 changes: 3 additions & 3 deletions layouts/partials/cover.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{{- if (and .Params.cover.image (not $.isHidden)) }}
{{- $alt := (.Params.cover.alt | default .Params.cover.caption | plainify) }}
<figure class="entry-cover">
{{- $responsiveImages := (.Params.cover.responsiveImages | default .Site.Params.cover.responsiveImages) | default true }}
{{- $addLink := (and .Site.Params.cover.linkFullImages (not $.IsHome)) }}
{{- $responsiveImages := (.Params.cover.responsiveImages | default site.Params.cover.responsiveImages) | default true }}
{{- $addLink := (and site.Params.cover.linkFullImages (not $.IsHome)) }}
{{- $cover := (.Resources.ByType "image").GetMatch (printf "*%s*" (.Params.cover.image)) }}
{{- if $cover -}}{{/* i.e it is present in page bundle */}}
{{- if $addLink }}<a href="{{ (path.Join .RelPermalink .Params.cover.image) | absURL }}" target="_blank"
Expand All @@ -13,7 +13,7 @@
{{- if hugo.IsExtended -}}
{{- $processableFormats = $processableFormats | append "webp" -}}
{{- end -}}
{{- $prod := (hugo.IsProduction | or (eq .Site.Params.env "production")) }}
{{- $prod := (hugo.IsProduction | or (eq site.Params.env "production")) }}
{{- if (and (in $processableFormats $cover.MediaType.SubType) ($responsiveImages) (eq $prod true)) }}
<img loading="lazy" srcset="{{- range $size := $sizes -}}
{{- if (ge $cover.Width $size) -}}
Expand Down
8 changes: 4 additions & 4 deletions layouts/partials/edit_post.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{- if or .Params.editPost.URL .Site.Params.editPost.URL -}}
{{- if or .Params.editPost.URL site.Params.editPost.URL -}}
{{- $fileUrlPath := path.Join .File.Path }}

{{- if or .Params.author $.Site.Params.author (.Param "ShowReadingTime") (not .Date.IsZero) .IsTranslated }}&nbsp;|&nbsp;{{- end -}}
<a href="{{ .Params.editPost.URL | default .Site.Params.editPost.URL }}{{ if .Params.editPost.appendFilePath | default ( .Site.Params.editPost.appendFilePath | default false ) }}/{{ $fileUrlPath }}{{ end }}" rel="noopener noreferrer" target="_blank">
{{- .Params.editPost.Text | default (.Site.Params.editPost.Text | default (i18n "edit_post" | default "Edit")) -}}
{{- if or .Params.author site.Params.author (.Param "ShowReadingTime") (not .Date.IsZero) .IsTranslated }}&nbsp;|&nbsp;{{- end -}}
<a href="{{ .Params.editPost.URL | default site.Params.editPost.URL }}{{ if .Params.editPost.appendFilePath | default ( site.Params.editPost.appendFilePath | default false ) }}/{{ $fileUrlPath }}{{ end }}" rel="noopener noreferrer" target="_blank">
{{- .Params.editPost.Text | default (site.Params.editPost.Text | default (i18n "edit_post" | default "Edit")) -}}
</a>
{{- end }}
12 changes: 6 additions & 6 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{- if not (.Param "hideFooter") }}
<footer class="footer">
{{- if .Site.Copyright }}
<span>{{ .Site.Copyright | markdownify }}</span>
{{- if site.Copyright }}
<span>{{ site.Copyright | markdownify }}</span>
{{- else }}
<span>&copy; {{ now.Year }} <a href="{{ "" | absLangURL }}">{{ .Site.Title }}</a></span>
<span>&copy; {{ now.Year }} <a href="{{ "" | absLangURL }}">{{ site.Title }}</a></span>
{{- end }}
<span>
Powered by
Expand All @@ -13,7 +13,7 @@
</footer>
{{- end }}

{{- if (not .Site.Params.disableScrollToTop) }}
{{- if (not site.Params.disableScrollToTop) }}
<a href="#top" aria-label="go to top" title="Go to Top (Alt + G)" class="top-link" id="top-link" accesskey="g">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 6" fill="currentColor">
<path d="M12 6H0l6-6z" />
Expand Down Expand Up @@ -53,7 +53,7 @@

</script>

{{- if (not .Site.Params.disableScrollToTop) }}
{{- if (not site.Params.disableScrollToTop) }}
<script>
var mybutton = document.getElementById("top-link");
window.onscroll = function () {
Expand All @@ -69,7 +69,7 @@
</script>
{{- end }}

{{- if (not .Site.Params.disableThemeToggle) }}
{{- if (not site.Params.disableThemeToggle) }}
<script>
document.getElementById("theme-toggle").addEventListener("click", () => {
if (document.body.className.includes("dark")) {
Expand Down
Loading

0 comments on commit 575cc0c

Please sign in to comment.