mirror of
https://github.com/tomfran/typo.git
synced 2025-04-25 21:19:55 +03:00
Add support for hooks in layouts/partials/hooks
Supported hooks: - head_start - head_end - body_end - footer_start
This commit is contained in:
parent
745f0e089d
commit
fe5d64c3c8
4 changed files with 33 additions and 0 deletions
|
@ -32,6 +32,8 @@
|
|||
{{ partialCached "math.html" . }}
|
||||
{{ end }}
|
||||
|
||||
{{/* Body end hook */}}
|
||||
{{ partial "functions/get_hook.html" (dict "hook" "body_end" "context" .) }}
|
||||
</body>
|
||||
|
||||
<script src="{{ "js/theme-switch.js" | relURL }}"></script>
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
{{ $showFooter := default true .Site.Params.showFooter }}
|
||||
{{ if $showFooter }}
|
||||
{{/* Footer start hook */}}
|
||||
{{ partial "functions/get_hook.html" (dict "hook" "footer_start" "context" .) }}
|
||||
|
||||
{{ if not .Site.Params.footerContent }}
|
||||
<p>Powered by
|
||||
<a href="https://gohugo.io/">Hugo</a>
|
||||
|
|
23
layouts/partials/functions/get_hook.html
Normal file
23
layouts/partials/functions/get_hook.html
Normal file
|
@ -0,0 +1,23 @@
|
|||
{{/*
|
||||
Customize layouts without overwriting files.
|
||||
Hooks should be defined in the layouts/partials/hooks directory.
|
||||
|
||||
Parameters:
|
||||
- hook: The name of the hook to be used.
|
||||
- context: The context to be passed to the partial.
|
||||
*/}}
|
||||
|
||||
{{ $hook := .hook }}
|
||||
{{ $context := .context }}
|
||||
{{ $hookName := $hook.Name }}
|
||||
{{ $hookType := $hook.Type }}
|
||||
|
||||
{{ if not (hasSuffix $hook ".html") }}
|
||||
{{ $hook = printf "%s.html" $hook }}
|
||||
{{ end }}
|
||||
|
||||
{{ $hook_path := path.Join "layouts/partials/hooks" $hook }}
|
||||
|
||||
{{ if fileExists $hook_path }}
|
||||
{{ partial $hook_path $context }}
|
||||
{{ end }}
|
|
@ -1,6 +1,9 @@
|
|||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
|
||||
{{/* Head start hook */}}
|
||||
{{ partial "functions/get_hook.html" (dict "hook" "head_start" "context" .) }}
|
||||
|
||||
{{ $faviconPath := (.Site.Params.faviconPath | default "" | absURL) }}
|
||||
|
||||
<link rel="icon" type="image/ico" href="{{ $faviconPath }}/favicon.ico">
|
||||
|
@ -46,3 +49,5 @@
|
|||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{/* Head end hook */}}
|
||||
{{ partial "functions/get_hook.html" (dict "hook" "head_end" "context" .) }}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue