diff --git a/content/glossary/_create_glossaries.py b/content/glossary/_create_glossaries.py index 3bd7c7bce80..e8366d81c16 100755 --- a/content/glossary/_create_glossaries.py +++ b/content/glossary/_create_glossaries.py @@ -47,32 +47,45 @@ def process_references(references_text, apa_lookup, missing_refs_log=None): if not references_text: return [] - citation_pattern = r'\\?\[@([^\\]+)\\?\]' - matches = re.findall(citation_pattern, references_text) - formatted_refs = [] - for match in matches: - # Clean the key: remove markdown formatting, trailing punctuation, etc. - key = match.strip() - original_key = key # Keep for logging - - # Remove markdown formatting - key = re.sub(r'^\*+|\*+$', '', key) # Remove leading/trailing asterisks - key = re.sub(r'^_+|_+$', '', key) # Remove leading/trailing underscores - - # Remove trailing punctuation - key = re.sub(r'[,;:]+$', '', key) - - # Remove trailing digits that look like typos (e.g., "Pownall20210" -> "Pownall2021") - key = re.sub(r'(\d{4})0+$', r'\1', key) - - if key in apa_lookup: - formatted_refs.append(apa_lookup[key]) - else: - # Log missing reference but don't include in output + + # Match [@key] format (Pandoc citations) + # Pattern handles: \[@key\], [@key], \[@key], [@key\] + # The Google Sheets may have escaped brackets (\[@key\]) from Markdown, + # so we match both escaped and unescaped versions + citation_pattern = r'\\?\[@([^\]\\]+)\\?\]' + matches = re.findall(citation_pattern, references_text) + + if matches: + # Process [@key] format citations + for match in matches: + # Clean the key: remove markdown formatting, trailing punctuation, etc. + key = match.strip() + original_key = key # Keep for logging + + # Remove markdown formatting + key = re.sub(r'^\*+|\*+$', '', key) # Remove leading/trailing asterisks + key = re.sub(r'^_+|_+$', '', key) # Remove leading/trailing underscores + + # Remove trailing punctuation + key = re.sub(r'[,;:]+$', '', key) + + # Remove trailing digits that look like typos (e.g., "Pownall20210" -> "Pownall2021") + key = re.sub(r'(\d{4})0+$', r'\1', key) + + if key in apa_lookup: + formatted_refs.append(apa_lookup[key]) + else: + # Log missing reference but don't include in output + if missing_refs_log is not None: + missing_refs_log.add(original_key) + print(f"Warning: Missing reference key '{original_key}' (cleaned: '{key}') - skipping") + else: + # No citation keys found - log a warning + if references_text.strip(): + print(f"Warning: No citation keys found in: '{references_text[:50]}...'") if missing_refs_log is not None: - missing_refs_log.add(original_key) - print(f"Warning: Missing reference key '{original_key}' (cleaned: '{key}') - skipping") + missing_refs_log.add(f"[NO KEYS]: {references_text[:50]}") return list(dict.fromkeys(formatted_refs)) diff --git a/layouts/glossary/single.html b/layouts/glossary/single.html index 370998ebd78..3e1ccbc9c2f 100644 --- a/layouts/glossary/single.html +++ b/layouts/glossary/single.html @@ -192,9 +192,21 @@ {{ end }} {{ if .Params.references }} - {{ $references := delimit .Params.references ", " | len }} - {{ if ne $references 0 }} -

{{ if gt (len .Params.references) 1 }}{{ index (index $dictionary $lang) "references" }}{{ else }}{{ index (index $dictionary $lang) "reference" }}{{ end }}: {{ delimit .Params.references ", " ", & " | markdownify }}

+ {{ $refs := .Params.references }} + {{ $refsIsString := eq (printf "%T" $refs) "string" }} + {{ if $refsIsString }} + {{ if ne $refs "" }} +

{{ index (index $dictionary $lang) "references" }}: {{ $refs | markdownify }}

+ {{ end }} + {{ else }} + {{ if gt (len $refs) 0 }} + {{ $firstRef := index $refs 0 }} + {{ if $firstRef }} + {{ $refLabel := index (index $dictionary $lang) "reference" }} + {{ if gt (len $refs) 1 }}{{ $refLabel = index (index $dictionary $lang) "references" }}{{ end }} +

{{ $refLabel }}: {{ range $index, $ref := $refs }}{{ if $index }}, {{ end }}{{ $ref }}{{ end }}

+ {{ end }} + {{ end }} {{ end }} {{ end }}