Redirecting links that match a regexp

46 views
Skip to first unread message

jarble

unread,
Jan 3, 2012, 10:14:58 PM1/3/12
to tiddl...@googlegroups.com
I'm not familiar with TiddlyWiki's API, and I'm trying to create an extension that redirects pages that match a regular expression. If a link matches a regular expression, it should be redirected to a specific page.

Example regular expression:

(web|online)( )(pages|sites)( that| )( I )(like|like to(read|browse|explore))

Example matching links:

[[web sites that I like to read]]

[[web sites I like]]

[[web sites I like to browse]]

If I clicked one of these links, it should redirect me to a page called (web|online)( )(pages|sites)( that| )( I )(like|like to(read|browse|explore)).

Eric Shulman

unread,
Jan 3, 2012, 11:32:50 PM1/3/12
to TiddlyWiki
On Jan 3, 7:14 pm, jarble <jar...@gmail.com> wrote:
> I'm not familiar with TiddlyWiki's API, and I'm trying to create an
> extension that redirects pages that match a regular expression. If a link
> matches a regular expression, it should be redirected to a specific page.

http://www.TiddlyTools.com/#MissingTiddlersPlugin

uses regular expressions to match titles of "missing" tiddlers and
provide alternative, fallback content. After installing the plugin,
you can then simply create a tiddler called [[MissingTiddlers]]
containing sections, where the section headings are regexp patterns to
match and the section content is the fallback content to use when
matched.

You can use any content as a fallback, including static text, TW
macros, etc. For your purposes ("redirecting" to another tiddler),
you could use a <<tiddler>> macro to display the desired 'redirected'
content. You can also embed a special marker sequence, "$1" (without
quotes) within the fallback content to display the actual name of the
tiddler used in the link.

For example, suppose [[MissingTiddlers]] contains:
!(web|online)( )(pages|sites)( that| )( I )(like|like to(read|
browse|explore))
$1
<<tiddler MyFavoriteSites>>

and [[MyFavoriteSites]] contains:
http://www.TiddlyWiki.com/
http://www.TiddlyTools.com/

Then, when you click on a link like: [[web sites that I like to
read]], MissingTiddlersPlugin will find the matching regexp in the
MissingTiddlers list, and display:
web sites that I like to read:
http://www.TiddlyWiki.com/
http://www.TiddlyTools.com/

Note: if you actually want to *redirect* to another tiddler (rather
than just showing the fallback content), you can install
http://www.TiddlyTools.com/#SlideshowTimer

The SlideshowTimer transclusion automatically opens the specified
tiddler (e.g., [[MyFavoriteSites]]) after an indicated delay
(0=immediate) and, with the optional "close" keyword, automatically
closes the current tiddler that was being displayed (i.e. it
'redirects' from one tiddler to another).

This would allow to you write something like this in
[[MissingTiddlers]]:
!(web|online)( )(pages|sites)( that| )( I )(like|like to(read|
browse|explore))
<<tiddler SlideshowTimer with: MyFavoriteSites 0 close>>

The net result is that any link that matches your desired regexp
pattern(s) in [[MissingTiddlers]] would redirect to
[[MyFavoriteSites]] instead. Q.E.D.

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

----
TiddlyTools needs YOUR financial support...
Help ME to continue to help YOU...
make a generous donation today:
http://www.TiddlyTools.com/#Donations

Professional TiddlyWiki Consulting Services...
Analysis, Design, and Custom Solutions:
http://www.TiddlyTools.com/#Contact

Andy Green

unread,
Jan 4, 2012, 12:50:12 PM1/4/12
to tiddl...@googlegroups.com
I copied and pasted SlideshowTimer into the wiki, and the page showed an "error in macro <<tiddler>>" message instead of the correct page content. How should I install SlideshowTimer correctly?

Andy Green

unread,
Jan 4, 2012, 1:01:10 PM1/4/12
to tiddl...@googlegroups.com
EDIT: I think I was using an outdated version of TiddlyWiki. Thanks for your help!

Andy Green

unread,
Jan 4, 2012, 2:50:46 PM1/4/12
to tiddl...@googlegroups.com
How do you indicate the end of a section on the "ShowTiddler" page?

Andy Green

unread,
Jan 4, 2012, 3:02:22 PM1/4/12
to tiddl...@googlegroups.com
Also, I think the page you mentioned should be called "MissingTiddlersList" instead of "MissingTiddlers." The plugins wouldn't work correctly until I changed the name.
Reply all
Reply to author
Forward
0 new messages