Any alias solution that is actually... natural?

I’m hoping there is an “alias” solution that doesn’t interfere. I just want to type [[somealias]] and it renders as a regular looking link but clicking it navigates to [[the target]].

Here are some annoying use cases where you’re currently forced to use prettylinks:

  • singular/plural, e.g A [[Feature|Features]] for everyone
  • upper/lowercase e.g Many [[features|Features]]
  • abbreviations etc, e.g [[TW|TiddlyWiki]] or [[JR|JeremyRuston]]
  • “simplifications” e.g [[sidebar|$:/state/sidebar]]

This syntax caters for the reader - the resulting link is pretty - but it burdens the author: When taking lecture notes or composing poetry, you should not have to break the moment by needing to recall exact tiddler titles or TW syntax. Not to mention dyslectics who can have a few variations of a word.

So, I’m hoping for:

  • Alias links that are directly typed as if they were actual titles, i.e [[myalias]]
  • In the target tiddler there’s an alias field (or other name) where I can list multiple aliases for the current tid
  • If there exists a real tiddler with that title, then the real tid takes precedence in the navigation.

The above I cannot solve myself. The following are nice-to-haves that I could solve myself:

  • Alerts when attempting to add an invalid alias:
    Invalid alias, [[xxx]] exists as a tiddler - and -
    Invalid alias, "xxx" is already used in [[yyy]]
    Those warnings should be persistent. (I don’t have a strong opinion on navigation from an alias that appears in multiple tiddlers.)
  • Conversely, in tiddler xxx - or when that creating tiddler - there’s an alert that
    Tiddler [[yyy]] uses "xxx" as an alias
    …maybe also a Remove button
    …and a backlinks list
  • A central listing of tiddlers and their aliases, directly editable
    …and which also alerts about conflicts.
  • The missing tiddler template can list any alias occurences and a link to that tiddler

Thoughts?

Give this a try:

First, edit the shadow tiddler: $:/language/MissingTiddler/Hint, so that it has the following contents:

\define redirect()
<$action-navigate $to=<<target>>/>
<$action-sendmessage $message="tm-close-tiddler" $param=<<currentTiddler>>/>
\end

<$list filter="[<currentTiddler>listed[alias]]" variable="target">
   <<currentTiddler>> is an alias for <$link to=<<target>>/><br>
   @@display:none;<$action-timeout autostart=yes delay=0 actions="<<redirect>>"/>@@
</$list>

Missing tiddler "<$text text=<<currentTiddler>>/>" -- click {{||$:/core/ui/Buttons/edit}} to create

Next, import TiddlyTools/Time/action-timeout.js. This is needed to trigger a “redirect” action when a link to a tiddler alias is rendered as a “missing” tiddler.

Then, add your alias fields to the desired tiddlers, where the field value contains a space-separated list of aliases.

How it works:

  • When a link to an existing tiddler is clicked it is displayed as usual.
  • When a link to a missing tiddler is clicked it is displayed using the content from $:/language/MissingTiddler/Hint which now also scans all tiddlers that have an alias field to determine if the missing tiddler’s title is listed as an alias.
  • If the missing tiddler’s title is NOT an alias, the default “Missing tiddler …” text is displays as usual.
  • If an alias IS found, the TiddlyTools $action-timeout widget is triggered immediately upon rendering (using autostart=yes delay=0) to open the corresponding “target” tiddler and close the “missing tiddler”.
  • If TiddlyTools/Time/action-timeout.js is NOT installed, the missing tiddler content includes a message with a link to the target tiddler. (Note the $action-timeout widget is surrounded by @@display:none; to suppress the “undefined widget” error message that would otherwise appear).

enjoy,
-e

edited: improved “scan for matching alias” by using [<currentTiddler>listed[alias]] filter

2 Likes

For completeness, I believe @mklauber’s alias plugin hits many if not all your requirements.

@EricShulman - Man! :laughing:

I would never have figured out to tweak the $:/language/MissingTiddler/Hint-tiddler rather than messing with the mechanism that defines how links in general work. (I have totally assumed that “language/hint-tiddlers” are merely for static content.)

I find that the following line actually never shows up for the viewer and can be deleted - correct? (Even an open missing tiddler will disappear if it’s title is entered into an alias field)

<<currentTiddler>> is an alias for <$link to=<<target>>/><br>

There are two issues.

  • The missing tiddler quickly flashes by. In the redirect macro, I switched places for the two action-navigates figuring it should hide the missing tid while the navigation takes place. I can’t quite tell if it makes it smoother.
  • The link styling seems to get messed up. I have to investigate a bit more to be able to describe this properly.

Thanks again Eric!

Doesn’t @pmario 's UniLink do pretty much this?

In terms of flow, my problem with this type of linking is that you have to insert each variation of a name into an alias list field.

@etardiff - a quick peek does seem promising. Thanks…

@Mark_S - While unilink has its benefits, it requres special syntax.

But how else could it be done? As noted in the OP, I’m thinking there should also be a central location to modify aliases. For workflow, it makes most sense to add aliases as the tiddler is created though, don’t you think?

