Yeah, it's rubbish. I'd be tempted to leverage headless chrome via the Puppeteer library to modify the links. I guess the alternative would be to modify NextJS to give it the support I described earlier in this thread. I don't think the core devs are interested in making those changes themselves.