gristlabs / grist-core

Grist is the evolution of spreadsheets.

Home Page:https://www.getgrist.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Self-Hosting] Injecting custom script in html templates

hihuz opened this issue · comments

First, thank you for the wonderful job, we love grist. ❤️

Context

We are hosting our own grist instance at ANCT and we would like to be able to inject some custom scripts to the html grist templates (e.g. static/app.html).

Some of our use cases for this:

  • Add some analytics script tags to analyse usage / visits of our instance
  • Add some (temporary) custom alerts for users to warn of upcoming maintenance

Proposition

An environment variable (APP_STATIC_INCLUDE_CUSTOM_CSS) exists to add a custom.css file to the template.

We could imagine a similar approach here, and have a APP_STATIC_INCLUDE_CUSTOM_JS variable injecting a custom.js file to the template.

This is not the most flexible, but it would be consistent with the existing way to inject custom css.

Any other idea or way to add custom scripts on all pages of the grist client app would work for us as well.

What do you think of this idea / would you be in favor of having such a feature? If so we could try to propose an implementation.

Thank you!

A similar thing for a similar purpose was actually added recently, here:

If env var GRIST_INCLUDE_CUSTOM_SCRIPT_URL is set, load it in a <script> tag on all app pages.

If that works for you, then perhaps all that's missing is to document it in README.

Thanks a lot @dsagal! My mistake, I didn't notice this recent addition, I was a bit behind on my local copy.

This will most certainly work for our case.

I think we could indeed add it to the README for discoverability.

I created a very small PR to add a line to the readme for this variable: #906