middleman: `set :http_prefix` is not working in the build configuration block

It seems that

configure :build do
  set :http_prefix, "/someprefix"
end

is not working properly on rc.1. If you try to use

set :http_prefix, "/someprefix"

outside the configure block it seems to work.

Thank you. Vincenzo

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Comments: 27 (16 by maintainers)

Commits related to this issue

Most upvoted comments

I’m confused as to what the decision was, and how to trigger the feature, and which version it’s available in.

I’m hosting on github pages, so I want to use link_to everywhere, and set the http_prefix in the build config such that when I upload to github pages, all the links work. Later, if I build for s3 or something else, I expect to be able to replace the http_prefix or similar attribute and have all the links and assets prefixed. Right now I can’t seem to find a combination that works as expected and works in live preview mode.

I will try to boil it down to a minimal example, but I tried a bunch of techniques here: http://bewest.github.io/glucose-html5/wiki/Home/ and couldn’t get link_to to produce links that will work on gh-pages and in live preview mode in such a way that I can easily change it later. I see some deploy plugins, but it’s seems they mainly handle authorization logic around uploading.

Say you have a 3 languages static site and you want to put it under a web server.

Without any http_prefix setting you have the following scenario:

The root address is / and the language under / is eng. You have italian under /it/ and spanish under /es/.

Now let’s say you need to put your whole static site in a subfolder, let’s say /new/.

In this situation, all the localized pages links will not work, as they need to refer to a “relative to root” structure. If you are viewing /new/it/ciao.html and you want to access to /new/hello.html or /new/es/hola.html you can’t, since if you are viewing the italian version under /new/it/, the relative links will be hello.html resolving to /new/it/hello.html (404) or es/hola.html resolving to /new/it/es/hola.html (same 404).

This is a problem I encountered in my last project (you can watch at my md repository in my Github account).

set :http_prefix could elegantly solve this little issue, and I think that prepending something to all the URL is less ambiguous than the actual behaviour.

I think that it should prepend a prefix to all urls, in this way you can easily put a compiled static site into any subdirectory. It is very handy if you want to mantain your urls relative to the root, and you want the freedom of changing the place your static site lives in. Plus I think that adding a prefix to all urls is less ambiguous. For the cdn case, you should use the base tag and compile with relative assets.

I was setting in both cases to view the differences between the build code and the live code.

I noticed that the :http_prefix is not added when you activate :relative_assets.

However, if you use :http_prefix while not activating :relative_assets, all the helpers like image_tag, stylesheet_link_tag, javascript_include_tag… works fine, but the link_to method don’t work.

I expect that

configure :build do
  set :http_prefix, '/preview'
end
= image_tag 'picture.png'
= link_to 'my page', 'my_page.html'

produces

<img src="/preview/images/picture.png" />
<a href="/preview/my_page.html">my page</a>

but instead I get:

<img src="/preview/images/picture.png" />
<a href="/my_page.html">my page</a>

Notice that the image_tag helper is working, but the link_to is not.