page_edit.html 1.2 KB

12345678910111213141516171819
  1. {{/* This makes `edit_page` optional in `params.toml` and prevents errors if it's removed. */}}
  2. {{ if site.Params.edit_page }}
  3. {{ if site.Params.edit_page.repo_url | and (index site.Params.edit_page.editable .Type) | and (ne .Params.editable false) | or .Params.editable }}
  4. {{/* Get language subfolder for multilingual sites. */}}
  5. {{/* Limitations: the subfolder param, `<LANG>.contentDir`, is unexposed in the Hugo `site` API so we attempt to workaround this issue. */}}
  6. {{ $content_dir := "content" }}
  7. {{ if site.Params.edit_page.content_dir }}
  8. {{ $content_dir = site.Params.edit_page.content_dir }}
  9. {{else}}
  10. {{/* Attempt to get content dir from the LanguagePrefix URI, but defaultContentLanguageInSubdir can break this assumption. */}}
  11. {{ $content_dir = cond site.IsMultiLingual (cond (ne .Site.LanguagePrefix "") (printf "%s%s" $content_dir .Site.LanguagePrefix) $content_dir) $content_dir }}
  12. {{end}}
  13. <p class="edit-page">
  14. <a href="{{site.Params.edit_page.repo_url}}/edit/{{site.Params.edit_page.repo_branch | default "main"}}/{{$content_dir}}/{{.File.Path}}">
  15. <i class="fas fa-pen pr-2"></i>{{ i18n "edit_page" | default "Edit this page" }}
  16. </a>
  17. </p>
  18. {{ end }}
  19. {{ end }}