withastro / roadmap

Ideas, suggestions, and formal RFC proposals for the Astro project.
320 stars 30 forks source link

Relative links RFC #381

Closed matthewp closed 1 year ago

matthewp commented 2 years ago

Summary

Add support for relative links written out during the build, such as <link rel="stylesheet" href="../assets/main.hash.css"> through a new build configuration.

Links

kelvin-zhao commented 1 year ago

Wondering if there is any updates on this, we really don't have control over client server setup and folders so a relative path would really be the best way we can let them drop the project to anywhere they want to.

matthewp commented 1 year ago

@kelvin-zhao Are you ok with not having support for 404.astro in SSG mode with this proposal? I still haven't thought of a way of avoiding that restriction.

The other thing missing is a good story around adding <a href>, <img src>, etc. I'm currently thinking about doing directive like <a relative:href="/other/page"> which would be transformed to <a href="../other/page">.

kelvin-zhao commented 1 year ago

@matthewp Tbh, I'm okay with any possible option... Currently I'm building the files, then manually go into different folders to update the paths on all links... It's so painful I'm halfway onto switching entire projects to other frameworks.

falco467 commented 1 year ago

@kelvin-zhao Are you ok with not having support for 404.astro in SSG mode with this proposal? I still haven't thought of a way of avoiding that restriction.

The other thing missing is a good story around adding <a href>, <img src>, etc. I'm currently thinking about doing directive like <a relative:href="/other/page"> which would be transformed to <a href="../other/page">.

The 404 Problem only exists when serving the 404 Page without redirect, right? You could also implement 404 by sending an 302 Temporary redirect with the location of 404.html and then everything would work with a relative base.

kelvin-zhao commented 1 year ago

Seems Parcel, https://parceljs.org/features/targets/#publicurl runs on default using relative paths, in case anyone is looking for alternative solutions. "In most cases, bundles are loaded using a relative path from the parent bundle to the child bundle. This allows the deployment to be moved to a new location without re-building (e.g. promoting a staging build to production)."

bstro commented 1 year ago

Are there any known hacks to get around this until official support lands? I need a relative path to css assets and I'm afraid I can't even manually edit the paths as the site is being built remotely through vercel ci. Perhaps a post-build npm script might work for me.

matthewp commented 1 year ago

I'm not happy with the way this RFC makes Astro work 2 different ways. I'd prefer to find a path that works the same way in all cases. For that reason I'm going to close this PR as it stands and look into a different solution to the problem.

falco467 commented 1 year ago

@matthewp can we put a link here to an RFC with a different solution?

While I understand your decision I have the feeling a single niche feature (404 page without redirect) is blocking simple fixes fix for a general problem and adding complexity to every decision in the build process. In hindsight I don't know if the feature was worth this trouble.

ixkaito commented 1 year ago

I have published an integration and hope it will be a solution.

https://www.npmjs.com/package/astro-relative-links

nusendra commented 6 months ago

I have published an integration and hope it will be a solution.

https://www.npmjs.com/package/astro-relative-links

my build problem solved with this, Thanks mate

Nicochess commented 3 months ago

I have published an integration and hope it will be a solution.

https://www.npmjs.com/package/astro-relative-links

This lib solves the problem.