Skip to content

Commit 7d5197f

Browse files
authored
Merge pull request #11 from nkdAgility/fix-for-PDFs
Fix for PDF logic on translations page
2 parents b66e32b + 8c29212 commit 7d5197f

File tree

5 files changed

+140
-269
lines changed

5 files changed

+140
-269
lines changed

module/layouts/_partials/components/translations/community-translations.html

Lines changed: 0 additions & 215 deletions
This file was deleted.

module/layouts/_partials/components/translations/community-translations2.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ <h6 class="card-title mb-2">
146146
</div>
147147

148148
<!-- Desktop Row -->
149-
<div class="row d-none d-md-flex align-items-center py-3 border-bottom">
149+
<div class="row d-none d-md-flex align-items-center py-3 border-bottom" {{ if eq hugo.Environment "development" -}}title="ReadOnline:={{ .ReadOnline }} | ReadPDF:={{ .ReadPDF }}"{{- end -}}>
150150
<div class="col-md-4">
151151
{{ .LanguageName }}
152152
{{- if .Date }}

module/layouts/_partials/components/translations/official-version.html

Lines changed: 88 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,80 @@
1-
{{- $guidePage := . }}
1+
{{/* Official Version Component
2+
3+
This partial renders the official version section of a guide, displaying download options
4+
for the official version in the default site language. This component always uses the default
5+
site version, regardless of the current page's language context.
6+
7+
Context:
8+
- Expects the current page context (guide page)
9+
- Always references the default site (index 0 of site.Sites)
10+
- Uses the default site's page date, resources, and permalink
11+
12+
Features:
13+
- Displays founding contributors/creators with external links
14+
- Provides online reading link to the default language guide version
15+
- Shows PDF download buttons for all available language variants if available
16+
- Responsive design with mobile cards and desktop table rows
17+
- Tracks PDF downloads with data attributes for analytics
18+
19+
Language Behavior:
20+
- Always displays the default site language version of the content
21+
- Uses the first site in the sites collection (index 0) which is the default language
22+
- Explicitly uses $defaultSite := index site.Sites 0 to ensure consistent default language content
23+
- Never uses the current page's language context - always defaults to first site
24+
- PDF resources are sourced from the default language version pages
25+
26+
Dependencies:
27+
- functions/get-contributors.html partial
28+
- Bootstrap CSS classes for responsive layout
29+
- Font Awesome icons for buttons
30+
- i18n translations for labels
31+
32+
PDF Resources:
33+
- Dynamically looks for pdf/*.[language-code]*.pdf patterns based on default site language
34+
- Shows disabled button if PDF is not available
35+
*/}}
36+
{{/* Get the latest version using the function */}}
37+
{{- $latestVersion := partial "functions/get-latest-version" . }}
38+
{{/* Always use the first site in the sites collection (index 0) which is the default language
39+
This ensures consistent behavior regardless of the current page's language context
40+
*/}}
41+
{{- $defaultSite := index site.Sites 0 }}
42+
{{/* Dynamically find the latest guide page in the current section */}}
43+
{{- $guidePage := "" }}
44+
45+
{{/* Get all pages in the current section */}}
46+
{{- $sectionPages := where $defaultSite.RegularPages "Section" .Section }}
47+
48+
{{/* Filter for guide pages and sort by date (newest first) */}}
49+
{{- $guidePages := where $sectionPages "Type" "guide" }}
50+
{{- if $guidePages }}
51+
{{- $sortedPages := $guidePages.ByDate.Reverse }}
52+
{{- $guidePage = index $sortedPages 0 }}
53+
{{- end }}
54+
55+
{{/* Fallback: try to find the page with the latest version */}}
56+
{{- if and (not $guidePage) $latestVersion }}
57+
{{- range $sectionPages }}
58+
{{- $pathParts := split .RelPermalink "/" }}
59+
{{- range $pathParts }}
60+
{{- if eq . $latestVersion }}
61+
{{- $guidePage = $ }}
62+
{{- break }}
63+
{{- end }}
64+
{{- end }}
65+
{{- if $guidePage }}
66+
{{- break }}
67+
{{- end }}
68+
{{- end }}
69+
{{- end }}
70+
271
{{- $foundingContributors := partial "functions/get-contributors.html" . -}}
372
{{- $foundingContributors = where $foundingContributors "founder" true -}}
473
{{- $foundingContributors = where $foundingContributors "role" "in" (slice "contributor" "creator") -}}
574

75+
{{ $pdfPattern := printf "pdf/*.%s*.pdf" $defaultSite.Language }}
76+
{{ $pdfMatches := $guidePage.Resources.Match $pdfPattern }}
77+
678

779
<h2 class="mb-3">{{ i18n "download_official_version" . }}</h2>
880

