WikiLinks

Short and sweet links in Sausagewiki, by
2018-10-10

I've been working on Sausagewiki for a while now, but I have only recently discovered how best to enable prolific linking between articles. I have now made it possible to link to an article by just writing its title in square brackets inline in the text; I like [pie], I like [cake]. This is a bit of a lucky combination of an extension to Markdown and the way URLs are generated for articles in Sausagewiki. Let's look at the URLs first.

When designing the URL generation mechanism, I had some goals in mind, based on what I think works great and less great in existing wiki engines.

I wanted to allow the titles of pages to be anything. Many wiki engines, famously including MediaWiki, use the URL as the only input to decide what the title of the page is. This gives rise to the banner at the top of some pages on Wikipedia that tells you the title is inaccurate. It could be that the title should have started with a lower case letter or that there is supposed to be a symbol in there which isn't allowed in the URL scheme. Sausagewiki goes the other way and uses the given title to generate the URL.

I also wanted the URLs to be easy to deal with, both technically and mentally, and a wiki engine should have good support for creating new pages by inventing URLs.

To make them easy to deal with, the article URLs in Sausagewiki only consist of lower case latin letters and the dash symbol. The process to convert any string into such a string is well established and often used in blog software. It is called slugging and the result of slugging a string is called a slug. To make it easy to invent URLs and to be forgiving to people trying to remember URLs, Sausagewiki will also accept URLs that do not conform to the slug format. If you enter a path that is not a valid slug, Sausagewiki will respond with a redirect to the slug of that path. Say you navigate to /Howl's Moving Castle, you'll be redirected to /howl-s-moving-castle. Similarly /Soyanøttesmør will be a redirect to /soyanottesmor. These URLs are nice and easy and never require any special encoding or escaping.

However, it means that including a link to the "Soyanøttesmør" article would require you to write [Soyanøttesmør](soyanottesmor) or possibly [Soyanøttesmør](Soyanøttesmør), if you were willing to incur the cost of a redirect. Finding the correct slug requires you to either run the slugging algorithm in your head or creating the target article before linking to it. This adds a speed bump where there shouldn't be one! Let's fix that.

There is another way to write links in Markdown, so-called reference links. You write I like [soyanøttesmør][1] in one part of the text and on a different line you define the link: [1]: soyanottesmor. The reference can be any string, it doesn't have to be a number; I like [soyanøttesmør][soyanøttesmør] then [soyanøttesmør]: soyanottesmor works the same. Notice that the reference definition at this point is a mapping from a title to its slug. (References are case insensitive)

The original Markdown definition includes a shorthand form for having the link text be the same as the reference text. The above example can in this way be shortened to I like [soyanøttesmør][] while retaining the reference definition. Several variants of Markdown, notably including CommonMark, have shortened this further down to I like [soyanøttesmør]. Neat! This is starting to look like the low effort linking a wiki engine should support.

The only thing remaining now is to free the user from creating the reference definition. In this case I was a bit lucky to find that the library I was already using to process Markdown, pulldown-cmark, had support for taking a callback to handle missing reference definitions. It was then simply a question of plugging in the slugging function to allow short and sweet inline wiki links.

, 2018