Skip to content

Add Ancestors (plural) method to GitInfo #13839

@jmooring

Description

@jmooring

We recently added an Ancestor method, but I suspect most people will want to render the full history, or the last N changes, requiring a recursive partial similar to:

{{ partial "inline/changelog.html" .GitInfo }} 

{{ define "_partials/inline/changelog.html" }}
  {{ with . }}
    {{ partial "inline/changelog.html" .Ancestor }}
    {{ .CommitDate.Format "2006-01-02" }}: {{ .Subject }}<br>
  {{ end }}
{{ end }}

Conceptually this new method would align with the .Page.Ancestors method that is commonly used when rendering a breadcrumbs UI component.

{{ with .GitInfo }}
  {{ range .Ancestors }}
    {{ .CommitDate.Format "2006-01-02" }}: {{ .Subject }}
  {{ end }}
{{ end }}

OR

{{ with .GitInfo }}
  {{ range .Ancestors | first 5 }} 
    {{ .CommitDate.Format "2006-01-02" }}: {{ .Subject }}
  {{ end }}
{{ end }}

The above would give you the last 5 changes.

If this is practical from a performance standpoint (and it may not be), and we implement an Ancestors method, it seems like the Ancestor method (singular) could be removed.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions