From 4f16b311f7aee36ee78dbef87531f91b96bf6ace Mon Sep 17 00:00:00 2001 From: Colin Wilson Date: Tue, 29 Aug 2023 02:16:47 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20fix=20for=20#43=20(edit=20this=20pa?= =?UTF-8?q?ge=20enhancement)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exampleSite/hugo.toml | 3 ++- layouts/docs/single.html | 2 +- layouts/partials/docs/gitinfo.html | 23 +++++++++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/exampleSite/hugo.toml b/exampleSite/hugo.toml index fb0760f1..668c1c86 100644 --- a/exampleSite/hugo.toml +++ b/exampleSite/hugo.toml @@ -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 diff --git a/layouts/docs/single.html b/layouts/docs/single.html index 8d3cf72f..0fb744b3 100644 --- a/layouts/docs/single.html +++ b/layouts/docs/single.html @@ -5,7 +5,7 @@ {{ .Content }} - {{ if and .GitInfo .Site.Params.docs.ghrepo -}} + {{ if and .GitInfo .Site.Params.docs.repoURL -}} {{ partial (printf "%s/%s" ($.Scratch.Get "pathName") "gitinfo") . }} {{ end -}} diff --git a/layouts/partials/docs/gitinfo.html b/layouts/partials/docs/gitinfo.html index 1975c063..fe83249d 100644 --- a/layouts/partials/docs/gitinfo.html +++ b/layouts/partials/docs/gitinfo.html @@ -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 "/") }} +
{{ if .Site.Params.docs.editPage | default false -}}