Where to put custom Handlebars functions in Ghost CMS?

I’m trying to break out of the limitations of Handlebars HBS templates and make a couple of helpers, something like this for example:

// Custom Handlebars helper to compare dates
// Usage: {{#isBeforeDate date1 date2}} Content {{else}} Other content {{/isBeforeDate}}
Handlebars.registerHelper('isBeforeDate', function(date1, date2, options) {
    if (new Date(date1) < new Date(date2)) {
        return options.fn(this);
    } else {
        return options.inverse(this);
    }
});

Where exactly should I put these helpers in (a self-hosted) Ghost CMS so that it works and doesn’t break the whole site during a scheduled Ghost update?