Is there a function to get the list of Git tags available in the project.
Saw that there is a gitinfo function, GitInfo, but is it possible to get the tags?
if not how can we get this using any custom function or code
Is there a function to get the list of Git tags available in the project.
Saw that there is a gitinfo function, GitInfo, but is it possible to get the tags?
if not how can we get this using any custom function or code
You may use the GitHub API to query a repository using resources.GetRemote
Here’s a Tips and Tricks Article Paged Rest API with Hugo v0.143.0
There’s a hopefulle comprehensive README and a link to an example implementation GitHub - irkode/hugo-forum at getRemotePaged
For your local repository there’s no such option - I would think of a prebuild step that generates a data file that you may then access in your templates/shortcodes: Data sources
Thanks for the update, Want to avoid the API call and was looking for something to be done within the local itself
say to execute a code like below
{{ $tags := (os.Exec "git" (slice "tag" "--sort=-creatordate")) }}
but found that os.Exec
is not possible, so wanted to know if we can create a custom function/module which can execute this and return the values
say a go function like this… if so how can we call this from HUGO
func GetGitTags() []string {
cmd := exec.Command("git", "tag", "--sort=-creatordate")
....
}
Run something like this from the command line before each build:
mkdir -p data
git fetch origin --tags
git tag -l --sort=version:refname --format=$'- name: %(refname:short)\n object: %(objectname)\n type: %(objecttype)' > data/tags.yaml
In the above, replace origin
with the name of the remote (e.g., upstream
) if applicable.
Then access the data from your templates using {{ site.Data.tags }}
.
The data file will look something like this:
- name: v0.136.0
object: 1ad28e1e0e1aa06725265bf3f117300d5116143c
type: commit
- name: v0.141.0
object: 8fa19b50fa4c6e99d77ca84f795540d6b75e8cc8
type: commit
executing arbitrary host commands from Hugo is not possible by design and intention
do we have a way to run a pre
scripts before hugo build (say like what we have in npm)
No, we do not.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.