Browse Source

feat(pub): auto detect PDF and generate link

To automatically generate a PDF link for a publication, place a
PDF in your publication's own folder which has the same name as the
folder.
George Cushen 6 years ago
parent
commit
315fb47cf7
1 changed files with 15 additions and 2 deletions
  1. 15 2
      layouts/partials/publication_links.html

+ 15 - 2
layouts/partials/publication_links.html

@@ -6,8 +6,21 @@
   {{ i18n "btn_preprint" }}
 </a>
 {{ end }}
-{{ with $.Params.url_pdf }}
-<a class="btn btn-outline-primary my-1 mr-1{{ if $is_list }} btn-sm{{end}}" href="{{ . | relURL }}" target="_blank" rel="noopener">
+{{ $pdf := "" }}
+{{ $slug := "" }}
+{{ if eq $.File.TranslationBaseName "index" }}{{/* Check if using dir-based page bundles. */}}
+  {{ $slug = delimit (last 1 (split (substr $.Dir 0 -1) "/")) "" }}
+{{ end }}
+{{ $resource := $.Resources.GetMatch (printf "%s.pdf" $slug) }}
+{{ with $resource }}
+  {{ $pdf = .RelPermalink }}
+{{ else }}
+  {{ if $.Params.url_pdf }}
+    {{ $pdf = $.Params.url_pdf | relURL }}
+  {{ end }}
+{{ end }}
+{{ with $pdf }}
+<a class="btn btn-outline-primary my-1 mr-1{{ if $is_list }} btn-sm{{end}}" href="{{ . }}" target="_blank" rel="noopener">
   {{ i18n "btn_pdf" }}
 </a>
 {{ end }}