I would like to extend the code snippet from @jmooring Hugo v0.112.0 - New template functions. The idea is to display the last link that was created for a certain page and with a click on the button the corresponding commit should be displayed in GitLab.
hugo.toml
[params.repository]
branch = 'main'
owner = 'example'
repo = 'developer'
service = 'GitLab'
urlPatternCommit = 'https://gitlab.com/%s/%s/-/commits/%s/%s'
urlPatternEdit = 'https://gitlab.com/%s/%s/-/edit/%s/%s'
urlPatternView = 'https://gitlab.com/%s/%s/-/blob/%s/%s'
urlPatternIssues = 'https://gitlab.com/%s/%s/-/issues/new?title=%s/%s'
single.html
{{ define "main" }}
<div class="container">
<div class="row">
<div class="col p-4 my-4">
{{ .Content }}
{{ $published := .PublishDate | time.Format ":date_medium" }}
{{ $modified := .Lastmod | time.Format ":date_medium" }}
{{ if ne $published $modified }}
<span> Last modified: {{ $modified }} </span>
{{ if not .Params.disableGitLabEditLink }}
{{ partial "repository-link.html" (dict "action" "commits" "page" .) }}
{{ partial "repository-link.html" (dict "action" "edit" "page" .) }}
{{ partial "repository-link.html" (dict "action" "view" "page" .) }}
{{ partial "repository-link.html" (dict "action" "issues" "page" .) }}
{{ end }}
{{ end }}
</div>
</div>
</div>
{{ end }}
repository-link.html
{{- if $.page.File }}
{{- with site.Params.repository }}
{{- $path := strings.TrimPrefix hugo.WorkingDir $.page.File.Filename }}
{{- $href := "" }}
{{- $text := "" }}
{{- if eq $.action "commits" }}
{{- $href = printf .urlPatternCommit .owner .repo .branch $path | urls.JoinPath }}
{{- $text = printf "Last commit: %s" .GitInfo.AbbreviatedHash }}
{{- else if eq $.action "edit" }}
{{- $href = printf .urlPatternEdit .owner .repo .branch $path | urls.JoinPath }}
{{- $text = printf "Edit this page on %s" .service }}
{{- else if eq $.action "view" }}
{{- $href = printf .urlPatternView .owner .repo .branch $path | urls.JoinPath }}
{{- $text = printf "View this page on %s" .service }}
{{- else if eq $.action "issues" }}
{{- $href = printf .urlPatternIssues .owner .repo .branch $path | urls.JoinPath }}
{{- $text = printf "New issue on %s" .service }}
{{- end }}
<div class="repository-link">
<a href="{{ $href }}" class="btn btn-outline-secondary btn-sm my-1" type="button" rel="external">{{ $text }}</a>
</div>
{{- end }}
{{- end -}}