Skip to content

Commit

Permalink
theme: detect output format where it is needed #891
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed Oct 11, 2024
1 parent 4d706da commit ac4faed
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 34 deletions.
9 changes: 4 additions & 5 deletions layouts/partials/_main.hugo
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{{- partialCached "page-meta.hugo" . .RelPermalink }}
{{- $outputFormat := partial "output-format.hugo" . }}
{{- partial "output-partial.hugo" (dict "base" "header" "page" . "parameter" . "outputFormat" $outputFormat) }}
{{- partial "output-partial.hugo" (dict "base" "header" "page" . "parameter" .) }}
{{- if not .File }}
{{- partial "output-partial.hugo" (dict "base" "body" "page" . "parameter" (dict "page" . "content" (partial "output-partial.hugo" (dict "base" "initial" "page" . "parameter" . "outputFormat" $outputFormat))) "outputFormat" $outputFormat) }}
{{- partial "output-partial.hugo" (dict "base" "body" "page" . "parameter" (dict "page" . "content" (partial "output-partial.hugo" (dict "base" "initial" "page" . "parameter" .)))) }}
{{- else }}
{{- partial "output-partial.hugo" (dict "base" "body" "page" . "parameter" (dict "page" . "content" (partial "output-partial.hugo" (dict "base" "content" "page" . "parameter" . "outputFormat" $outputFormat))) "outputFormat" $outputFormat) }}
{{- partial "output-partial.hugo" (dict "base" "body" "page" . "parameter" (dict "page" . "content" (partial "output-partial.hugo" (dict "base" "content" "page" . "parameter" .)))) }}
{{- end }}
{{- partial "output-partial.hugo" (dict "base" "footer" "page" . "parameter" . "outputFormat" $outputFormat) }}
{{- partial "output-partial.hugo" (dict "base" "footer" "page" . "parameter" .) }}
6 changes: 1 addition & 5 deletions layouts/partials/archetype.hugo
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{{- $hook := .hook }}
{{- $page := .page }}
{{- $parameter := .parameter }}
{{- $outputFormat := .outputFormat }}
{{- if not $outputFormat }}
{{- $outputFormat = partial "output-format.hugo" $page }}
{{- end }}
{{- $archetype := "default" }}
{{- if not $page.File }}
{{- else if $page.Params.archetype }}
Expand All @@ -24,4 +20,4 @@
{{- if not (partialCached "fileExists.hugo" $f $f) }}
{{- $archetype = "default" }}
{{- end }}
{{- partial "output-partial.hugo" (dict "base" (printf "archetypes/%s/%s" $archetype $hook) "page" $page "parameter" $parameter "outputFormat" $outputFormat) }}
{{- partial "output-partial.hugo" (dict "base" (printf "archetypes/%s/%s" $archetype $hook) "page" $page "parameter" $parameter) }}
3 changes: 1 addition & 2 deletions layouts/partials/article.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{- $page := .page }}
{{- $content := .content }}
{{- $outputFormat := .outputFormat }}
{{- $hook := "article" }}
{{- partialCached "archetype.hugo" (dict "hook" $hook "page" $page "parameter" (dict "page" $page "content" $content) "outputFormat" $outputFormat) $page.RelPermalink $outputFormat $hook }}
{{- partialCached "archetype.hugo" (dict "hook" $hook "page" $page "parameter" (dict "page" $page "content" $content)) $page.RelPermalink $hook }}
3 changes: 1 addition & 2 deletions layouts/partials/body.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{{- $page := .page }}
{{- $content := .content }}
{{- $outputFormat := partial "output-format.hugo" .page }}
{{- partial "single-article.hugo" (dict "page" $page "content" $content "outputFormat" $outputFormat) }}
{{- partial "single-article.hugo" (dict "page" $page "content" $content) }}
3 changes: 1 addition & 2 deletions layouts/partials/body.print.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{{- $page := .page }}
{{- $content := .content }}
{{- $outputFormat := partial "output-format.hugo" .page }}
{{- partial "nested-article.hugo" (dict "page" $page "outputFormat" $outputFormat) }}
{{- partial "nested-article.hugo" (dict "page" $page) }}
3 changes: 1 addition & 2 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
</main><!-- #R-body-inner -->
{{- partial "custom-comments.html" . }}
</div><!-- #R-body -->
{{- $outputFormat := partial "output-format.hugo" .Page }}
{{- partial "output-partial.hugo" (dict "base" "menu" "page" . "parameter" . "outputFormat" $outputFormat) }}
{{- partial "output-partial.hugo" (dict "base" "menu" "page" . "parameter" .) }}
{{- $assetBusting := partialCached "assetbusting.hugo" . }}
<script src="{{"js/clipboard.min.js" | relURL}}{{ $assetBusting }}" defer></script>
<script src="{{"js/perfect-scrollbar.min.js" | relURL}}{{ $assetBusting }}" defer></script>
Expand Down
5 changes: 2 additions & 3 deletions layouts/partials/header.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<!DOCTYPE html>
{{- $format := partial "get-format.hugo" . }}
{{- $outputFormat := partial "output-format.hugo" (dict "page" . "format" $format) }}
{{- $outputFormat := partial "output-format.hugo" . }}
{{- if eq . .Site.Sites.First.Home }}
{{- $hugoVersion := "0.126.0" }}
{{- if lt hugo.Version $hugoVersion }}
Expand Down Expand Up @@ -69,5 +68,5 @@
</nav>
{{- $hook := "styleclass" }}
<div id="R-main-overlay"></div>
<main id="R-body-inner" class="highlightable {{ partialCached "archetype.hugo" (dict "hook" $hook "page" . "parameter" . "outputFormat" $outputFormat) .RelPermalink $outputFormat $hook }}" tabindex="-1">
<main id="R-body-inner" class="highlightable {{ partialCached "archetype.hugo" (dict "hook" $hook "page" . "parameter" .) .RelPermalink $hook }}" tabindex="-1">
<div class="flex-block-wrapper">
13 changes: 5 additions & 8 deletions layouts/partials/nested-article.hugo
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
{{- $page := .page }}
{{- $outputFormat := .outputFormat }}
{{- $page.Page.Store.Set "relearnIsNested" true }}
{{- with $page }}
{{- $currentNode := . }}
{{- $pages := partial "pageHelper/pagesBy.html" (dict "page" .) }}
{{- template "section-print" dict "sect" . "currentnode" $currentNode "outputFormat" $outputFormat }}
{{- template "section-print" dict "sect" . "currentnode" $currentNode }}
{{- if $pages }}
<section>
<h1 class="a11y-only">{{ T "Subsections" .Title }}</h1>
{{- end }}
{{- range $pages }}
{{- template "section-tree-print" dict "sect" . "currentnode" $currentNode "outputFormat" $outputFormat }}
{{- template "section-tree-print" dict "sect" . "currentnode" $currentNode }}
{{- end }}
{{- if $pages }}
</section>
{{- end }}
{{- end }}
{{- define "section-tree-print" }}
{{- $currentNode := .currentnode }}
{{- $outputFormat := .outputFormat }}
{{- $currentFileRelPermalink := .currentnode.RelPermalink }}
{{- with .sect }}
{{- $isSelf := eq .RelPermalink $currentFileRelPermalink }}
Expand All @@ -28,13 +26,13 @@
{{- $hidden := and $relearnIsHiddenFrom (not $.showhidden) (not $isSelf) (not $isAncestor) }}
{{- if $hidden }}
{{- else }}
{{- template "section-print" dict "sect" . "currentnode" $currentNode "outputFormat" $outputFormat }}
{{- template "section-print" dict "sect" . "currentnode" $currentNode }}
{{- if $pages }}
<section>
<h1 class="a11y-only">{{ T "Subsections" .Title }}</h1>
{{- end }}
{{- range $pages }}
{{- template "section-tree-print" dict "sect" . "currentnode" $currentNode "outputFormat" $outputFormat }}
{{- template "section-tree-print" dict "sect" . "currentnode" $currentNode }}
{{- end }}
{{- if $pages }}
</section>
Expand All @@ -44,10 +42,9 @@
{{- end }}
{{- define "section-print" }}
{{- $currentNode := .currentnode }}
{{- $outputFormat := .outputFormat }}
{{- with .sect }}
{{- $page := . }}
{{- partialCached "nested-content.hugo" (dict "page" $page "outputFormat" $outputFormat) $page.RelPermalink "outputFormat" $outputFormat }}
{{- partialCached "nested-content.hugo" (dict "page" $page) $page.RelPermalink }}
{{- range $page.Site.Params.relearn.dependencies }}
{{- $has := printf "has%s" .name }}
{{- $hasnested := printf "relearnHasNested%s" .name }}
Expand Down
5 changes: 2 additions & 3 deletions layouts/partials/nested-content.hugo
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{{- $page := .page }}
{{- $outputFormat := .outputFormat }}
{{- $content := "" }}
{{- $url := partial "relLangPrettyUglyURL.hugo" (dict "to" $page) }}
{{- if $url }}
{{- /* if we have a relative link in a print page, our print URL is one level to deep; so we are making it absolute to our page by prepending the page's permalink */}}
{{- $link_prefix := strings.TrimRight "/" $page.RelPermalink }}
{{- $content = partial "output-partial.hugo" (dict "base" "content" "page" $page "parameter" $page "outputFormat" $outputFormat) }}
{{- $content = partial "output-partial.hugo" (dict "base" "content" "page" $page "parameter" $page) }}
{{- $content = replaceRE "((?:src|href)\\s*=(?:\\s*[\"']\\s*)?)(\\.[^\"'\\s>]*|[\\w]+[^\"'\\s>:]*)([\"'\\s>])" (printf "${1}%s/${2}${3}" $link_prefix) $content }}
{{- end }}
{{- if $page.Title }}
{{- partial "output-partial.hugo" (dict "base" "article" "page" $page "parameter" (dict "page" $page "content" $content "outputFormat" $outputFormat) "outputFormat" $outputFormat) }}
{{- partial "output-partial.hugo" (dict "base" "article" "page" $page "parameter" (dict "page" $page "content" $content)) }}
{{- end }}
3 changes: 1 addition & 2 deletions layouts/partials/single-article.hugo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{- $page := .page }}
{{- $content := .content }}
{{- $outputFormat := .outputFormat }}
{{- $page.Page.Store.Set "relearnIsNested" false }}
{{- partial "output-partial.hugo" (dict "base" "article" "page" $page "parameter" (dict "page" $page "content" $content "outputFormat" $outputFormat) "outputFormat" $outputFormat) }}
{{- partial "output-partial.hugo" (dict "base" "article" "page" $page "parameter" (dict "page" $page "content" $content)) }}

0 comments on commit ac4faed

Please sign in to comment.