@@ -21,7 +93,7 @@ <h2 class="mb-3">{{ i18n "download_official_version" . }}</h2>
2193
<div class="card mb-3 d-lg-none">
2294
<div class="card-body">
2395
<h6 class="card-title mb-2">
24-
English ({{ $guidePage.Date.Format "January 2006" }}) -
96+
{{ $defaultSite.Language.LanguageName }} ({{ $guidePage.Date.Format "January 2006" }}) -
2597
{{ i18n "download_official_current_version" . }}
2698
</h6>
2799
<p class="card-text text-muted mb-3">
@@ -37,26 +109,14 @@ <h6 class="card-title mb-2">
37109
<a href="{{ $guidePage.Permalink }}" class="btn btn-outline-secondary btn-sm">
38110
<i class="fa-solid fa-book-open me-1"></i>{{ i18n "read_online_action" . }}
39111
</a>
40-
<!-- PDF Download Link -->
41-
{{- $pdfPattern := printf "pdf/*.en.pdf" }}
42-
{{- $pdfResource := $guidePage.Resources.GetMatch $pdfPattern }}
43-
{{- if $pdfResource }}
44-
<a href="{{ $pdfResource.RelPermalink }}" class="btn btn-primary btn-sm pdf-download" download data-language="English" data-language-code="en" data-type="Official" data-filename="{{ $pdfResource.Name }}">
45-
<i class="fa-solid fa-download me-1"></i>EN
46-
</a>
47-
{{- else }}
48-
<a href="#" class="btn btn-primary btn-sm disabled" title="PDF not available at {{ $pdfPattern }}"> <i class="fa-solid fa-ban me-1"></i>EN </a>
49-
{{- end }}
50-
<!-- PDF Download Link -->
51-
{{- $pdfPattern := printf "pdf/*.en-us.pdf" }}
52-
{{- $pdfResource := $guidePage.Resources.GetMatch $pdfPattern }}
53-
{{- if $pdfResource }}
54-
<a href="{{ $pdfResource.RelPermalink }}" class="btn btn-primary btn-sm pdf-download" download data-language="English (US)" data-language-code="en-us" data-type="Official" data-filename="{{ $pdfResource.Name }}">
55-
<i class="fa-solid fa-download me-1"></i>EN (US)
112+
{{ range $pdfMatches }}
113+
{{ $lang := replaceRE `.*\.(?:([a-z]{2}(?:-[a-z]{2})?))\.pdf$` `$1` .Name }}
114+
<a href="{{ .RelPermalink }}" class="btn btn-primary btn-sm pdf-download" download data-language="English" data-language-code="{{ $lang | upper }}" data-type="Official" data-filename="{{ .Name }}">
115+
<i class="fa-regular fa-file-pdf"></i>{{ $lang | upper }}
56116
</a>
57-
{{- else }}
58-
<a href="#" class="btn btn-primary btn-sm disabled" title="PDF not available at {{ $pdfPattern }}"> <i class="fa-solid fa-ban me-1"></i>EN (US) </a>
59-
{{- end }}
117+
{{ else }}
118+
<a href="#" class="btn btn-primary btn-sm disabled" title="PDF not available at {{ $pdfPattern }}"> <i class="fa-solid fa-ban me-1"></i>{{ $defaultSite.Language | upper }}</a>
119+
{{ end }}
60120
</div>
61121
</div>
62122
</div>
@@ -80,26 +140,14 @@ <h6 class="card-title mb-2">
80140
<a href="{{ $guidePage.Permalink }}" class="btn btn-outline-secondary btn-sm">
81141
<i class="fa-solid fa-book-open me-1"></i>{{ i18n "read_online_action" . }}
82142
</a>
83-
<!-- PDF Download Link -->
84-
{{- $pdfPattern := printf "pdf/*.en.pdf" }}
85-
{{- $pdfResource := $guidePage.Resources.GetMatch $pdfPattern }}
86-
{{- if $pdfResource }}
87-
<a href="{{ $pdfResource.RelPermalink }}" class="btn btn-primary btn-sm pdf-download" download data-language="English" data-language-code="en" data-type="Official" data-filename="{{ $pdfResource.Name }}">
88-
<i class="fa-regular fa-file-pdf"></i>EN
89-
</a>
90-
{{- else }}
91-
<a href="#" class="btn btn-primary btn-sm disabled" title="PDF not available at {{ $pdfPattern }}"> <i class="fa-solid fa-ban me-1"></i>EN </a>
92-
{{- end }}
93-
<!-- PDF Download Link -->
94-
{{- $pdfPattern := printf "pdf/*.en-us.pdf" }}
95-
{{- $pdfResource := $guidePage.Resources.GetMatch $pdfPattern }}
96-
{{- if $pdfResource }}
97-
<a href="{{ $pdfResource.RelPermalink }}" class="btn btn-primary btn-sm pdf-download" download data-language="English (US)" data-language-code="en-us" data-type="Official" data-filename="{{ $pdfResource.Name }}">
98-
<i class="fa-regular fa-file-pdf"></i>EN-US
143+
{{ range $pdfMatches }}
144+
{{ $lang := replaceRE `.*\.(?:([a-z]{2}(?:-[a-z]{2})?))\.pdf$` `$1` .Name }}
145+
<a href="{{ .RelPermalink }}" class="btn btn-primary btn-sm pdf-download" download data-language="English" data-language-code="{{ $lang | upper }}" data-type="Official" data-filename="{{ .Name }}">
146+
<i class="fa-regular fa-file-pdf"></i>{{ $lang | upper }}
99147
</a>
100-
{{- else }}
101-
<a href="#" class="btn btn-primary btn-sm disabled" title="PDF not available at {{ $pdfPattern }}"> <i class="fa-solid fa-ban me-1"></i>EN-US</a>
102-
{{- end }}
148+
{{ else }}
149+
<a href="#" class="btn btn-primary btn-sm disabled" title="PDF not available at {{ $pdfPattern }}"> <i class="fa-solid fa-ban me-1"></i>{{ $defaultSite.Language | upper }}</a>
150+
{{ end }}
103151
</div>
104152
</div>
105153
</div>

0 commit comments

Comments
 (0)