Remove TOC

Hi. I recently upgraded from v1 to v2 and have some questions about things I had automated before, but I’m not sure how to do them now. I’ll create a separate thread for each topic so everything doesn’t get mixed up in case someone needs the information in the future.

First, I had a tag (#notoc) to remove the tables of contents on some pages.

The code was as follows:

```space-config
objectDecorators:
- where: 'tags = "notoc"'
  attributes:
     pageDecoration.disableTOC: "true"

How would it be done in v2?

Try this — you need to replace the existing widgets.toc function (defined in your workspace at Library/Std/Widgets):

space-lua
--priority: 9
local oldtoc = widgets.toc
function widgets.toc(options)
    local pageTags = editor.getCurrentPageMeta()
    if table.includes(pageTags, "notoc") then
        return
    else
        return oldtoc()
    end
end

I used a similar version filtered on name of the page to remove TOC from those pages

Thanks. I’ve understood that you execute this code with more priority (9 over 10 at Library/Std/Widgets).

I don’t know why but, for the moment, doesn’t work. The TOC always appears.

I’ve tried to put only a “return” inside the function to always remove the TOC, but neither.

How can I know if this code is ever executed?

I have two thoughts:

  1. I don’t want to be presumptuous but I ran into this issue initially and then embarrassingly discovered that I wasn’t actually on v2 but was on v1. Once I migrated to v2, the script worked. Are you certain? i.e. if you check your Docker compose file or run “client: version” from the command palette, do you see Silverbullet 2.0.0?

  2. Where are you storing this space-lua. I have mine at /CONFIG. Did you try to edit Library/Std/Widgets? (Not sure if you actually can…)

If neither of these are true, then I apologize, I don’t have a better solution for you currently.

The first point could be a real posibility :smiley: but, no:

I had placed the code in an article called Meta/NoTOC, tagged #meta.

I’ve tried adding it to CONFIG article, after the existing code, but it still doesn’t do anything.

Thanks anyway.

For me at least this version

--priority: 9
function widgets.toc(options)
    return
end

inside a normal spacelua block on a normal page works.

Did you try it like that or did you just put the return before the other code, because returns have to always be the last statement in lua?
Also the table.includes doesn’t seem to work for me, I wrote about that in the general chat.