middleman icon indicating copy to clipboard operation
middleman copied to clipboard

Path prefix not added when using the directory_indexes extension and http_prefix

Open murraysum opened this issue 9 years ago • 17 comments

Issue

When using the set :http_prefix, "/deploy-test" configuration and the directory_indexes extension the path is not always prefixed when using the link_to helper.

If you use the link_to helper with the source file then it correctly prefixes the "/deploy-test" path:

# Correctly generates /deploy-test/test/
<%= link_to "This works", "/test.html", target: "_blank" %> 

However, if you use the link_to helper with a directory path then it doesn't prefix the "/deploy-test" path:

# Incorrectly generates /test/ instead of /deploy-test/test/
<%= link_to "This should work but does not work", "/test/", target: "_blank" %>

Expected Behaviour

I would expect that when linking to the directory path when using the directory_indexes extension would prefix /deploy-test

Actual Behaviour

Linking to the directory path when using the directory_indexes extension does not prefix /deploy-test

Reproducibility

I searched the documentation/previous issues and couldn't find anything related to this. Apologises if there has been. I've created a sample app on Middleman v4.1.9 at https://github.com/murraysum/deploy-test and it is deployed to http://murraysum.github.io/deploy-test/

  • config.rb - https://github.com/murraysum/deploy-test/blob/master/config.rb
  • index.html.erb - https://github.com/murraysum/deploy-test/blob/master/source/index.html.erb

Please let me know if you need any help reproducing. Thanks 👍

murraysum avatar Jun 07 '16 22:06 murraysum

Great bug report. Thank you.

Does this work?

<%= link_to "This should work but does not work", "/test/index.html", target: "_blank" %>

tdreyno avatar Jun 08 '16 00:06 tdreyno

@tdreyno Thanks for the prompt reply. 😀

As suggested I've tried the following and it does correctly prefix:

<%= link_to "This should work but does not work", "/test/index.html", target: "_blank" %>

I think linking to the directory feels cleaner. I am happy to put together a PR to add support to linking to directories with http_prefix if you would accept the patch. Thoughts?

murraysum avatar Jun 08 '16 08:06 murraysum

Yeah, the URL rewriting code basically says "can I find this URL in the site, if so, modify". It'll never find the version without the index.html because that kind of directory -> file inference is outside of MM (usually Apache config).

There is an index_file config option. So if the URL we're looking for is possibly a directory (ends with / or has no extension), then attempt to look it up again with the / (if necessary) and index_file appended.

This should probably happen pretty deep in. In url_for or maybe Sitemap::Store.

There is also a strip_index_file config which should then try to remove the /index.html if it matches the resource, before outputting the string.

I'd love a PR. It's a bunch of somewhat conflicting extensions all trying to avoid stepping on each others' toes.

tdreyno avatar Jun 08 '16 16:06 tdreyno

Has this been resolved?

abolishme avatar Nov 26 '16 22:11 abolishme

@abolishme Hello 👋. Unfortunately, it is still an issue on latest middleman (v4.1.12 as of writing). I didn't get a chance to look into creating a PR with a fix as I ended up not using github-pages so I didn't need to set a prefix path.

I've updated the sample app at https://github.com/murraysum/deploy-test to show it is still an issue in 4.1.12.

murraysum avatar Nov 29 '16 19:11 murraysum

Still an issue with 4.3.7, http_prefix not prefixing anything to link_to avoid from deploying to a subfolder. As said earlier when dealing with i18n sometimes using absolute links is requires especially when using directory_indexes for pretty urls.

noraj avatar Aug 09 '20 18:08 noraj

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 17 '21 19:07 stale[bot]

stale bots...

noraj avatar Jul 19 '21 10:07 noraj

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 17 '21 11:09 stale[bot]

unstale

noraj avatar Sep 17 '21 19:09 noraj

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 16 '21 21:11 stale[bot]

has this been fixed?

noraj avatar Nov 17 '21 18:11 noraj

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 16 '22 20:01 stale[bot]

unstale

noraj avatar Jan 17 '22 17:01 noraj

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 18 '22 19:03 stale[bot]

Still an issue with 4.3.7, http_prefix not prefixing anything to link_to avoid from deploying to a subfolder. As said earlier when dealing with i18n sometimes using absolute links is requires especially when using directory_indexes for pretty urls.

Any news?

noraj avatar Mar 19 '22 00:03 noraj

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 17 '22 08:06 stale[bot]