Skip to content

Commit

Permalink
perf: use Ancestors for section titles
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Jun 16, 2024
1 parent ee0b20b commit 8655e18
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions layouts/partials/base/functions/sections-titles.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
{{/* Returns the ancestral sections titles of current page, except home page. */}}
{{- $titles := slice }}
{{/* Get parent section of the page. */}}
{{- $section := cond .IsSection .Parent .CurrentSection }}
{{- if ne $section . }}
{{- with $section }}
{{/* Break the loop if home page reached. */}}
{{- if not .IsHome }}
{{- $titles = $titles | append .Title }}
{{/* Dive deeper. */}}
{{- $titles = $titles | append (partial "base/functions/sections-titles" .) }}
{{- end }}
{{- range .Ancestors }}
{{/* Break the loop if home page reached. */}}
{{- if .IsHome }}
{{- continue }}
{{- end }}
{{- $titles = $titles | append .Title }}
{{- end }}
{{- return $titles }}

0 comments on commit 8655e18

Please sign in to comment.