From 598671aab3d3c7b668312adde96371829ca21ad5 Mon Sep 17 00:00:00 2001 From: Will Faught Date: Fri, 7 Feb 2025 23:21:13 -0800 Subject: [PATCH] Add include file kind variants --- README.md | 18 +++++++++++++++++ layouts/_default/baseof.html | 19 ++++-------------- layouts/partials/paige/func-include.html | 25 ++++++++++++++++++++++++ layouts/partials/paige/page-footer.html | 8 ++------ layouts/partials/paige/page-header.html | 8 ++------ layouts/partials/paige/site-footer.html | 8 ++------ layouts/partials/paige/site-header.html | 8 ++------ layouts/partials/paige/tag-head.html | 10 ++-------- 8 files changed, 57 insertions(+), 47 deletions(-) create mode 100644 layouts/partials/paige/func-include.html diff --git a/README.md b/README.md index b8bbd0f6..0f3fd1e4 100644 --- a/README.md +++ b/README.md @@ -935,6 +935,8 @@ Body: None. ### Include +Files can be included in many places in HTML. + | If this file exists | It is included at | | ---------------------------------------------------------| -------------------------------------| | `yoursite/layouts/partials/paige/body-first.html` | The beginning of the body tag | @@ -954,6 +956,22 @@ Body: None. | `yoursite/layouts/partials/paige/style-first.css` | The beginning of the style tag | | `yoursite/layouts/partials/paige/style-last.css` | The end of the style tag | +There are kind variants of include files that are included only when the file kind matches the page kind. + +| If this file exists | It is included when | +| --------------------------------------------------------| ----------------------------| +| `yoursite/layouts/partials/paige/[PLACE]-home.html` | The page kind is "home" | +| `yoursite/layouts/partials/paige/[PLACE]-page.html` | The page kind is "page" | +| `yoursite/layouts/partials/paige/[PLACE]-section.html` | The page kind is "section" | +| `yoursite/layouts/partials/paige/[PLACE]-taxonomy.html` | The page kind is "taxonomy" | +| `yoursite/layouts/partials/paige/[PLACE]-term.html` | The page kind is "term" | + +Above, the place placeholder must be "body-first", "body-last", "head-first", etc. + +Kind variants are included right after their counterpart non-kind variant. + +The argument for the templates is the page. + ### Override Most code is in partial templates that the layout templates use. diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 47eb5819..adc69ce3 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -14,32 +14,21 @@ {{ partial "paige/tag-head.html" $page }} {{ partial "paige/tag-body.html" $page }} - {{ if templates.Exists "partials/paige/body-first.html" }} - {{ partial "paige/body-first.html" $page }} - {{ end }} + {{ partial "paige/func-include.html" (dict "name" "body-first%s.html" "page" $page) }}
- {{ if templates.Exists "partials/paige/site-first.html" }} - {{ partial "paige/site-first.html" $page }} - {{ end }} - + {{ partial "paige/func-include.html" (dict "name" "site-first%s.html" "page" $page) }} {{ partial "paige/site-header.html" $page }} {{ block "main" $page }}{{ end }} {{ partial "paige/site-footer.html" $page }} - - {{ if templates.Exists "partials/paige/site-last.html" }} - {{ partial "paige/site-last.html" $page }} - {{ end }} + {{ partial "paige/func-include.html" (dict "name" "site-last%s.html" "page" $page) }}
{{ partial "paige/scripts.html" $page }} - - {{ if templates.Exists "partials/paige/body-last.html" }} - {{ partial "paige/body-last.html" $page }} - {{ end }} + {{ partial "paige/func-include.html" (dict "name" "body-last%s.html" "page" $page) }} diff --git a/layouts/partials/paige/func-include.html b/layouts/partials/paige/func-include.html new file mode 100644 index 00000000..f9f0d2ce --- /dev/null +++ b/layouts/partials/paige/func-include.html @@ -0,0 +1,25 @@ +{{ $params := . }} + +{{ $name := $params.name }} +{{ $page := $params.page }} + +{{ $partial := print "paige/" (printf $name "") }} + +{{ $file := print "partials/" $partial }} + +{{ if templates.Exists $file }} + {{ partial $partial $page }} +{{ end }} + +{{ range slice "home" "page" "section" "taxonomy" "term" }} + {{ $partial := print "paige/" (printf $name (print "-" .)) }} + + {{ $file := print "partials/" $partial }} + + {{ $exists := templates.Exists $file }} + {{ $matches := eq $page.Kind . }} + + {{ if and $exists $matches }} + {{ partial $partial $page }} + {{ end }} +{{ end }} diff --git a/layouts/partials/paige/page-footer.html b/layouts/partials/paige/page-footer.html index 238a9bd2..1a17bb88 100644 --- a/layouts/partials/paige/page-footer.html +++ b/layouts/partials/paige/page-footer.html @@ -19,9 +19,7 @@ {{ if or $edit $history $first $last $next $prev }} {{ end }} diff --git a/layouts/partials/paige/page-header.html b/layouts/partials/paige/page-header.html index c5f3f79c..f8e4c211 100644 --- a/layouts/partials/paige/page-header.html +++ b/layouts/partials/paige/page-header.html @@ -22,9 +22,7 @@ {{ if or $alert $authors $date $description $first $keywords $last $time $series $title $toc }}
- {{ if $first }} - {{ partial "paige/page-header-first.html" . }} - {{ end }} + {{ partial "paige/func-include.html" (dict "name" "page-header-first%s.html" "page" $page) }} {{ with $title }}

