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.
This commit is contained in:
James Elliott
2022-01-20 11:36:43 +11:00
parent 40a8705ab6
commit 1b6a1ca0cd
2 changed files with 21 additions and 7 deletions

View File

@ -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 "/" }}
<div class="edit-page">
<a href="{{ $url }}">