Skip to content

Commit

Permalink
⚡ fix for #43 (edit this page enhancement)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinwilson committed Aug 29, 2023
1 parent 4cb7089 commit 4f16b31
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion exampleSite/hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ defaultContentLanguage = 'en'
prism = true # enable syntax highlighting via Prism

# gitinfo
ghrepo = "github.com/colinwilson/lotusdocs.dev" # Git repository URL for your site
repoURL = "https://github.com/colinwilson/lotusdocs.dev" # Git repository URL for your site
repoBranch = "release"
editPage = true # enable 'Edit this page' feature - default false
lastMod = true # enable 'Last modified' date on pages - default false
lastModRelative = true # format 'Last modified' time as relative - default true
Expand Down
2 changes: 1 addition & 1 deletion layouts/docs/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{{ .Content }}
</div>

{{ if and .GitInfo .Site.Params.docs.ghrepo -}}
{{ if and .GitInfo .Site.Params.docs.repoURL -}}
{{ partial (printf "%s/%s" ($.Scratch.Get "pathName") "gitinfo") . }}
{{ end -}}

Expand Down
23 changes: 21 additions & 2 deletions layouts/partials/docs/gitinfo.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
{{ $repoURL := slice .Site.Params.docs.repoURL }}
{{ $repoHostname := (urls.Parse (.Site.Params.docs.repoURL)).Hostname }}
{{ $filePath := replace .File.Path "\\" "/" }}
{{ $iconPath := "" }}

{{ if strings.Contains ($repoHostname | lower) "github" }}
{{ $repoURL = $repoURL | append "blob" (.Site.Params.docs.repoBranch | default "main") }}
{{ $iconPath = "images/social/github_icon.svg" }}
{{ else if strings.Contains ($repoHostname | lower) "gitlab" }}
{{ $repoURL = $repoURL | append "-/blob" (.Site.Params.docs.repoBranch | default "main") }}
{{ $iconPath = "images/social/gitlab_icon.svg" }}
{{ else if strings.Contains ($repoHostname | lower) "bitbucket" }}
{{ $repoURL = $repoURL | append "src" (.Site.Params.docs.repoBranch | default "master") }}
{{ $iconPath = "images/social/bitbucket_icon.svg" }}
{{ end }}

{{ $repoURL = $repoURL | append "content" .Site.LanguagePrefix $filePath }}
{{ $editPageURL := path.Clean (delimit $repoURL "/") }}

<div class="gitinfo d-flex flex-wrap justify-content-between align-items-center opacity-85 {{ if and .Site.Params.docs.lastMod .Site.Params.docs.editPage -}}pt-3{{ else }}visually-hidden{{ end }}">
{{ if .Site.Params.docs.editPage | default false -}}
<div id="edit-this-page" class="mt-1">
<a href="https://{{ .Site.Params.docs.ghrepo }}/blob/{{ .GitInfo.Hash }}/content/{{ path.Clean .File.Path }}/" alt="{{ .Title }}" rel="noopener noreferrer" target="_blank">
<a href="{{ $editPageURL }}" alt="{{ .Title }}" rel="noopener noreferrer" target="_blank">
<!-- <span class="material-icons size-20 align-text-bottom text-primary">edit</span> -->
<span class="me-1 align-text-bottom">
{{ with resources.Get "images/social/github_icon.svg" }}
{{ with resources.Get $iconPath }}
{{ .Content | safeHTML }}
{{ end }}
</span>
Expand Down

0 comments on commit 4f16b31

Please sign in to comment.