Skip to content

Load custom Javascript file from theme #4627

Closed
@RobinNiemann

Description

@RobinNiemann

Attempted Debugging

  • I have read the debugging page

Searched GitHub Issues

  • I have searched GitHub for the issue.

Describe the Scenario

My theme needs a small amount of Javascript. How can I load that Javascript file from my themes folder (e.g. BookStack/themes/my_theme/js/script.js)?

What I tried and didn't work:

  • Put this into the Custom Head Setting on the customization page -> My customization needing that script is on the customization page itself and the Custom Head Setting is not loaded there.
  • Overwrite common/custom-head.blade.php or layouts/base.blade.php or layouts/parts/base-body-start.blade.php or layouts/parts/base-body-start.blade.php and add the <script> block in there -> My browser blocks inline scripts; I get the Browser-Log Message "Content-Security-Policy: The page's settings blocked the loading of a resource on inline ('script-src')"
    • This was inspired by this issue wich is pretty similar but the final solution wasn't presented there and I failed to figure out the details.

What worked but is no clean solution:

  • I put the script.js file into the folder Bookstack/public/dist. From there it is loaded, but this would mean that I would have to create my own Docker Image just to add that one file

Exact BookStack Version

v23.08.3

Log Content

No response

Hosting Environment

Docker Compose on local machine

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions