Shared lexicon schemas for long-form publishing on AT Protocol. Uses typescript to json via prototypey.

Why recommend avoid trailing slashes on publications? #13

Open mb21.bsky.social
Open opened by mb21.bsky.social

The Standard.site schema currently says about publication.url: "Avoid trailing slashes", and about document.path: "Combine with site or publication url to construct a canonical URL to the document. Prepend with a leading slash."

I see two problems with that recommendation:

  1. https://example.com is in fact not a valid fully qualified URL, because the path always needs to start with a slash. That's why new URL("https://example.com").toString() normalizes this correctly to https://example.com/. This is a problem if I want my library to accept publication.url as a JS URL object instead of as a string.
  2. What if my publication's URL is in fact https://mastrojs.github.io/blog/ (with a trailing slash)? Yes, some websites may redirect /blog to /blog/, but not all will.

That's why I'd advocate for just dropping that recommendation. People should just make sure that publication.url + document.path (string concatenation) resolves to the correct thing.

I have another user story: I want to make my publication be a statically-hosted HTML page that is a viewer for a document record specified as a query parameter, e.g. https://example.com/?rkey=3x36222222222. For this use case, the base url of the publication would naturally be https://example.com/?rkey= and the path of the document would be the record key, 3x36222222222[1]. But https://example.com/?rkey= is obviously not a valid URL by itself. While I could instead make the document path be /?rkey=3x36222222222, that seems to be a non-essential boilerplate and to be less portable (if I want to move the publication to another platform, it’s less likely that the platform would like the path ?rkey=3x36222222222 than 3x36222222222. Updating the path of every document is possible, but not desirable).

I think it’d be cleaner to separate the concept of the canonical URL of the publication (which is an accessible URL by itself) from the base URL of the publication (used to construct document URLs). That way, the canonical URL of the publication could just be a plain URL like https://example.com/, and the base URL could be ?rkey= or just remain omitted.


  1. path mandating a leading slash is another problem. ↩︎

Sign up or Sign in to add to the discussion.