middleman / middleman-blog

Blog Engine Extension for Middleman
https://middlemanapp.com
MIT License
325 stars 179 forks source link

Get full URL of blog post #224

Closed LandonSchropp closed 10 years ago

LandonSchropp commented 10 years ago

I'm sorry if this is the wrong place to ask this, but I couldn't find anything in the docs. Is it possible to get the full URL of an article, including the domain? For example, when I call article.url, I'd like to see http://landonschropp.com/blog/writing-better-media-queries-with-sass/. Instead, I get /blog/writing-better-media-queries-with-sass/.

lolmaus commented 10 years ago

Middleman does not know where you're going to host the resulting static site.

You'll have to put the base URL into a configuration variable and write a custom helper that produces an absolute URL.

Here's mine, i needed absolute URLs it to produce email templates:

config.rb

@images_path = 'https://user.github.io/project/__assets/images/'

helpers/custom_image_url.rb

def custom_image_tag(img)
  image_path = img.clone

  if environment == :build
    image_path = @images_path + image_path
  end

  image_tag image_path
end

You can adapt this code to your needs.

LandonSchropp commented 10 years ago

Thanks for the quick reply! That definitely solves my problem for now.

What do you think about taking a Rails approach to this problem in the long term? You could have a configuration variable for the URL domain and have differentiated url and path methods? My use case for this is I'm using the BlogPosting microdata format, which requires a full URL, but I'd like for the rest of my URLs on the site to be paths.

tdreyno commented 10 years ago

@LandonSchropp I understand the use-case, but it seems like a much better feature for a per-project helper than a core function.