From e880cd5381567e274a3b402b762aec3bda79cfd1 Mon Sep 17 00:00:00 2001 From: gzwongkk Date: Sun, 7 Aug 2022 00:55:39 +0800 Subject: [PATCH] Fix commas in author list (#770) --- _config.yml | 6 ++-- _layouts/bib.html | 80 ++++++++++++++++++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 21 deletions(-) diff --git a/_config.yml b/_config.yml index 3bc296bac382..cca03098737f 100644 --- a/_config.yml +++ b/_config.yml @@ -235,8 +235,10 @@ scholar: # Filter out certain bibtex entry keywords used internally from the bib output filtered_bibtex_keywords: [abbr, abstract, arxiv, bibtex_show, html, pdf, selected, supp, blog, code, poster, slides, website, preview] -# Maximum number of authors to be shown, other authors will be visible on hover, leave blank to show all authors -max_author_limit: 3 +# Maximum number of authors to be shown for each publication (more authors are visible on click) +max_author_limit: 3 # leave blank to always show all authors +more_authors_animation_delay: 10 # more authors are revealed on click using animation; smaller delay means faster animation + # ----------------------------------------------------------------------------- # Responsive WebP Images diff --git a/_layouts/bib.html b/_layouts/bib.html index b280df1cd237..c3af0dc2872a 100644 --- a/_layouts/bib.html +++ b/_layouts/bib.html @@ -28,27 +28,69 @@ {% endif %} --> -
- {% if entry.type == "thesis" %} - {{reference}} - {% else %} -
{{entry.title}}
-
- {% for author in entry.author_array %} - {% assign author_is_self = false %} - {% if author.last == site.scholar.last_name%} - {% if site.scholar.first_name contains author.first%} - {% assign author_is_self = true %} - {% endif %} + +
+ {% if entry.type == "thesis" -%} + {{reference}} + {%- else %} + +
{{entry.title}}
+ +
+ {% assign author_array_size = entry.author_array | size %} + + {% assign author_array_limit = author_array_size %} + {%- if site.max_author_limit and author_array_size > site.max_author_limit %} + {% assign author_array_limit = site.max_author_limit %} + {% endif %} + + {%- for author in entry.author_array limit: author_array_limit -%} + {%- assign author_is_self = false -%} + {%- assign author_last_name = author.last | remove: "¶" | remove: "&" | remove: "*" | remove: "†" | remove: "^" -%} + {%- if author_last_name == site.scholar.last_name -%} + {%- if site.scholar.first_name contains author.first -%} + {%- assign author_is_self = true -%} + {%- endif -%} + {%- endif -%} + {%- assign coauthor_url = nil -%} + {%- if site.data.coauthors[author_last_name] -%} + {%- for coauthor in site.data.coauthors[author_last_name] -%} + {%- if coauthor.firstname contains author.first -%} + {%- assign coauthor_url = coauthor.url -%} + {%- break -%} + {%- endif -%} + {%- endfor -%} + {%- endif -%} + + {%- if forloop.length > 1 -%} + {%- if forloop.first == false -%}, {%- endif -%} + {%- if forloop.last and author_array_limit == author_array_size -%}and {%- endif -%} + {%- endif -%} + {%- if author_is_self -%} + {{author.first}} {{author.last}} + {%- else -%} + {%- if coauthor_url -%} + {{author.first}} {{author.last}} + {%- else -%} + {{author.first}} {{author.last}} + {%- endif -%} + {%- endif -%} + {%- endfor -%} + {%- assign more_authors = author_array_size | minus: author_array_limit -%} - {% assign more_authors_show = '' %} + {%- assign more_authors_hide = more_authors | append: " more author" -%} + {%- if more_authors > 0 -%} + {%- if more_authors > 1 -%} + {%- assign more_authors_hide = more_authors_hide | append: "s" -%} + {%- endif -%} + {%- assign more_authors_show = '' -%} {%- for author in entry.author_array offset: author_array_limit -%} - {% assign more_authors_show = more_authors_show | append: author.last | append: ", " | append: author.first %} - {% unless forloop.last %} - {% assign more_authors_show = more_authors_show | append: ", " %} - {% endunless %} + {%- assign more_authors_show = more_authors_show | append: author.first | append: " " | append: author.last -%} + {%- unless forloop.last -%} + {%- assign more_authors_show = more_authors_show | append: ", " -%} + {%- endunless -%} {%- endfor -%} - and + , and {{more_authors_hide}} {% endif %}