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:
https://example.comis in fact not a valid fully qualified URL, because thepathalways needs to start with a slash. That's whynew URL("https://example.com").toString()normalizes this correctly tohttps://example.com/. This is a problem if I want my library to accept publication.url as a JSURLobject instead of as a string.- What if my publication's URL is in fact https://mastrojs.github.io/blog/ (with a trailing slash)? Yes, some websites may redirect
/blogto/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 baseurlof thepublicationwould naturally behttps://example.com/?rkey=and thepathof thedocumentwould be the record key,3x36222222222[1]. Buthttps://example.com/?rkey=is obviously not a valid URL by itself. While I could instead make the documentpathbe/?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=3x36222222222than3x36222222222. Updating thepathof everydocumentis 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.pathmandating a leading slash is another problem. ↩︎