Relative URL's

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Relative URL's

ge0ffrey
Using absolute URL's, such as href="/download/a.html", in an awestruct website is annoying:
- they don't work locally when build with the production profile (it tries to go to file:///download/a.html)
- they don't work remote if the website is not on the root of the website. For example
  http://www.jboss.org/optaplanner/index.html
would go to
  http://www.jboss.org/download/a.html
instead of
  http://www.jboss.org/optaplanner/download/a.html

Relative URL's, such as href="download/a.html" don't suffer from these problem, but they are hard to use in layout files.
- index.html would go to the correct
  http://www.jboss.org/optaplanner/download/a.html
- but code/sourceCode.thml would go to the invalid
  http://www.jboss.org/optaplanner/code/download/a.html
- even download/a.html would go to the invalid
  http://www.jboss.org/optaplanner/download/download/a.html
The last 2 cases need to use "../download/a.html" in their layout heading.

Is there a way to grab the content's filepath and translate that into the relative path to the website root, so ".", "..", "../..", etc?
Reply | Threaded
Open this post in threaded view
|

Re: Relative URL's

Emmanuel Bernard
I believe that the problem comes from the fact that the indexer plugin
has to come late in the game. In ceylon, we add on each page a root
metadata property (manually) that can then be used in the page content.
But that sucks.

On Fri 2013-03-08  8:04, ge0ffrey wrote:

> Using absolute URL's, such as href="/download/a.html", in an awestruct
> website is annoying:
> - they don't work locally when build with the production profile (it tries
> to go to file:///download/a.html)
> - they don't work remote if the website is not on the root of the website.
> For example
>   http://www.jboss.org/optaplanner/index.html
> would go to
>   http://www.jboss.org/download/a.html
> instead of
>   http://www.jboss.org/optaplanner/download/a.html
>
> Relative URL's, such as href="download/a.html" don't suffer from these
> problem, but they are hard to use in layout files.
> - index.html would go to the correct
>   http://www.jboss.org/optaplanner/download/a.html
> - but code/sourceCode.thml would go to the invalid
>   http://www.jboss.org/optaplanner/code/download/a.html
> - even download/a.html would go to the invalid
>   http://www.jboss.org/optaplanner/download/download/a.html
> The last 2 cases need to use "../download/a.html" in their layout heading.
>
> *Is there a way to grab the content's filepath and translate that into the
> relative path to the website root, so ".", "..", "../..", etc?*
>
>
>
>
> --
> View this message in context: http://talk-archive.awestruct.org/Relative-URL-s-tp145.html
> Sent from the Awestruct Talk mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> Archives: http://talk-archive.awestruct.org/
> To unsubscribe, e-mail: [hidden email]
>

---------------------------------------------------------------------
Archives: http://talk-archive.awestruct.org/
To unsubscribe, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Relative URL's

Torsten Curdt
check out this extension

 Awestruct::Extensions::Relative

cheers,
Torsten

---------------------------------------------------------------------
Archives: http://talk-archive.awestruct.org/
To unsubscribe, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Relative URL's

ge0ffrey
Torsten Curdt wrote
check out this extension

 Awestruct::Extensions::Relative
Looks like just what I need: def relative(href, p = page)
Me being a total Ruby noob, how do I use this in a webpage? :)

I noticed it's not documented yet on awestruct.org, I 'll create a pull request to document it, once I figure out how it works.
Reply | Threaded
Open this post in threaded view
|

Re: Relative URL's

Torsten Curdt
Once you activate it in the pipeline you should be able to use it like this

 %a{ :href => relative(page.url) }= page.title

HTH

---------------------------------------------------------------------
Archives: http://talk-archive.awestruct.org/
To unsubscribe, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Relative URL's

ge0ffrey
I am afraid I 'll need more info... I can't get it it to work. Here's what I tried:

In my _layouts/base.html.hamls I added:

      %p b1 #{relative(page.url)} b2 #{relative("community/index.html")} b3 #{relative('community/index.html')}
      %p test1 #{relative(page.url)}
      %p test2 #{relative("community/index.html")}
      %p test2b #{relative("/community/index.html")}
      %p test3 #{relative('community/index.html')}
      %p test3b #{relative('/community/index.html')}
      %a{ :href => relative(page.url) } test4
      %a{ :href => relative("community/index.html") } test5
      %a{ :href => relative("/community/index.html") } test5b
      %a{ :href => relative('community/index.html') } test6
      %a{ :href => relative('/community/index.html') } test6b

They always remained empty. I combined it with these combinations:

1) No other changes

2) In pipeline.rb add

require 'relative'
...
        extension Awestruct::Extensions::Relative.new # After Partial

And copy paste relative.rb into the dir _ext.

Result: undefined method `new' for Awestruct::Extensions::Relative:Module

3) The same as 2), but without the extension line (so only the require line)


Reply | Threaded
Open this post in threaded view
|

Re: Relative URL's

ge0ffrey
Turns out this works to enable it:

require 'relative'

Awestruct::Extensions::Pipeline.new do
        ...

        helper Awestruct::Extensions::Relative
end

If there is an error, the page will not be rendered and the console will remain silent.
Here's a pull request to fix the error reporting in the console:
  https://github.com/awestruct/awestruct/pull/242
Reply | Threaded
Open this post in threaded view
|

Re: Relative URL's

ge0ffrey
Here's the awestruct.org pull request to document the Relative extension:
  https://github.com/awestruct/awestruct.org/pull/28
I wasn't able to decently test those changes due to:
  https://github.com/awestruct/awestruct.org/issues/27