Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Insert note feature #2

Closed
wants to merge 1 commit into from
Closed

Conversation

frthjf
Copy link

@frthjf frthjf commented Jun 1, 2022

Thanks a lot for your plugin, it's great!

In my vault, I like to put the Zotero links into their own file so it's easy to reference notes related to the literature from there.

I've extended the plugin to do this note creation from a template automatically via an "Zotero: Insert note" command similar to the existing "Zotero: Insert Link" command.

If you are interested in adding such a feature, here is an initial implementation.

@MunGell
Copy link
Collaborator

MunGell commented Jun 5, 2022

Hi @frthjf

Thank you for your contribution, I am going to merge it now!

I am also thinking how this use case could be generalized to avoid configuring multiple templates in this plugin.

I will look into integrating into Templater and Temple so that this plugin will provide data and template-focused plugins will provide ability to put it into any form or shape.

It I will find a way to do so, we might move this functionality to templates instead, what do you think?

@frthjf
Copy link
Author

frthjf commented Jun 5, 2022

Great, thanks. Yes, I think delegating the template parsing to other plugins is a good idea! Let me know if I can help with anything. Thanks again for your work here!

@MunGell
Copy link
Collaborator

MunGell commented Jun 7, 2022

Hi @frthjf

I had some time on the weekend and gone with full refactoring of the plugin. It is now turned into API-first plugin that provides access to Zotero through ZotServer.

What it means in practice that it exposes API through window object, which is then consumable by other plugins or code in the system.

Zotero Link insertion is now extracted into a separate plugin that uses this API (so you need to have Zotero Bridge (new name of this plugin) and Zotero Link installed to get link insertion working).

For the note insertion - it is now possible to have access to Zotero from Templater user scripts.

Example of how this could be used below:

Templater user script called zotero.js:

module.exports = async function(prop) {
    const item = await PluginApi.ZoteroBridge.v1().search();
    return item.getValues()[prop];
}

Then, this function can be used in template like this:

<% tp.user.zotero('title') %>

I am having an issue with accessing properties of returned object (e.g. <% tp.user.zotero('firstAuthor').lastName %>, but I probably didn't spend enough time on learning eta

I believe this will allow template for your use case without needing additional plugins installed (other than Templater and Zotero Bridge).

I would really appreciate if you could look into re-creating your template with Templater user script setup and see if it works for you.

@MunGell
Copy link
Collaborator

MunGell commented Jun 11, 2022

I think I got it working:

zotero.js:

module.exports = async function () {
    const item = await PluginApi.ZoteroBridge.v1().search();
    return (prop) => dotAccess(prop, item.getValues());
}

function dotAccess(str, obj) {
    return str.split('.').reduce((previousValue, currentValue) => previousValue[currentValue], obj);
}

Templater template:

<%* const zi = await tp.user.zotero() %>


<% zi('firstAuthor.lastName') %><%* if (zi('authors.length')  == 2) { %> and <% zi('authors')[1].lastName %><%* } else if (zi('authors.length') > 2) { %> et al.<%* } %> <% zi('date.year') %> <% zi('title') %>

@frthjf
Copy link
Author

frthjf commented Jun 13, 2022

Cool, thanks, that makes sense! Looks like it's working for me 👍

@MunGell
Copy link
Collaborator

MunGell commented Jun 13, 2022

Glad to hear it works for you! :)

I am going to close this PR now

@MunGell MunGell closed this Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants