ssg icon indicating copy to clipboard operation
ssg copied to clipboard

Suggestion: Allow more than one "after" callback

Open efc opened this issue 1 year ago • 1 comments

I have already written two "after" functions for SSG, one to do some URL rewriting and one to generate HTML redirect pages. It seems to me that different addon authors might want to create their own SSG::after functions as well. But it seems that only the last SSG::after function is saved and called by SSG (see the definition in /src/Generator.php...

    public function after($after)
    {
        $this->after = $after;

        return $this;
    }

Wouldn't it make more sense to allow multiple functions to be "registered" and called, so that multiple addons might hook onto the tail end of a static site generation to do whatever cleanup they need for their own data?

I'm not sure how to best accomplish this, probably does not need to be as sophisticated as the WP hook mechanism (though that is not a bad model, and accounts for things like managing the order of callback). Maybe even just a simple array of after callbacks would be enough?

efc avatar Nov 02 '24 03:11 efc

I find I really need this now. For example, the redirect addon I use includes an after callback for SSG, but I need to also include my own. This is currently impossible to accomplish. I just submitted PR #207 which makes this possible by adding identifiers when registering the after callbacks.

efc avatar Aug 09 '25 20:08 efc