diff --git a/src/ZoteroItem.ts b/src/ZoteroItem.ts index 8278c78..da0f46e 100644 --- a/src/ZoteroItem.ts +++ b/src/ZoteroItem.ts @@ -26,8 +26,6 @@ export class ZoteroItem { return this.raw.shortTitle || this.raw.title || this.getNoteExcerpt() || '[No Title]'; } - // @todo: some transformations in this class should be moved to ZotServer - // breaking changes for ZotServer v2 getAuthors() { return this.getCreators() .filter(creator => creator.creatorType === 'author') @@ -43,7 +41,7 @@ export class ZoteroItem { } getDate() { - return this.raw.date ? this.formatDate(this.raw.date) : ''; + return this.raw.date ? this.formatDate(this.raw.date) : null; } getNoteExcerpt() { @@ -80,6 +78,10 @@ export class ZoteroItem { formatDate(date: string) { const dateObject = new Date(date); + if (isNaN(dateObject.getTime())) { + return null; + } + return { year: dateObject.getFullYear(), month: dateObject.getMonth(), diff --git a/src/ZoteroSuggestModal.ts b/src/ZoteroSuggestModal.ts index 4264dbb..fd00edd 100644 --- a/src/ZoteroSuggestModal.ts +++ b/src/ZoteroSuggestModal.ts @@ -18,8 +18,24 @@ export class ZoteroSuggestModal extends SuggestModal { } renderSuggestion(item: ZoteroItem, el: HTMLElement) { + const authors = item.getAuthors(); el.createEl('div', { text: item.getTitle() }); - el.createEl('small', { text: item.getKey() }); + + // author + if (authors.length > 0) { + let text = authors[0].fullName + ' '; + if (authors.length > 1) { + text += 'et al. ' + } + el.createEl('small', { text }); + + // date + if (item.getDate()) { + el.createEl('small', { text: `(${item.getDate().year}) ` }); + } + } + + el.createEl('small', { text: `[${item.getKey()}]`, cls: 'zotero-bridge__text-secondary' }); } onChooseSuggestion(item: ZoteroItem) { diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..e90a6f1 --- /dev/null +++ b/styles.css @@ -0,0 +1,3 @@ +.zotero-bridge__text-secondary { + color: var(--text-faint); +}