mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 17:15:31 +00:00
87 lines
3.2 KiB
Plaintext
87 lines
3.2 KiB
Plaintext
{{- /*
|
|
Global citation component for resolving IssueRef elements
|
|
Usage: {{ template "_citation" $issueRef }}
|
|
|
|
Input: xmlmodels.IssueRef with fields:
|
|
- .Nr (int): Issue number
|
|
- .Von (int): Starting page
|
|
- .Bis (int): Ending page (optional)
|
|
- .Beilage (int): Beilage number (optional)
|
|
- .When (DateAttributes): Date information
|
|
|
|
Outputs: citation text + link with minimal formatting
|
|
Automatically detects current page and styles accordingly
|
|
*/ -}}
|
|
|
|
{{- $issue := . -}}
|
|
{{- $issueKey := printf "%d-%d" $issue.When.Year $issue.Nr -}}
|
|
{{- $issueData := GetIssue $issueKey -}}
|
|
{{- $url := printf "/%s/%d" $issue.When $issue.Nr -}}
|
|
<a href="{{- $url -}}{{- if $issue.Von -}}
|
|
{{- if $issue.Beilage -}}
|
|
/b{{ $issue.Beilage }}-{{ $issue.Von }}
|
|
{{- else -}}
|
|
/{{ $issue.Von }}
|
|
{{- end -}}
|
|
{{- end -}}"
|
|
class="citation-link no-underline"
|
|
data-citation-url="{{ $url }}">
|
|
{{- if $issueData -}}
|
|
{{ $issueData.Datum.When.Day }}.{{ $issueData.Datum.When.Month }}.{{ $issueData.Datum.When.Year }}/{{ $issue.Nr }}
|
|
{{- else -}}
|
|
{{ $issue.When.Year }}/{{ $issue.Nr }}
|
|
{{- end -}}
|
|
{{- if $issue.Von }}, {{ if $issue.Beilage }}Beil. {{ else }}S. {{ end }}{{ $issue.Von }}{{- if and $issue.Bis (ne $issue.Von $issue.Bis) -}}
|
|
-{{ $issue.Bis }}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
</a>
|
|
|
|
<script>
|
|
// Check if citation links point to current page (without hash)
|
|
function updateCitationLinks() {
|
|
const currentPath = window.location.pathname;
|
|
const citationLinks = document.querySelectorAll('.citation-link[data-citation-url]');
|
|
|
|
citationLinks.forEach(link => {
|
|
const citationUrl = link.getAttribute('data-citation-url');
|
|
let isCurrentPage = false;
|
|
|
|
// Check for exact match
|
|
if (citationUrl === currentPath) {
|
|
isCurrentPage = true;
|
|
} else {
|
|
// Check if current path is an issue with page number that matches this citation
|
|
const currentPathMatch = currentPath.match(/^\/(\d{4})\/(\d+)(?:\/(\d+))?$/);
|
|
const citationUrlMatch = citationUrl.match(/^\/(\d{4})\/(\d+)$/);
|
|
|
|
if (currentPathMatch && citationUrlMatch) {
|
|
const [, currentYear, currentIssue, currentPage] = currentPathMatch;
|
|
const [, citationYear, citationIssue] = citationUrlMatch;
|
|
|
|
// If year and issue match, this citation refers to the current issue
|
|
if (currentYear === citationYear && currentIssue === citationIssue) {
|
|
isCurrentPage = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (isCurrentPage) {
|
|
// Style as current page: red text, no underline, not clickable
|
|
link.classList.add('text-red-700', 'pointer-events-none');
|
|
link.setAttribute('aria-current', 'page');
|
|
} else {
|
|
// Reset to default styling for non-current pages
|
|
link.classList.remove('text-red-700', 'pointer-events-none');
|
|
link.removeAttribute('aria-current');
|
|
}
|
|
});
|
|
}
|
|
|
|
// Run on initial load
|
|
document.addEventListener('DOMContentLoaded', updateCitationLinks);
|
|
|
|
// Run on HTMX page swaps
|
|
document.addEventListener('htmx:afterSwap', updateCitationLinks);
|
|
document.addEventListener('htmx:afterSettle', updateCitationLinks);
|
|
</script> |