frthjf / obsidian-zotero-sync-client

A Zotero Sync client for Obsidian
GNU Affero General Public License v3.0
24 stars 3 forks source link

How to render standalone notes #14

Closed ulahcherubim closed 7 months ago

ulahcherubim commented 7 months ago

First of all, thank you for your work. When I tried this plugin I noticed that I only got child notes. Is there a way to get standalone notes into Obsidian? Preferably with their related fields parsed as links? Thanks again!

frthjf commented 7 months ago

Hi @ulahcherubim,

Sorry, I am not sure what you mean by 'standalone notes'. When you go to the plugin settings, you should be able to see all available ZoteroItems of your library (if not, there might be an issue with the key or you may need to select another library)

You are free to parse the data however you like by modifying the template code in the settings.

ulahcherubim commented 7 months ago

I feel like my problem could be about how Zotero stores standalone notes. I mean note items without a parent item when I say standalone notes.

frthjf commented 7 months ago

Ok, I see what you mean. The standalone notes are handled like any other item in the library, so you should be able to generate Obsidian notes for them by adjusting the template in the plugin settings.

The raw data for a note looks like this (you can preview the data in the settings):

{
    "key": "IZR6D6W3",
    "version": 8079,
    "itemType": "note",
    "note": "<div data-schema-version=\"8\"><p>test</p>\n</div>",
    "tags": [],
    "collections": [
        "N9DRRV32"
    ],
    "relations": {},
    "dateAdded": "2024-04-01T18:14:43Z",
    "dateModified": "2024-04-01T18:14:47Z",
    "note_markdown": "test",
    "children": [],
    "super_collections": [
        "N9DRRV32"
    ]
}

So to generate the note, modify the template to generate a file name and content for that itemType.

For example:

+ if (data.itemType == 'note') {
+   // generate and return a title somehow; this may be tricky since notes only have content
+    return 'Zotero Notes/' + data.key;
+ }
if (data.itemType == 'collection') {
   return;
}
...
+ if (data.itemType == 'note') {
+   // return the note content
+    return data.note_markdown;
+ }
let n = '';
if (data.creators) {
...

Once you apply these changes, the note should appear under Zotero Notes/IZR6D6W3.md.

I am going to close this for now, but let me know if there are any other issues.

frthjf commented 7 months ago

It seems like Zotero uses the first line of the note as the title, to replicate that behavior you may use something like this:

if (data.itemType == 'note') {
   // use first line in note as title
   return 'Zotero Notes/' + (data.note_markdown.split("\n")[0] || 'Untitled Note');
}
ulahcherubim commented 7 months ago

Thank you for the solution but I couldn't get it to work somehow. I don't have any experience in coding so it is not unexpected. I tried adding your adjusted code to the default template but couldn't figure out how. What I need is only standalone notes in my library synced to Obsidian with their respective titles, tags and related field's title parsed in double bracket at the end of the note. I am sorry for the inconvenience, I will try to get some of my friends to make it work as I need.