Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index files inside folders not working by default with clean URLs #1098

Open
gazpachu opened this issue Aug 2, 2022 · 5 comments
Open

Index files inside folders not working by default with clean URLs #1098

gazpachu opened this issue Aug 2, 2022 · 5 comments

Comments

@gazpachu
Copy link

gazpachu commented Aug 2, 2022

I was expecting that any index.html.jsx file would automatically work as a clean URL when placed inside a folder.

Example:

A file placed in /changelog/index.html.jsx would be loaded when visiting the http://localhost:2468/changelog URL

Instead, the default system forces you to go to http://localhost:2468/changelog/index.html

Is there any way to make it work as I intend? Thanks!

@gazpachu
Copy link
Author

Raised a PR: #1099

@brandonweiss
Copy link
Owner

Hey! Could you help me understand what you’re trying to accomplish? Is there a reason you don’t want to name the file changelog.html.jsx?

@gazpachu
Copy link
Author

Hi. The website I'm building has many pages, so I prefer to have a folder for each of them that contains an index.html.jsx and a styles.jsx file.

@brandonweiss
Copy link
Owner

Got it. So this is mostly an organizational issue? Instead of this:

pages/changelog.html.jsx
pages/changelog/subpage.html.jsx
pages/changelog/styles.html.jsx

You want this:

pages/changelog/index.html.jsx
pages/changelog/subpage.html.jsx
pages/changelog/styles.html.jsx

Does it make sense to change this behavior? I’m not sure.

  1. This is perhaps a bit subjective, but I think that when searching for files via fuzzy-finder in an editor, having lots of files that are named “index.html” can get confusing really fast. When I think of opening the changelog page, for example, I want to type “changelog” and have the fuzzy-finder highlight that filename. I think it’s much more confusing for the editor to show me /changelog/index.html.js.
  2. Perhaps a less subjective reason against it is that having two ways of doing the same thing isn’t particularly appealing. What happens if someone makes a changelog.html.jsx file and a changelog/index.html.jsx. Should there be an error? Should one get preferred over the other? That could be pretty confusing.
  3. This is also could get even more confusing because the structure you want looks very similar to a concept called “directory indexes”. If someone makes a changelog/index.html.jsx, should Charge build the file to changelog.html or changelog/index.html? It’s ambiguous which is correct—it really depends on how you want to deploy your site. And since Charge has no configuration, there’d be no way to tell Charge which one you want.

Does that make sense?

@gazpachu
Copy link
Author

Thanks for your suggestions.

I get your point, but the use of index files is at the core of how web servers work. I wouldn't bypass that just because of IDE search preferences.

There's also the file collocation argument. Having everything related to a unit of information in the same folder provides an easier-to-understand folder structure.

Points 2 and 3 could be solved by following the same approach web servers use to decide which file takes priority loading in this scenario: changelog.html.jsx file and a changelog/index.html.jsx. AFAICR, it was the index file the one with a higher priority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants