Unable to adjust the pages' permalink at runtime without success

Hello there,

I’ve seen several scripts, more or less similar to each others, that override the class PermalinkRewriter < Generator to rewrite the permalink of a given post/pages. An example here.

I’ve been trying to do the same on Jekyll 4.2.2 without success. Even a simple replacement like the one below fails to produce the expected output

if p.data['slug'].include?("/test/") 
    puts("rewriting the permalink")
    p.data['permalink'] = "/hola"

The puts is generated three times although I’ve only one page with that slug variable. At code level I can see the permalink being replaces, but in fact the page is not accessible via the new permalink but the old one.

Do you have any idea?