From 315fb47cf74dc361e7b04400d191299816577d68 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Wed, 17 Oct 2018 22:30:50 +0100 Subject: [PATCH] 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. --- layouts/partials/publication_links.html | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/layouts/partials/publication_links.html b/layouts/partials/publication_links.html index 186f3142..623e772a 100644 --- a/layouts/partials/publication_links.html +++ b/layouts/partials/publication_links.html @@ -6,8 +6,21 @@ {{ i18n "btn_preprint" }} {{ end }} -{{ with $.Params.url_pdf }} - +{{ $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 }} + {{ i18n "btn_pdf" }} {{ end }}