silverbulletmd / silverbullet

The hackable notebook
https://silverbullet.md
MIT License
2.03k stars 140 forks source link

RegisterAttributeExtractor doesn't seem to work #844

Closed montarion closed 6 days ago

montarion commented 2 months ago

I copied the example from here: https://silverbullet.md/Space%20Script#Custom%20attribute%20extractors

I changed it to filter to be custom task for this MVP:

\```space-script
silverbullet.registerAttributeExtractor({tags: ["testtask"]}, (text) => {
  // This is an MVP after all
    return {
      name: "I'm not here...",
      completed: "oops",
      noshadows: "nothing here either"
    };
  }
});
\```

I then create a task:

reindex using the Space: Reindex command, wait for it to complete, reload the page, and refresh the query for:

testtask

Which returns:

ref tag name done page pos state tags itags
misc/todolist@217 task this should have extra attributes false misc/todolist 217 testtask task, testtask

I expected 2 new attributes, 'completed' and 'noshadow'. I also expected the 'name' attribute to have changed into "I'm not here..."

What am I missing?

zefhemel commented 2 months ago

This looks like it should work, so here's what you can try:

  1. Whenever you change a space script, reload it on both client and server using the System: Reload command
  2. After reloading you can edit a page with the test task and see if it's picked up. You can reindex your entire space, but that may be overkill
  3. Have a look at the server logs to see if there are any errors. You can also put in console.logs in your function's body there to make sure your code is invoked and with what values. These logs will appear on the server in this case (if you're in online mode) or in your browser's JS console (if you're in sync mode).

Let me know what you find!

deepkn commented 4 days ago

@montarion Were you able to get this to work? I'm seeing the same issue. @zefhemel Tried the steps you suggested - but the attribute extractor does not seem to be getting invoked. I can see it being picked up when spacescript.ts runs but post that, it does not seem to be getting invoked. Tried adding a console.log() inside the function body and tried both online mode and sync mode, but it does not show up in either side. I could very well be missing something obvious - but any more ideas I can try? I don't see any errors in server side logs as well as in JS console. PS: I'm running edge.