From 1b6a1ca0cdc33cf18eba9823f39424e89bb0476f Mon Sep 17 00:00:00 2001 From: James Elliott Date: Thu, 20 Jan 2022 11:36:43 +1100 Subject: [PATCH 1/2] feat: edit link docs repo subpath Can be used if the folder with your content is in a subfolder so if your project wishes to contain code and docs in the same repo it's convenient to do so. Additionally includes some refactoring in the edit-page.html logic to make it easier to manage. --- config/_default/params.toml | 3 ++- layouts/partials/main/edit-page.html | 25 +++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/config/_default/params.toml b/config/_default/params.toml index b9f36ca..84f272a 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -66,11 +66,12 @@ alertDismissable = true alertText = "Introducing the Doks child theme, several DX + UX updates, and more! Check out Doks v0.2" # Edit Page -# repoHost [Github | Gitea | GitLab] is used for building the edit link based on git hoster +# repoHost [Github | Gitea | GitLab | Bitbucket ] is used for building the edit link based on git hoster repoHost = "GitHub" #repoHost = "Gitea" docsRepo = "https://github.com/h-enk/doks" docsRepoBranch = "master" +docsRepoSubPath = "" editPage = false lastMod = false diff --git a/layouts/partials/main/edit-page.html b/layouts/partials/main/edit-page.html index 30c0dba..71e310a 100644 --- a/layouts/partials/main/edit-page.html +++ b/layouts/partials/main/edit-page.html @@ -1,16 +1,29 @@ +{{ $parts := slice .Site.Params.docsRepo }} {{ $filePath := replace .File.Path "\\" "/" }} -{{ $editPath := "null" }} {{ if (eq .Site.Params.repoHost "GitHub") }} - {{ $editPath = "/blob/" }} + {{ $parts = $parts | append "blob" .Site.Params.docsRepoBranch }} {{ else if (eq .Site.Params.repoHost "Gitea") }} - {{ $editPath = "/_edit/" }} + {{ $parts = $parts | append "_edit" .Site.Params.docsRepoBranch }} {{ else if (eq .Site.Params.repoHost "GitLab") }} - {{ $editPath = "/-/blob/" }} + {{ $parts = $parts | append "-/blob" .Site.Params.docsRepoBranch }} +{{ else if (eq .Site.Params.repoHost "Bitbucket") }} + {{ $parts = $parts | append "browse" .Site.Params.docsRepoBranch }} {{ end }} -{{ $contentPath := print .Site.Params.docsRepo $editPath .Site.Params.docsRepoBranch "/content/" }} -{{ $url := print $contentPath .Lang "/" $filePath }} +{{ if isset .Site.Params "docsreposubpath" }} + {{ if not (eq .Site.Params.docsRepoSubPath "") }} + {{ $parts = $parts | append .Site.Params.docsRepoSubPath }} + {{ end }} +{{ end }} + +{{ if .Site.Params.options.multilingualMode }} + {{ $parts = $parts | append "content" .Lang $filePath }} +{{ else }} + {{ $parts = $parts | append "content" $filePath }} +{{ end }} + +{{ $url := delimit $parts "/" }}
From b063faaf376ab9a47315177d4a11e2f63f7d4899 Mon Sep 17 00:00:00 2001 From: James Elliott Date: Thu, 20 Jan 2022 11:43:20 +1100 Subject: [PATCH 2/2] fix: correct bitbucket Bitbucket (bitbucket.org) is different to BitbucketServer, so made sure to add the distinction. Also moved a declaration closer to where it's used. --- config/_default/params.toml | 2 +- layouts/partials/main/edit-page.html | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/config/_default/params.toml b/config/_default/params.toml index 84f272a..f8a684b 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -66,7 +66,7 @@ alertDismissable = true alertText = "Introducing the Doks child theme, several DX + UX updates, and more! Check out Doks v0.2" # Edit Page -# repoHost [Github | Gitea | GitLab | Bitbucket ] is used for building the edit link based on git hoster +# repoHost [Github | Gitea | GitLab | Bitbucket | BitbucketServer ] is used for building the edit link based on git hoster repoHost = "GitHub" #repoHost = "Gitea" docsRepo = "https://github.com/h-enk/doks" diff --git a/layouts/partials/main/edit-page.html b/layouts/partials/main/edit-page.html index 71e310a..5f5d762 100644 --- a/layouts/partials/main/edit-page.html +++ b/layouts/partials/main/edit-page.html @@ -1,5 +1,4 @@ {{ $parts := slice .Site.Params.docsRepo }} -{{ $filePath := replace .File.Path "\\" "/" }} {{ if (eq .Site.Params.repoHost "GitHub") }} {{ $parts = $parts | append "blob" .Site.Params.docsRepoBranch }} @@ -8,6 +7,8 @@ {{ else if (eq .Site.Params.repoHost "GitLab") }} {{ $parts = $parts | append "-/blob" .Site.Params.docsRepoBranch }} {{ else if (eq .Site.Params.repoHost "Bitbucket") }} + {{ $parts = $parts | append "src" .Site.Params.docsRepoBranch }} +{{ else if (eq .Site.Params.repoHost "BitbucketServer") }} {{ $parts = $parts | append "browse" .Site.Params.docsRepoBranch }} {{ end }} @@ -17,6 +18,8 @@ {{ end }} {{ end }} +{{ $filePath := replace .File.Path "\\" "/" }} + {{ if .Site.Params.options.multilingualMode }} {{ $parts = $parts | append "content" .Lang $filePath }} {{ else }}