Open imomaliev opened 1 year ago
What is the use case? Why do you need to store this value in front matter instead of accessing the value during build?
The current .GitInfo
is tied to directly to the last Git commit. When you create a new content file there's no commit yet, so I don't see how this would work on the technical level.
What is the use case? Why do you need to store this value in front matter instead of accessing the value during build?
We are trying to use Hugo to host ADRs (Architectural Decision Records). It would be useful to take a value of an author
from the git on hugo new
command call and extract it into the document, it will be imprinted in the document's frontmatter the same way date
does.
When you create a new content file there's no commit yet, so I don't see how this would work on the technical level.
Yes, I assumed that and wrote in my original post that .GitInfo
may not fit my request because it is bound to the git history of the document and doesn't have access to the general git configuration of the repository.
Maybe there is some other way to provide this info for the archetype template?
@imomaliev
It would be useful to take a value...
I understand what you want to do, but I am asking why you want to do it instead of extracting .GitInfo.AuthorName during the build?
but I am asking why you want to do it instead of extracting .GitInfo.AuthorName during the build?
I want to have author
to be viewable from gitlab UI or source as well. If it will be available only after build, we wouldn't be able to just open ADR as markdown file and be able to tell who the author was
If you do this from the command line:
HUGO_GIT_USER_NAME=$(git config user.name) hugo new something
You can do this in your archetype:
user = '{{ os.Getenv "HUGO_GIT_USER_NAME" }}'
Or export the env var from .bashrc, etc.
if git -v &> /dev/null; then
export HUGO_GIT_USER_NAME=$(git config user.name)
fi
@jmooring Thank you. I will try this.
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 useauthor: {{ .GitInfo.AuthorName }}
in archetype template frontmatter. There will be multiple authors for the project so I need information from git, not from config.tomlExample
Add
author: {{ .GitInfo.AuthorName }}
toarchetypes/default.md
Current behavior
We get an error.
Expected behavior
New
test.md
content file is created