If the $action-timeout widget is not installed, then the <<redirect>> actions are not triggered, the missing tiddler doesn’t get closed, and the above message DOES appear.

Ah, that’s what you referred to previously :grinning_face_with_smiling_eyes: Thanks Eric

Command palette plugin have a config, default to include the “alias” field:

图片

Hope this is a standard field, so when you are using alias, the command palette works out-of-box.

But sadly I just see @mklauber 's alias plugin is using aliases field! (Maybe there should be an alias between aliases and alias!)

So, this is another field that need the standardization, like the What’s the standard way to not writing Title. Do we have a committee for standardizing tiddlywiki ontology?

1 Like

@pmario’s uni-link plugin also uses aliases, so I’d say that would be a better “standard” to promote.

That’s mainly for performance and code simplicity reasons. It would be possible to have algorithms to detect eg: “singular” or “plural” versions of words. But the problem is, that they are language specific and for some languages they can be very complex and error-prone.

As plugin authors we have to make compromises. — It’s a bit more work for the user to define the alias variations, but the plugin can be universally useful.

That’s needed to be able to detect “aliasbacklinks” and the other features that are important for myself.

1 Like

I think, there is a difference between alias and aliases.

  • alias … Contains a single alias value only
  • aliases … Can contain several alias values

It may be possible to use the alias field as a title in a list-widget, but the aliases field can have many definitions. So it may not really be useful to be shown as a title. See: uni-link — extended link functions

On the other hand, it will be more useful than a UUID …

2 Likes

Then let’s use this field name. I will update the command palette / WYSIWYG editor / Whiteboard plugin to use this instead of alias. (Also wait a month until this ontology is decided)

This can work with titleless tiddler, but not necessarly. Many titleless tiddler don’t even need a display name, nor need to be linked to. We have alternative layout, many of then may not have a concept of “display name/caption” or “linking”.

1 Like

One thought, which I don’t have time to fully explain at the moment, would be to use something like Virtual Tiddlers. The brief explanation would be to edit the Story Tiddler Template Cascade, which controls the transclusion of tiddlers into the story river. You could add a filter to the cascade that returns a custom template if the current tiddler is missing, but is found in an aliases field of another tiddler. Your custom template could then simply find that tiddler, set the current tiddler (and story tiddler) to that tiddler, and then transclude the original View Template.

Additionally, in the custom template, you could also set a variable <<aliasTiddler>> to the current tiddler before changing the current tiddler (so that <<aliasTiddler>> contains whatever alias was in the link), and you could then add a tiddler to the view template under the title which would say, redirected from <<aliasTiddler>>.

Then if “spammed” is an alias of “spam”, and you have a link [[spammed]], and you click on this link, then behind the scenes it will actually open the missing tiddler spammed, but your custom template would be applied to make it look exactly as if you had clicked a link to spam (except for the “redirected from” message if you choose to add it).

This solution would not fix the fact that links would display as links to missing tiddlers (because in fact they still would be). This could probably be fixed by adding a custom stylesheet, but I’m not sure if it could be done in a palette-independent way.

2 Likes

Happy to see my aliases plugin still getting notes! I believe it does meet many of the OP’s requirements, such as using double bracket Title formatting, multiple aliases, and the real tiddler getting precedence. It even handles conflicting aliases with a wikipedia inspired “disambiguation” page.

However, it does have a few issues I’ve not put the time in to fix. First, if you add an alias, previously rendered missing links remain formatted as missing until the link is re-rendered. (Actually, this is the behavior of the regular link widget, so nevermind) Additionally, my implementation does suffer from version rot since it’s overriding internal tiddlers that are undergoing regular development.

1 Like

Consider whether you might be able to just subclass the widgets you want to modify and just override the necessary methods rather than the entire widgets.

It might also be possible now to implement the entirety of the plugin as a wikitext based custom widget that overrides the core link widget.

1 Like

I’m sort of assuming that you mean that the links are styled as links to missing tiddlers. That’s what would happen with the solution I proposed, anyway.

One idea to fix this would be to override this link widget, calling the original link widget (via the Genesis widget with $type="$link" and $remappable="no"), but using the class and/or overrideclass attributes of the link widget to make sure that links to aliases are styled as internal links instead of missing ones. (Note that overriding widgets is something you can do with plain wikitext in recent versions of TW. It is similar to macros and procedures.)

However, if you’re going to override custom widgets, and if you don’t specifically need a “redirected from” note, then it may be easier to change where the “to” attribute of the link points. Perhaps you could make a custom function that takes a link target as a parameter, returns the input unchanged if it is a tiddler, otherwise returns the tiddler that contains it in its alias field if it exists, and otherwise returns the input unchanged - and then when calling the $genesis widget in your override definition, you could call that function for your “to” attribute.

In fact, if you don’t need the “redirected from” message, that’s what I recommend.

@saqimtiaz recommended the same thing (in less detail):

Good point, I didn’t know about widget-subclasses. I’ve reworked the plugin to use them and it looks a lot nicer.

2 Likes

Oh, is the new one on the same site as previously; here?

Yes, just bumped to version 5.3.3

1 Like