Best practice for setting the <base> tag per page #214

Open
opened 2024-10-10 12:38:13 +00:00 by davmo · 1 comment
Owner

The current <base> setting per page is:

<base href="https://hackerpublicradio.org/">

This is not ideal for show notes.

When adding internal links to notes (such as footnotes, or links to sections of the notes) it's only possible to use relative links of the form eps/hpr4227/#fn1, because #fn1 will not be relative to the page, but to the site with this <base> tag. Absolute links could be provided of course, but (as far as I know) Pandoc does not provide a method of adding a relative URL prefix to internal links, nor of making such links absolute, since notes are generated as HTML fragments.

There is a similar issue when referring to "assets" like pictures and scripts from within the notes.

What should the <base> be, or should it be omitted?

The current `<base>` setting per page is: ``` <base href="https://hackerpublicradio.org/"> ``` This is not ideal for show notes. When adding internal links to notes (such as footnotes, or links to sections of the notes) it's only possible to use relative links of the form `eps/hpr4227/#fn1`, because `#fn1` will not be relative to the page, but to the site with this `<base>` tag. Absolute links could be provided of course, but (as far as I know) Pandoc does not provide a method of adding a relative URL prefix to internal links, nor of making such links absolute, since notes are generated as HTML *fragments*. There is a similar issue when referring to "assets" like pictures and scripts from within the notes. What should the `<base>` be, or should it be omitted?
Owner

@davmo I originally added the baseurl config so I could test using my local files without needing a web server running. Modern browsers won't follow a relative link when the file:// protocol is part of the URL unless there is a meta tag set. This sandboxes the browser to just the directory structure of the website in your filesystem.

For a working website, the best practice would not be setting this at all. Then the links will be generated with the path, but not the protocol://host:port and relative links should work. That same idea is used for the various other ..._baseurl settings in the site.cfg

@davmo I originally added the baseurl config so I could test using my local files without needing a web server running. Modern browsers won't follow a relative link when the file:// protocol is part of the URL unless there is a <base> meta tag set. This sandboxes the browser to just the directory structure of the website in your filesystem. For a working website, the best practice would not be setting this at all. Then the links will be generated with the path, but not the protocol://host:port and relative links should work. That same idea is used for the various other ..._baseurl settings in the site.cfg
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: HPR/hpr_generator#214
No description provided.