{{ if $link }}{{ . }}{{ else }}{{ . }}{{ end }}

@@ -104,9 +102,7 @@
{{ end }} - {{ if $last }} - {{ partial "paige/page-header-last.html" . }} - {{ end }} + {{ partial "paige/func-include.html" (dict "name" "page-header-last%s.html" "page" $page) }}
{{ end }} diff --git a/layouts/partials/paige/site-footer.html b/layouts/partials/paige/site-footer.html index 67bce1bb..236c0a0a 100644 --- a/layouts/partials/paige/site-footer.html +++ b/layouts/partials/paige/site-footer.html @@ -17,9 +17,7 @@ {{ if or $copyright $credit $first $last $license }} {{ end }} diff --git a/layouts/partials/paige/site-header.html b/layouts/partials/paige/site-header.html index fd5da055..0457d929 100644 --- a/layouts/partials/paige/site-header.html +++ b/layouts/partials/paige/site-header.html @@ -34,9 +34,7 @@ {{ if or $breadcrumbs $description $first $last $menu $title }}
- {{ if $first }} - {{ partial "paige/site-header-first.html" $page }} - {{ end }} + {{ partial "paige/func-include.html" (dict "name" "site-header-first%s.html" "page" $page) }} {{ with $title }}
{{ . }}
@@ -162,8 +160,6 @@ {{ end }} - {{ if $last }} - {{ partial "paige/site-header-last.html" $page }} - {{ end }} + {{ partial "paige/func-include.html" (dict "name" "site-header-last%s.html" "page" $page) }}
{{ end }} diff --git a/layouts/partials/paige/tag-head.html b/layouts/partials/paige/tag-head.html index 1c46b171..984e482b 100644 --- a/layouts/partials/paige/tag-head.html +++ b/layouts/partials/paige/tag-head.html @@ -23,10 +23,7 @@ {{ $title = delimit $titles " ยท " }} - {{ if templates.Exists "partials/paige/head-first.html" }} - {{ partial "paige/head-first.html" $page }} - {{ end }} - + {{ partial "paige/func-include.html" (dict "name" "head-first%s.html" "page" $page) }} {{ partial "paige/metas.html" $page }} {{ with $title }} @@ -35,8 +32,5 @@ {{ partial "paige/links.html" $page }} {{ partial "paige/style.html" $page }} - - {{ if templates.Exists "partials/paige/head-last.html" }} - {{ partial "paige/head-last.html" $page }} - {{ end }} + {{ partial "paige/func-include.html" (dict "name" "head-last%s.html" "page" $page) }}