Skip to content

Commit

Permalink
fix: repo widget
Browse files Browse the repository at this point in the history
Use hugo.WorkingDir instead of Site.Language.ContentDir to generate the edit and view links
  • Loading branch information
razonyang committed May 23, 2023
1 parent c58320d commit 54c3ac0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions exampleSite/config/_default/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ timeout = "120s"

[build]
writeStats = true

[security.funcs]
getenv = ['^HUGO_', '^CI$', 'PWD']
4 changes: 2 additions & 2 deletions layouts/partials/docs/repo.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{{- $branch := default "master" .branch -}}
{{- $dateFormat := default "02/01/2006, 15:04:05 PM" .dateFormat -}}
{{- $subPath := default "" .subPath -}}
{{- $contentDir := default "content" $.Site.Language.ContentDir -}}
{{- $root := partialCached "functions/working-directory" . }}
{{- if $subPath -}}{{ $subPath = printf "/%s" $subPath }}{{- end -}}
<div class="accordion">
<div class="accordion-item docs-repo row card component">
Expand All @@ -27,7 +27,7 @@ <h2 class="card-title fs-4 my-2 text-surface d-none d-lg-block">{{ i18n "repo_ti
<div class="card-body collapse accordion-collapse accordion-body text-secondary-on-surface d-lg-block{{ if not $collapsed }} show{{ end }}" id="repo" aria-labelledby="repo-header">
<ul class="list-unstyled">
{{- if $.File -}}
{{- $filePath := printf "%s%s/%s/%s" $branch $subPath $contentDir $.File.Path -}}
{{- $filePath := printf "%s/%s%s" $branch $subPath (strings.TrimPrefix $root $.File.Filename) -}}
<li class="mb-1">
<a href="{{ printf $sourceUrlFormat $url $filePath }}" target="_blank" rel="noopener noreferrer">
<i class="fas fa-fw fa-file-archive text-success"></i> {{ i18n "repo_action_view" }}
Expand Down
7 changes: 7 additions & 0 deletions layouts/partials/functions/working-directory.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{- $dir := "" }}
{{- if ge hugo.Version "0.112.0" }}
{{- $dir = hugo.WorkingDir }}
{{- else }}
{{- $dir = os.Getenv "PWD" }}
{{- end }}
{{- return $dir }}

0 comments on commit 54c3ac0

Please sign in to comment.