otterwiki icon indicating copy to clipboard operation
otterwiki copied to clipboard

Add ability to customize the 404 page

Open mattock opened this issue 10 months ago • 2 comments

Currently the 404 page is hardcoded (templates/page404.html). In our case we'd like to customize that page as we're migrating away from an old Trac wiki and wish to let people know why they may be hitting a 404 page in Otterwiki. While we can modify that file directly, it is a rather bad option as it makes Git unhappy. Two options I can think of to make this better:

Allow defining a custom 404 URL

This would default to an empty string. If it is an empty string, Otterwiki would default to its current behavior. Alternatively there could be a separate boolean to turn this on coupled with a string (HTML) field. As far as I can see, implementing this requires these steps:

  • templates/admin.html needs a new entry for custom 404 URL setting (empty by default)
  • preferences.py method handle_app_preferences() needs to be modified to commit the new 404 URL setting
  • wiki.py method exists_or_404() would need to check app.config['404_URL'] and act accordingly

Does this look correct? Is something else required, e.g. for database migrations?

Allow embedding custom HTML code snippets to page404.html

The implementation might be slightly simpler than above(?). Basically the snippet would be empty by default. If defined, it would override or get prepended/appended the default page404.html.


Any thoughts regarding this? I could take a stab at implementing this myself as it looks deceptively simple to do 😂 .

mattock avatar Feb 04 '25 08:02 mattock

Hey @mattock! Great idea and for sure very useful.

I like the idea of defining a custom URL more. Because you can just point it to a Wiki Page and there you can edit it nicely.

Does this look correct? Is something else required, e.g. for database migrations?

Another thing is to add the default in the server.py here:

https://github.com/redimp/otterwiki/blob/f618471f0ba32db60f0f76f79e16aab30f1bade5/otterwiki/server.py#L19-L60

Any thoughts regarding this? I could take a stab at implementing this myself as it looks deceptively simple to do 😂 .

Go for it, a PR is very welcome.

redimp avatar Feb 04 '25 13:02 redimp

Ok, I shall take a deep breath in the upcoming weeks and try to make it work.

mattock avatar Feb 05 '25 14:02 mattock