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

build.format / trailingSlash / Astro.url / Astro.props.url interactions all seem bolloxed #12833

Open
1 task done
egnor opened this issue Dec 26, 2024 · 0 comments
Open
1 task done
Labels
needs triage Issue needs to be triaged

Comments

@egnor
Copy link

egnor commented Dec 26, 2024

Astro Info

Astro                    v5.1.1
Node                     v22.4.0
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/sitemap

If this issue only occurs in one browser, which browser is a problem?

(browser independent)

Describe the Bug

I am trying to figure out how source files and generated files and URLs interrelate with the various choices for build.format (directory, file, and preserve) and trailingSlash (always, never, and ignore) and nothing makes any sense.

At the URL below I've made a simple exercise case that shows Astro.url and Astro.props.url (and the corresponding .url property of an imported page) for directory-index and non-directory index files, with a site base of /site_base/ (note trailing slash).

Here's what I get:

# format trailingSlash source file output file Astro.url dev Astro.url build Astro.props.url
1 directory always index.md index.html http://localhost:4321/site_base/ https://site.domain/site_base/ /site_base/
2 directory ignore index.md index.html http://localhost:4321/site_base/ https://site.domain/site_base/ /site_base
3 file never index.md index.html http://localhost:4321/site_base/ https://site.domain/site_base /site_base.html
4 file ignore index.md index.html http://localhost:4321/site_base/ https://site.domain/site_base/ /site_base.html
5 preserve ignore index.md index.html http://localhost:4321/site_base/ https://site.domain/site_base/ /site_base
6 directory always another_page.md another_page/index.html http://localhost:4321/site_base/another_page/ https://site.domain/site_base/another_page/ /site_base/another_page/
7 directory ignore another_page.md another_page/index.html http://localhost:4321/site_base/another_page/ https://site.domain/site_base/another_page/ /site_base/another_page
8 file never another_page.md another_page.html http://localhost:4321/site_base/another_page.html https://site.domain/site_base/another_page.html /site_base/another_page.html
9 file ignore another_page.md another_page.html http://localhost:4321/site_base/another_page.html https://site.domain/site_base/another_page.html /site_base/another_page.html
10 preserve ignore another_page.md another_page.html http://localhost:4321/site_base/another_page.html https://site.domain/site_base/another_page/ /site_base/another_page

Some things don't make sense to me?

  • rows 1/2 and 6/7: weird that changing Astro.props.url from always to ignore drops the trailing slash from Astro.props.url but NOT from Astro.url?
  • row 3: presence of trailing slash in Astro.url differs between dev and prod??
  • rows 3, 4: with a site base of /site_base/ and a generated file of index.html, Astro.props.url of /site_base.html seems completely wrong.
  • row 10: in prod, but NOT dev, Astro.url uses another_page/ instead of another_page.html; meanwhile Astro.props.url uses another_page (no trailing slash)!
  • most: it's generally surprising that the pathname of Astro.url doesn't match Astro.props.url.

Also, when using file output mode, the dev server has different behavior if you request .../another_file vs .../another_file/ vs .../another_file.html, which can't be right since in prod those would all be the same static file. (For the above examples, I always requested .../another_file.html.)

Finally, very strange things happen with file+always or directory+never, but I'm ignoring that because those are arguably not very sensible combinations??

What's the expected result?

A sane, consistent, and well documented approach to the necessary three way mapping between source file layout, output file layout, and assumed URL, without strange variations.

I'm sort of surprised I don't see more people having problems with this, maybe it's because I'm missing something major? Or I guess relatively few people access these metadata fields, people just hardcode URLs?

This is related to the question of how to construct links in Astro -- the docs just say to link to the URL, but to do that you need to know what the URL should be.

Potentially related:

Link to Minimal Reproducible Example

https://github.com/egnor/astro_bug_report

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant