refactor(edit_post): improve edit post URL handling and readability

This commit is contained in:
Aditya Telange
2026-05-03 12:47:39 +05:30
parent f82488f1f9
commit 30f865ef21
+18 -8
View File
@@ -1,10 +1,20 @@
{{- if and (or .Params.editPost.URL site.Params.editPost.URL) (not (.Param "editPost.disabled")) -}}
{{- $fileUrlPath := path.Join .File.Path }}
{{- if and (.Param "editPost.URL") (not (.Param "editPost.disabled")) -}}
{{- if or (.Param "author") (.Param "ShowReadingTime") (not .Date.IsZero) .IsTranslated }}
{{- printf " | " | safeHTML -}}
{{- end -}}
{{- if or .Params.author site.Params.author (.Param "ShowReadingTime") (not .Date.IsZero) .IsTranslated }} | {{- end -}}
<span>
<a href="{{ .Params.editPost.URL | default site.Params.editPost.URL }}{{ if .Params.editPost.appendFilePath | default ( site.Params.editPost.appendFilePath | default false ) }}/{{ $fileUrlPath }}{{ end }}" rel="noopener noreferrer edit" target="_blank">
{{- .Params.editPost.Text | default (site.Params.editPost.Text | default (i18n "edit_post" | default "Edit")) -}}
</a>
</span>
{{- $editURL := .Param "editPost.URL" }}
{{- $appendFilePath := .Param "editPost.appendFilePath" | default false }}
{{- $editText := .Param "editPost.Text" | default (i18n "edit_post" ) -}}
{{- if $appendFilePath -}}
{{- $fileUrlPath := path.Join .File.Path }}
{{- $editURL = printf "%s/%s" $editURL $fileUrlPath -}}
{{- end -}}
<span>
<a href="{{ $editURL }}" rel="noopener noreferrer edit" target="_blank">
{{- $editText -}}
</a>
</span>
{{- end }}