jackyzha0 / quartz

🌱 a fast, batteries-included static-site generator that transforms Markdown content into fully functional websites
https://quartz.jzhao.xyz
MIT License
6.59k stars 2.44k forks source link

Folder pages not generated for folders that only contain subfolders or are empty #651

Open AlpyneDreams opened 8 months ago

AlpyneDreams commented 8 months ago

Describe the bug Using FolderPage, any folders that only contain subfolders (no markdown files as immediate children) or are empty don't get an index.html page generated for them.

I don't think this behavior is intentional - the folder list is generated from the parent folders of markdown files and therefore ignores grandparent folders and empty folders.

It is a bit of a UX problem as it's not immediately obvious why some folders have pages and some don't, and the 404 page doesn't have sidebars or any other navigation elements, breaking flow. We have a large number of nested folders in our Obsidian Vault and it would be very annoying to create a blank index.md for all of them.

To Reproduce

  1. Add Plugin.FolderPage to emitters in config
  2. Create a folder
  3. Create a subfolder inside that folder
  4. Add markdown files inside the subfolder (optional)
  5. Navigate to the first folder's page and observe 404 error

Expected behavior Any one of the following would solve this problem:

Additionally, it would be nice if FolderPage could list subfolders as well as markdown files, so that grandparent folder pages aren't just empty.

Screenshots and Source

huffn commented 4 months ago

Edit: My cache hadn't cleared when I was testing if it would work for empty folders with a subdirectory. The isDirectChild change doesn't fix the folders from not being generated if there aren't any markdown files. I'll play around a little more to see if there is another spot where it is filtering out no direct children for folder pages.

In FolderContent.tsx I was able to fix this problem by modifying the allPagesInFolder filter by changing the return from return prefixed && isDirectChild to return prefixed || isDirectChild

The isDirectChild check is filtering out any files in subfolders. I was having a similar bug since the description for Folder and Tag Listings claims:

Quartz will generate an index page for all the pages under that folder. This includes any content that is multiple levels deep.

But my folder pages first returned the 404 since I didn't have any files in the higher up directories. I ended up putting a markdown file in that folder, but it still wasn't showing the sub directories. So this fix makes sure that subdirectories aren't filtered out when the folder pages are generated.

brandonhinds commented 3 months ago

I am not sure if my situation is the exact same as the original post, but in a similar situation, where a folder only has subfolders and no markdown files, navigating to it returns a 403. I looked in to the folder plugin but it does not look like it has any configuration so I am not sure if this is also a bug.

If this appears to be a separate bug compared to OP's 404 bug report I am happy to raise a separate issue.

BICH0 commented 2 months ago

Just came here to +1 this, it would be neat if folder generated even if it only contains other folders, i have my notes classified in subfolders and the directory tree is almost empty