¿Documenting error?

The documentations about variables (https://jekyllrb.com/docs/variables/) say in pages.categories:

For example, a post at /work/code/_posts/2008-12-24-closures.md 
would have this field set to ['work', 'code']

But I have tried it in Jekyll 4.0.0 and it does not work, when you put pages under subdirectories, they are not assigned a category based in their path.
Only when you declare categories in the Front Matter it seems to correctly assign categories to pages.

Notice that the example uses _posts in the path string?
Categories based on a path are only for posts not for regular pages.

The documentation section uses the title Page Variables because inside a template (layout or include), the current page / document being procesed is always referenced by the name page

That means even inside the post source file _posts/2019-11-12-hello.md, you would use page.title to render the Post’s title.

OK, thank you, you are right. It seems just posts get categorized using the directory structure.

It is not always evident in the documentation if it is talking just about posts or posts and pages.
Sometimes posts are considered pages too.

With pages the permalink does not include categories even if you speficy categories in the Front Matter.

It is a pity you cannot do that.