Skip to content

Commit

Permalink
Show authors list in the list of items
Browse files Browse the repository at this point in the history
  • Loading branch information
MunGell committed Jun 23, 2024
1 parent 86797bc commit 4ea3780
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/ZoteroItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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() {
Expand Down Expand Up @@ -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(),
Expand Down
18 changes: 17 additions & 1 deletion src/ZoteroSuggestModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,24 @@ export class ZoteroSuggestModal extends SuggestModal<ZoteroItem> {
}

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) {
Expand Down
3 changes: 3 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.zotero-bridge__text-secondary {
color: var(--text-faint);
}

0 comments on commit 4ea3780

Please sign in to comment.