Posts under folder/_posts not getting generated

I have a folder structure like this:

cat1/
     _posts/
         post1.html
cat2/
     _posts/
         post2.html

My object is to have post1 get a category cat1 and post2 gets a category of cat2 automatically without specifying categories in the yaml front matter of each post. However, none of these posts appear in the generated _site folder (cat1 and cat2 folders are not generated at all). Am I missing something?

I tried adding “categories: cat1 cat2” to my _config.yml but it didn’t make any difference.

Do I need any special configuration to make it work?

Thanks.

I figured out the problem. The post names had to start with YYYY-MM-DD- . Thanks.