How to automatate authors list with zotero integration

Hi everyone,
I recently receive a great help from @Feralflora about how automatate pdf attachment.

I am thinking in doing something similar to authors list, than I can create personal descritptions and identify publications.
Do you think is possible to apply a similar code to authors, when importing zotero files?

2 Likes

Can you clarify what exactly you are looking for in this case? Is it formatting the authors as links in the properties? Or something more advanced?

Not sure about OP, but I am looking for this solution. My use case is:

  1. I use zotero integration to import bibliographic data and annotations into Literature Notes.
  2. I also have Scholar Notes (for key scholars), the title = author name.
  3. I have an author property in the Literature Notes template that uses Zotero Integration [[{{authors}}]] so that it will link to a note of that name.

This works fine if the Literature Note only has one author, but I’m running into issues when there are multiple authors as it groups the different authors into the one property (even if I use a list).

I’m sure it’s the function I’m using, but I haven’t figured out the fix yet.

I have a partial solution for you, although I am still working out how to adjust the code for a false outcome. This is likely not sophisticated at all (I am learning as I go), but it could help you figure it out.

I have a properties field that extracts the creator data, doing this in a list format so that the property will link to a scholar note (if one exists) to create a relationship between scholar and literature notes.

The code including the linking brackets is:

[[{{creators[0].firstName + " " + creators[0].lastName}}]]

The code without linking brackets is:

{{creators[0].firstName + " " + creators[0].lastName}}

For my purposes (since it’s in the list properties) I need to enter this multiple times, changing the zeros to 1, then 2 etc. This will then pick up the corresponding author in the list. I don’t have sources with more than four authors (or I wouldn’t need the data for them) so I have authors 0, 1, 2, and 3.

The limitation with this is when there isn’t data to export (i.e., I fewer authors than I’m looking for with the code) it returns ā€˜undefined undefined’ for each property lacking an author. I am hoping to figure out a solution for this soon. It also tries to link authors that do not have a scholar page (although I’m not bothered by that).

You could apply something like this in your template, formatting the exported fields as a heading. For example:

# {{creators[0].firstName + " " + creators[0].lastName}}

I hope this is somewhat helpful :slightly_smiling_face:

Links in the properties have to be surrounded by quotation marks outside the square brackets to be recognized as links. Like so: "[[{{creators[0].firstName + " " + creators[0].lastName}}]]".

Instead of hardcoding how many authors there are, or you expect, you can just use a for-loop to apply the same formatting to every creator.

I don’t format them as links in the properties, but here’s how I do it:

{%- set camelRegex = r/([a-z])([A-Z])/g %}
{%- for type, creators in creators | groupby("creatorType") %} 
{% if creators.length > 1 %}{{type | replace(camelRegex, "$1 $2") | lower | trim}}s:{%- for creator in creators %}{% if creator.name %}
- {{creator.name}}{% else%}
- {{creator.firstName}} {{creator.lastName}} {% endif %}{%- endfor %} {% else -%}
{{type | replace(camelRegex, "$1-$2") | lower | trim}}:{%- for creator in creators %}{% if creator.name %} "{{creator.name}}"{% else%} "{{creator.firstName}} {{creator.lastName}}"{% endif -%}{%- endfor -%}{% endif -%}{% endfor %}

This looks extra convoluted because I am not putting all creators under ā€œcreatorsā€, but instead I have them grouped under their creatorType, which can be stuff like ā€œauthorā€, ā€œeditorā€, ā€œdirectorā€, ā€œcontributerā€ etc.

I am also accounting for the fact that creators can have a creator.name which is a single line name, typically the case for organizations, or they can have firstName and lastName.

I am using the camelRegex to remove the camelCase, so it becomes ā€œseries-editorā€ instead of ā€œseriesEditorā€, for example.

Lastly, I check for the number of creators in each creatorType group. If there’s only one, the key is singular, e.g. ā€œauthor: John Doeā€, and plural if there are several creators of that type, e.g.

authors:
- John Doe
- Jane Doe

The code is ugly, but the output is not.

For a simpler implementation of a non-grouped for-loop over all creators, formatted as links, you could do something like:

---
creators:
{% for creator in creators %}
	{%- if creator.name -%}
		- "[[{{creator.name}}]]"
	{%- else -%}
		- "[[{{creator.firstName}} {{creator.lastName}}]]"
	{%- endif %}
{% endfor -%}
---
2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.