Skip to content

Commit 87abfcf

Browse files
committed
Google Scholar - More robust CSL date parsing
When we render to CSLJSON using pandoc and an invalid date is present, the CSL date is an empty array rather than undefined, so we need to be aware of this. Fixes #8362
1 parent 911ab16 commit 87abfcf

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed

news/changelog-1.5.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ All changes included in 1.5:
33
## HTML Format
44

55
- ([#8118](https://github.com/quarto-dev/quarto-cli/issues/8118)): Add support for `body-classes` to add classes to the document body.
6+
- ([#8426](https://github.com/quarto-dev/quarto-cli/issues/8426)): Ignore invalid dates for references when generating Google Scholar data.
67

78
## Other Fixes
89

src/core/csl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export function suggestId(author: CSLName[], date?: CSLDate) {
165165
// See https://www.loc.gov/standards/datetime/
166166
// Currently omits time component so this isn't truly level 0
167167
export function cslDateToEDTFDate(date: CSLDate) {
168-
if (date["date-parts"]) {
168+
if (date["date-parts"] && date["date-parts"].length > 0) {
169169
const paddedParts = date["date-parts"][0].map((part) => {
170170
const partStr = part?.toString();
171171
if (partStr?.length === 1) {

src/format/html/format-html-meta.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,21 @@ function googleScholarMeta(
136136

137137
if (csl.issued) {
138138
const edtfIssued = cslDateToEDTFDate(csl.issued);
139-
write("citation_publication_date", edtfIssued);
140-
write("citation_cover_date", edtfIssued);
139+
if (edtfIssued) {
140+
write("citation_publication_date", edtfIssued);
141+
write("citation_cover_date", edtfIssued);
142+
}
141143
const parts = csl.issued["date-parts"];
142-
if (parts) {
144+
if (parts && parts.length > 0) {
143145
write("citation_year", parts[0][0]);
144146
}
145147
}
146148

147149
if (csl["available-date"]) {
148-
write("citation_online_date", cslDateToEDTFDate(csl["available-date"]));
150+
const edtfAvailable = cslDateToEDTFDate(csl["available-date"]);
151+
if (edtfAvailable) {
152+
write("citation_online_date", edtfAvailable);
153+
}
149154
}
150155

151156
if (csl.URL) {
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: Hello World
3+
format: html
4+
bibliography: bad.bib
5+
google-scholar: true
6+
nocite: |
7+
@*
8+
---
9+
10+
## Hello.
11+
12+
### References
13+
14+
::: {#refs}
15+
:::
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
@article{guo2020,
3+
title = {The origin, transmission and clinical therapies on coronavirus disease 2019 (COVID-19) outbreak {\textendash} an update on the status of our research.},
4+
author = {{Guo}, {Yan-Rong} and {Cao}, {Qing-Dong} and {Hong}, {Zhong-Si} and {Tan}, {Yuan-Yang} and {Chen}, {Shou-Deng} and {Jin}, {Hong-Jun} and {Tan}, {Kai-Sen} and {Wang}, {De-Yun} and {Yan}, {Yan}},
5+
year = {2020},
6+
month = {12},
7+
date = {2020-12},
8+
journal = {Military Medical Research},
9+
pages = {11},
10+
volume = {7},
11+
number = {1},
12+
doi = {10.1186/s40779-020-00240-0},
13+
url = {https://mmrjournal.biomedcentral.com/articles/10.1186/s40779-020-00240-0},
14+
langid = {en}
15+
}
16+
17+
18+
@book{hootsteinWearingFourPairs2012,
19+
title = {Wearing Four Pairs of Shoes: {{The}} Roles of e-Learning Facilitators},
20+
author = {Hootstein, Ed},
21+
year = {August 16, 2012 2002},
22+
publisher = {{American Society for Training and Development}},
23+
abstract = {The emergence of e-learning comes at a time when education and training are undergoing important transformations. The teacher-centered model that has dominated instruction for centuries is slowly giving way to a learner-centered model with instructors in the roles of facilitators or "guides on the side." E-learning is no exception. But e-learning's use doesn't preclude facilitators' responsibilities for structuring learning experiences. The effectiveness and success of e-learning programs are dependent on facilitators' roles in delivering and managing instruction. One of the leading conceptualizers in the field of distance learning, Zane Berge, broke down an instructor's role in computer conferencing into four separate parts. I propose a similar model, in which an e-learning facilitator "wears four pairs of shoes"{\textendash}acting as instructor, social director, program manager, and technical assistant.}
24+
}

0 commit comments

Comments
 (0)