Skip to content

Allow access to git config (user.name and user.email) during new content creation from archetype #10902

@imomaliev

Description

@imomaliev

I would like to have the ability to use .GitInfo in archetype templates to provide information about the author. It seems like .GitInfo is directly bound to the content file's git metadata, so this may not be a good candidate. But maybe there is another way to autopopulate information about author by using current git user. This will allow us to use author: {{ .GitInfo.AuthorName }} in archetype template frontmatter. There will be multiple authors for the project so I need information from git, not from config.toml

Example

Add author: {{ .GitInfo.AuthorName }} to archetypes/default.md

---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
author: {{ .GitInfo.AuthorName }}
---

Current behavior

We get an error.

$ hugo new test.md
Error: failed to execute archetype template: template: archetype.md:5:19: executing "archetype.md" at <.GitInfo.AuthorName>: can't evaluate field GitInfo in type *hugolib.archetypeFileData: template: archetype.md:5:19: executing "archetype.md" at <.GitInfo.AuthorName>: can't evaluate field GitInfo in type *hugolib.archetypeFileData

Expected behavior

New test.md content file is created

---
title: "Test"
date: 2023-04-18T16:15:43+07:00
draft: true
author: "John Doe"
---

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions