TOC based on backlinks?

Hello everyone

I have been playing with my altered version of the toc macro, and it is working great.

But I am wondering if there could be a parallel toc macro based on backlinks rather than tags.

The principal benefit would be at the point of creating new tiddlers and connecting them to the toc:

When you are in a tiddler and type to add tags via the tag editor, it only offers as possibilities the existing tags. That might be a couple dozen options. And it is likely that the tiddlers at the outermost branches of the toc have not become tags yet. They might still be only tiddlers tagged with the next level up in the toc. So they will not show in the available options in the tag editor when you want to add the present tiddler to a tiddler in the outermost branch of the toc.

But when you type [[ in a file that has the editcomptext plugin, it offers as possibilities ALL existing tiddlers that have the search string. I have even tweaked the editcomptext plugin so it offers me missing+tiddlers, so I get even more suggestions. I can link to any tiddler in the toc, even the outermost tiddlers.

Granted, that can lead to a problem at the other extreme, too many options in the list, and no assurance that the tiddler I backlinked toward is connected to the toc.

But the ability to create a toc based on backlinks would speed up the process of creating an expansive toc.

Just a thought…I would like to hear others’ perspectives on this…

The ToC macros are written in wikitext here and it looks like it should be pretty straightforward to replace the “tag” bits with whatever filterfragment you want, in whichever ToC-variant you want. I.e you copy the ToC variant you want into a new tiddler tagged $:/tags/Macroand fiddle around a bit.

What is straightforward for you is not so much for me. But I might try my hand at it. Blessings.

1 Like

This handles only the simplest toc case. Each toc has it’s own macro, which would have to be tweaked. Here I renamed toc and toc-body to btoc and btoc-body respectively. A more thorough refactoring would change the internal variable “tag” name.

image

\define btoc-body(tag,sort:"",itemClassFilter,exclude,path)
<ol class="tc-toc">
  <$list filter="""[title<__tag__>backlinks[]!has[draft.of]$sort$] -[<__tag__>] -[enlist<__exclude__>]""">
    <$vars item=<<currentTiddler>> path={{{ [<__path__>addsuffix[/]addsuffix<__tag__>] }}}>
      <$set name="excluded" filter="""[enlist<__exclude__>] [<__tag__>]""">
        <$set name="toc-item-class" filter=<<__itemClassFilter__>> emptyValue="toc-item-selected" value="toc-item">
          <li class=<<toc-item-class>>>
            <$list filter="[all[current]toc-link[no]]" emptyMessage="<$link to={{{ [<currentTiddler>get[target]else<currentTiddler>] }}}><$view field='caption'><$view field='title'/></$view></$link>">
              <<toc-caption>>
            </$list>
            <$macrocall $name="btoc-body" tag=<<item>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> exclude=<<excluded>> path=<<path>>/>
          </li>
        </$set>
      </$set>
    </$vars>
  </$list>
</ol>
\end

\define btoc(tag,sort:"",itemClassFilter:"")
<$macrocall $name="btoc-body"  tag=<<__tag__>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> />
\end

I am in the process of tackling this myself by extending the capabilities of the tag editor and the view tags. Specifically modifying or cloning the tag-picker macro $:/core/macros/tag-picker

  • I am finding editing/retrofitting/rewriting $:/core/macros/tag-picker very difficult
  • I would like to create a “tiddler picker” to which we can provide a fieldname, filter and placeholder (replacing “tag name”)
    • Since the fieldname can be tags and the filter [tags[]] it can do the same job as tag-picker
    • However it could be used to do the following both in edit and view modes.
      • Pick any tiddler title including not yet a tag and add it to the tags
      • Pick a tag from a filtered subset of tags
      • Pick any tiddler title and add it to any field, including multiple items eg a tiddler list
        • And as defined by any filter

Thus I will raise this in the Developer category.
[Edited] Raised here Wikitext and widget MACRO solution for tiddler-picker - HELP NEEDED

Tidgraph may be a nice solution for this!

1 Like

Thanks Mark! I will try this today.

This worked well when entering into a tiddler at the Stroll site. It did not work when using as a $:/tags/Macro tiddler. I get errors about too much recursion.

I think maybe $:/StoryList is interfering?

This version provides a little safety net, to prevent diving down too deep.

<<btoc tag:"HelloThere" curses:"5">>

Where curses is the limit to how far any “branch” will go down. There are probably more elegant solutions, but hopefully will give a feel for whether this even something you actually want/need.

\define btoc-body(tag,sort:"",itemClassFilter,exclude,path,curses,swear:"0",)
<ol class="tc-toc">
<$vars swear={{{[<__swear__>add[1]]}}}>
<$list filter="[<swear>compare:number:lt<__curses__>]" emptyMessage="""...""">
<$list filter="""[title<__tag__>backlinks[]!has[draft.of]$sort$] -[<__tag__>] -[enlist<__exclude__>]""">
    <$vars item=<<currentTiddler>> path={{{ [<__path__>addsuffix[/]addsuffix<__tag__>] }}}>
      <$set name="excluded" filter="""[enlist<__exclude__>] [<__tag__>]""">
        <$set name="toc-item-class" filter=<<__itemClassFilter__>> emptyValue="toc-item-selected" value="toc-item">
          <li class=<<toc-item-class>>>
            <$list filter="[all[current]toc-link[no]]" emptyMessage="<$link to={{{ [<currentTiddler>get[target]else<currentTiddler>] }}}><$view field='caption'><$view field='title'/></$view></$link>">
              <<toc-caption>>
            </$list>
            <$macrocall $name="btoc-body" tag=<<item>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> exclude=<<excluded>> 
                 path=<<path>> swear=<<swear>> curses=<<__curses__>>/>
          </li>
        </$set>
      </$set>
    </$vars>
  </$list>
</$list>
</$vars>
</ol>
\end

\define btoc(tag,sort:"",itemClassFilter:"",curses:"5")
<$macrocall $name="btoc-body"  tag=<<__tag__>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> curses=<<__curses__>> />
\end

Thanks Mark, your curses got me to stop cursing! :slight_smile: