stefanopagliari / bibnotes

360 stars 30 forks source link

Can't open pdf file using {{file}} #68

Closed zllx666 closed 2 years ago

zllx666 commented 2 years ago

Just started to use the plugin, and I found that if using {{file}} directly, the generated link will be like this: file://C:\Users...... The pdf cannot be opened until I add another slash to the link address, like this: file:///C:\Users......, maybe the default link should be modified?

By the way, I also want to ask that since Zotero6 comes with an internal pdf viewer, is that possible to generate a link that open the pdf file using the interal pdf viewer.

Thanks for the great plugin.

xuey06 commented 2 years ago

You can fix this problerm by yourself. You can open the 'main.js' file of the bibnotes-plugin folder with a text editor and search for words of 'file://’ in this file. you will see an mathched term under the item named 'function createLocalFileLink'. Then change 'file://’ into 'file:///’ and reload obsidian.

zllx666 commented 2 years ago

Thanks for the help! It's working now.

venkate123 commented 2 years ago

Just started to use the plugin, and I found that if using {{file}} directly, the generated link will be like this: file://C:\Users...... The pdf cannot be opened until I add another slash to the link address, like this: file:///C:\Users......, maybe the default link should be modified?

By the way, I also want to ask that since Zotero6 comes with an internal pdf viewer, is that possible to generate a link that open the pdf file using the interal pdf viewer.

Thanks for the great plugin.

Replacing 'createLocalFileLink' function in 'main.js' by following code allows you open files in Zotero internal pdf viewer.

function createLocalFileLink(reference2) {
  if (reference2.attachments.length == 0)
    return "{{localFile}}";
  const filesList = [];
  for (let attachmentindex = 0; attachmentindex < reference2.attachments.length; attachmentindex++) {
    if (reference2.attachments[attachmentindex].itemType !== "attachment")
      continue;
    // if (reference2.attachments[attachmentindex].path == void 0) {
    //   reference2.attachments[attachmentindex].path = "";
    // }
    // const attachmentPathCorrected = reference2.attachments[attachmentindex].path.replaceAll(" ", "%20");
    // const selectedfile = "[" + reference2.attachments[attachmentindex].title + "](file://" + attachmentPathCorrected + ")";
    if (reference2.attachments[attachmentindex].uri == void 0) {
      reference2.attachments[attachmentindex].uri = "";
    }
    const selectedfileUri = reference2.attachments[attachmentindex].uri
    const attachmentKey = selectedfileUri.split('/')[selectedfileUri.split('/').length - 1]
    selectedfile = "[" + reference2.attachments[attachmentindex].title + "](zotero://select/library/items/" + attachmentKey + ")";
    if (reference2.attachments[attachmentindex].title.endsWith('pdf')) {
      selectedfile = selectedfile.replaceAll("zotero://select/","zotero://open-pdf/");
    }
    filesList.push(selectedfile);
  }
  const filesListString = filesList.join("; ");
  return filesListString;
}
stefanopagliari commented 2 years ago

@zllx666/ @venkate123/ @xuey06 could you please let me know if the issue still persists in the latest version? I don't have a PC running Windows so I cannot replicate the problem

zllx666 commented 2 years ago

@stefanopagliari The issue is fixed in the latest version. Thanks for the freat plugin. :)