How to set page slug in code

I’m trying to set the page slug in code. This is what I tried:

Jekyll::Hooks.register :articles, :pre_render do |post|
  post.slug = "test-slug"
end

It fails with undefined method slug= for Jekyll::Document. How can this be done?

I figured it out, the solution is:

Jekyll::Hooks.register :articles, :pre_render do |post|
  post.data["slug"] = "test-slug"
end