page_links.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. {{ $is_list := .is_list }}
  2. {{ $page := .page }}
  3. {{ $link := "" }}
  4. {{/* ***** TODO: Deprecate `url_preprint` in favour of `url_pdf` given there's now a dedicated "Preprint" pub. type. ***** */}}
  5. {{ with $page.Params.url_preprint }}
  6. {{ $resource := $page.Resources.GetMatch . }}
  7. {{ if $resource }}
  8. {{ $link = $resource.RelPermalink }}
  9. {{ else }}
  10. {{ $link = . | relURL }}
  11. {{ end }}
  12. <a class="btn btn-outline-primary btn-page-header{{ if $is_list }} btn-sm{{end}}" href="{{ $link }}" target="_blank" rel="noopener">
  13. {{ i18n "btn_preprint" }}
  14. </a>
  15. {{ end }}
  16. {{ $pdf := "" }}
  17. {{ $resource := $page.Resources.GetMatch (printf "%s.pdf" $page.File.ContentBaseName) }}
  18. {{ with $resource }}
  19. {{ $pdf = .RelPermalink }}
  20. {{ else }}
  21. {{ if $page.Params.url_pdf }}
  22. {{ $pdf = $page.Params.url_pdf | relURL }}
  23. {{ end }}
  24. {{ end }}
  25. {{ with $pdf }}
  26. <a class="btn btn-outline-primary btn-page-header{{ if $is_list }} btn-sm{{end}}" href="{{ . }}" target="_blank" rel="noopener">
  27. {{ i18n "btn_pdf" }}
  28. </a>
  29. {{ end }}
  30. {{ $resource := $page.Resources.GetMatch "cite.bib" }}
  31. {{ with $resource }}
  32. <a href="#" class="btn btn-outline-primary btn-page-header{{ if $is_list }} btn-sm{{end}} js-cite-modal"
  33. data-filename="{{ .RelPermalink }}">
  34. {{ i18n "btn_cite" }}
  35. </a>
  36. {{ end }}
  37. {{ with $page.Params.url_code }}
  38. {{ $resource := $page.Resources.GetMatch . }}
  39. {{ if $resource }}
  40. {{ $link = $resource.RelPermalink }}
  41. {{ else }}
  42. {{ $link = . | relURL }}
  43. {{ end }}
  44. <a class="btn btn-outline-primary btn-page-header{{ if $is_list }} btn-sm{{end}}" href="{{ $link }}" target="_blank" rel="noopener">
  45. {{ i18n "btn_code" }}
  46. </a>
  47. {{ end }}
  48. {{ with $page.Params.url_dataset }}
  49. {{ $resource := $page.Resources.GetMatch . }}
  50. {{ if $resource }}
  51. {{ $link = $resource.RelPermalink }}
  52. {{ else }}
  53. {{ $link = . | relURL }}
  54. {{ end }}
  55. <a class="btn btn-outline-primary btn-page-header{{ if $is_list }} btn-sm{{end}}" href="{{ $link }}" target="_blank" rel="noopener">
  56. {{ i18n "btn_dataset" }}
  57. </a>
  58. {{ end }}
  59. {{ if $page.Params.projects }}
  60. {{ range $page.Params.projects }}
  61. {{ with (site.GetPage (printf "project/%s" .)) }}
  62. <a class="btn btn-outline-primary btn-page-header{{ if $is_list }} btn-sm{{end}}" href="{{ .RelPermalink }}">
  63. {{ i18n "btn_project" }}
  64. </a>
  65. {{ else }}
  66. {{/* errorf "The `projects` parameter in `content/%s` references a project file, `content/project/%s`, which cannot be found. Please either set `projects = []` or fix the reference." $page.File.Path . */}}
  67. {{ end }}
  68. {{ end }}
  69. {{ else }}
  70. {{ with $page.Params.url_project }}
  71. <a class="btn btn-outline-primary btn-page-header{{ if $is_list }} btn-sm{{end}}" href="{{ . }}" target="_blank" rel="noopener">
  72. {{ i18n "btn_project" }}
  73. </a>
  74. {{ end }}
  75. {{ end }}
  76. {{ with $page.Params.url_poster }}
  77. {{ $resource := $page.Resources.GetMatch . }}
  78. {{ if $resource }}
  79. {{ $link = $resource.RelPermalink }}
  80. {{ else }}
  81. {{ $link = . | relURL }}
  82. {{ end }}
  83. <a class="btn btn-outline-primary btn-page-header{{ if $is_list }} btn-sm{{end}}" href="{{ $link }}" target="_blank" rel="noopener">
  84. {{ i18n "btn_poster" }}
  85. </a>
  86. {{ end }}
  87. {{ if $page.Params.slides }}
  88. {{ with (site.GetPage (printf "slides/%s" $page.Params.slides)) }}
  89. <a class="btn btn-outline-primary btn-page-header{{ if $is_list }} btn-sm{{end}}" href="{{ .RelPermalink }}" target="_blank">
  90. {{ i18n "btn_slides" }}
  91. </a>
  92. {{ end }}
  93. {{ else }}
  94. {{ with $page.Params.url_slides }}
  95. {{ $resource := $page.Resources.GetMatch . }}
  96. {{ if $resource }}
  97. {{ $link = $resource.RelPermalink }}
  98. {{ else }}
  99. {{ $link = . | relURL }}
  100. {{ end }}
  101. <a class="btn btn-outline-primary btn-page-header{{ if $is_list }} btn-sm{{end}}" href="{{ $link }}" target="_blank" rel="noopener">
  102. {{ i18n "btn_slides" }}
  103. </a>
  104. {{ end }}
  105. {{ end }}
  106. {{ with $page.Params.url_video }}
  107. {{ $resource := $page.Resources.GetMatch . }}
  108. {{ if $resource }}
  109. {{ $link = $resource.RelPermalink }}
  110. {{ else }}
  111. {{ $link = . | relURL }}
  112. {{ end }}
  113. <a class="btn btn-outline-primary btn-page-header{{ if $is_list }} btn-sm{{end}}" href="{{ $link }}" target="_blank" rel="noopener">
  114. {{ i18n "btn_video" }}
  115. </a>
  116. {{ end }}
  117. {{ with $page.Params.url_source }}
  118. {{ $resource := $page.Resources.GetMatch . }}
  119. {{ if $resource }}
  120. {{ $link = $resource.RelPermalink }}
  121. {{ else }}
  122. {{ $link = . | relURL }}
  123. {{ end }}
  124. <a class="btn btn-outline-primary btn-page-header{{ if $is_list }} btn-sm{{end}}" href="{{ $link }}" target="_blank" rel="noopener">
  125. {{ i18n "btn_source" }}
  126. </a>
  127. {{ end }}
  128. {{ with $page.Params.doi }}
  129. <a class="btn btn-outline-primary btn-page-header{{ if $is_list }} btn-sm{{end}}" href="https://doi.org/{{ . }}" target="_blank" rel="noopener">
  130. DOI
  131. </a>
  132. {{ end }}
  133. {{ range $page.Params.links }}
  134. {{ $pack := or .icon_pack "fas" }}
  135. {{ $pack_prefix := $pack }}
  136. {{ if in (slice "fab" "fas" "far" "fal") $pack }}
  137. {{ $pack_prefix = "fa" }}
  138. {{ end }}
  139. {{ $link := .url | default "" }}
  140. {{ $scheme := (urls.Parse $link).Scheme }}
  141. {{ $target := "" }}
  142. {{ if not $scheme }}
  143. {{ $resource := $page.Resources.GetMatch $link }}
  144. {{ if $resource }}
  145. {{ $link = $resource.RelPermalink }}
  146. {{ else }}
  147. {{ $link = $link | relURL }}
  148. {{ end }}
  149. {{ else if in (slice "http" "https") $scheme }}
  150. {{ $target = "target=\"_blank\" rel=\"noopener\"" }}
  151. {{ end }}
  152. <a class="btn btn-outline-primary btn-page-header{{ if $is_list }} btn-sm{{end}}" href="{{ $link | safeURL }}" {{ $target | safeHTMLAttr }}>
  153. {{ if .icon }}<i class="{{ $pack }} {{ $pack_prefix }}-{{ .icon }} {{if .name}}mr-1{{end}}"></i>{{end}}
  154. {{- with .name }}{{ . | safeHTML }}{{ end -}}
  155. </a>
  156. {{ end }}