Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: edit link docs repo subpath #618

Merged
merged 2 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ alertDismissable = true
alertText = "Introducing the Doks child theme, several DX + UX updates, and more! <a class=\"alert-link stretched-link\" href=\"https://getdoks.org/blog/doks-v0.2/\">Check out Doks v0.2</a>"

# Edit Page
# repoHost [Github | Gitea | GitLab] 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"
docsRepoBranch = "master"
docsRepoSubPath = ""
editPage = false
lastMod = false

Expand Down
30 changes: 23 additions & 7 deletions layouts/partials/main/edit-page.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
{{ $filePath := replace .File.Path "\\" "/" }}
{{ $editPath := "null" }}
{{ $parts := slice .Site.Params.docsRepo }}

{{ 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 "src" .Site.Params.docsRepoBranch }}
{{ else if (eq .Site.Params.repoHost "BitbucketServer") }}
{{ $parts = $parts | append "browse" .Site.Params.docsRepoBranch }}
{{ end }}

{{ if isset .Site.Params "docsreposubpath" }}
{{ if not (eq .Site.Params.docsRepoSubPath "") }}
{{ $parts = $parts | append .Site.Params.docsRepoSubPath }}
{{ end }}
{{ end }}

{{ $filePath := replace .File.Path "\\" "/" }}

{{ if .Site.Params.options.multilingualMode }}
{{ $parts = $parts | append "content" .Lang $filePath }}
{{ else }}
{{ $parts = $parts | append "content" $filePath }}
{{ end }}

{{ $contentPath := print .Site.Params.docsRepo $editPath .Site.Params.docsRepoBranch "/content/" }}
{{ $url := print $contentPath .Lang "/" $filePath }}
{{ $url := delimit $parts "/" }}

<div class="edit-page">
<a href="{{ $url }}">
Expand Down