From 8f2562322aed1baf83dc1b261efdd8829564ddb2 Mon Sep 17 00:00:00 2001 From: Emmanuel Bernard Date: Thu, 18 Jul 2013 23:18:27 +0200 Subject: [PATCH 1/4] ORG-1737 Add custom Relative implementation to support absolute links --- _ext/pipeline.rb | 2 ++ _ext/relative.rb | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 _ext/relative.rb diff --git a/_ext/pipeline.rb b/_ext/pipeline.rb index 98e1b9d..15314e3 100644 --- a/_ext/pipeline.rb +++ b/_ext/pipeline.rb @@ -4,9 +4,11 @@ require 'html_minifier' require 'file_merger' require 'less_config' +require 'relative' Awestruct::Extensions::Pipeline.new do helper Awestruct::Extensions::Partial + helper Awestruct::Extensions::Relative extension Awestruct::Extensions::WgetWrapper.new transformer Awestruct::Extensions::JsMinifier.new transformer Awestruct::Extensions::CssMinifier.new diff --git a/_ext/relative.rb b/_ext/relative.rb new file mode 100644 index 0000000..8fb08b3 --- /dev/null +++ b/_ext/relative.rb @@ -0,0 +1,24 @@ +require 'pathname' + +module Awestruct + module Extensions + module Relative + + def relative(href, p = page) + begin + # Ignore absolute links + if href.start_with?("http://") || href.start_with?("https://") + result = href + else + result = Pathname.new(href).relative_path_from(Pathname.new(File.dirname(p.output_path))).to_s + end + result + rescue Exception => e + $LOG.error "#{e}" if $LOG.error? + $LOG.error "#{e.backtrace.join("\n")}" if $LOG.error? + end + end + + end + end +end From 4445c6c874e92d857d409227dffd01ab2b8d5c6f Mon Sep 17 00:00:00 2001 From: Emmanuel Bernard Date: Thu, 18 Jul 2013 23:20:27 +0200 Subject: [PATCH 2/4] ORG-1737 Make all links relative for the site to work locally Pass real page to partials and use it for the Relative helper --- _layouts/bothcol.html.haml | 4 ++-- _layouts/leftcol.html.haml | 2 +- _layouts/project.html.haml | 12 ++++++------ _layouts/rightcol.html.haml | 2 +- _partials/banner.html.haml | 1 + _partials/companyfooter.html.haml | 2 +- _partials/head.html.haml | 22 ++++++++++++---------- _partials/nav.html.haml | 10 +++++----- _partials/projectfooter.html.haml | 3 ++- bothcol.html.haml | 2 +- index.html.haml | 2 +- rightcol.html.haml | 2 +- 12 files changed, 34 insertions(+), 30 deletions(-) diff --git a/_layouts/bothcol.html.haml b/_layouts/bothcol.html.haml index e0f41a6..7d1663a 100644 --- a/_layouts/bothcol.html.haml +++ b/_layouts/bothcol.html.haml @@ -5,10 +5,10 @@ layout: project .row-fluid #equalHeightsLayout #leftcol.span2.well - = partial( page.leftcol_partial.nil? ? 'leftcol.html.haml' : page.leftcol_partial ) + = partial( page.leftcol_partial.nil? ? 'leftcol.html.haml' : page.leftcol_partial, {"real_page" => page} ) #maincol.span8 ~ content #rightcol.span2.well - = partial( page.rightcol_partial.nil? ? 'rightcol.html.haml' : page.rightcol_partial ) \ No newline at end of file + = partial( page.rightcol_partial.nil? ? 'rightcol.html.haml' : page.rightcol_partial, {"real_page" => page} ) diff --git a/_layouts/leftcol.html.haml b/_layouts/leftcol.html.haml index e992349..72a8c62 100644 --- a/_layouts/leftcol.html.haml +++ b/_layouts/leftcol.html.haml @@ -5,7 +5,7 @@ layout: project .row-fluid #equalHeightsLayout #leftcol.span3.well - = partial( page.leftcol_partial.nil? ? 'leftcol.html.haml' : page.leftcol_partial ) + = partial( page.leftcol_partial.nil? ? 'leftcol.html.haml' : page.leftcol_partial, {"real_page" => page} ) #maincol.span9 ~ content diff --git a/_layouts/project.html.haml b/_layouts/project.html.haml index 11240db..e98357a 100644 --- a/_layouts/project.html.haml +++ b/_layouts/project.html.haml @@ -2,7 +2,7 @@ %html(lang="en") %head %title #{page.title ? page.title : page.simple_name.capitalize } ยท #{site.title} - = partial( page.head_partial.nil? ? 'head.html.haml' : page.head_partial ) + = partial( page.head_partial.nil? ? 'head.html.haml' : page.head_partial, { "real_page" => page } ) %body / begin accesibility skip to top @@ -16,20 +16,20 @@ .dropup %a#tab.tabnav-closed{:href => "https://www.jboss.org"} Red Hat - = partial( page.banner_partial.nil? ? 'banner.html.haml' : page.banner_partial ) + = partial( page.banner_partial.nil? ? 'banner.html.haml' : page.banner_partial, {"real_page" => page} ) - = partial( page.nav_partial.nil? ? 'nav.html.haml' : page.nav_partial ) + = partial( page.nav_partial.nil? ? 'nav.html.haml' : page.nav_partial, {"real_page" => page} ) ~ content - = partial( page.projectfooter_partial.nil? ? 'projectfooter.html.haml' : page.projectfooter_partial ) + = partial( page.projectfooter_partial.nil? ? 'projectfooter.html.haml' : page.projectfooter_partial, {"real_page" => page} ) - = partial( page.companyfooter_partial.nil? ? 'companyfooter.html.haml' : page.companyfooter_partial ) + = partial( page.companyfooter_partial.nil? ? 'companyfooter.html.haml' : page.companyfooter_partial, {"real_page" => page} ) %span.backToTop %a{:href => "#top"} back to top - %script(src="#{pageStyle ? site[pageStyle].bootstrap_js_url : site.bootstrap_js_url}#{site.minified}.js") + %script(src="#{relative("#{pageStyle ? site[pageStyle].bootstrap_js_url : site.bootstrap_js_url}#{site.minified}.js")}") - if page.bottom_javascripts - page.bottom_javascripts.each do |javascript| %script{:src=>javascript, :type=>'text/javascript'} diff --git a/_layouts/rightcol.html.haml b/_layouts/rightcol.html.haml index 9fed5c2..94337f2 100644 --- a/_layouts/rightcol.html.haml +++ b/_layouts/rightcol.html.haml @@ -8,4 +8,4 @@ layout: project ~ content #rightcol.span3.well - = partial( page.rightcol_partial.nil? ? 'rightcol.html.haml' : page.rightcol_partial ) \ No newline at end of file + = partial( page.rightcol_partial.nil? ? 'rightcol.html.haml' : page.rightcol_partial, {"real_page" => page} ) diff --git a/_partials/banner.html.haml b/_partials/banner.html.haml index 4c3d326..5b9446f 100644 --- a/_partials/banner.html.haml +++ b/_partials/banner.html.haml @@ -1,3 +1,4 @@ +- real_page = page["real_page"] .banner %a(href="#")< .taglinelight.visible-desktop This text is for the project tagline. diff --git a/_partials/companyfooter.html.haml b/_partials/companyfooter.html.haml index 23036ad..1617458 100644 --- a/_partials/companyfooter.html.haml +++ b/_partials/companyfooter.html.haml @@ -2,4 +2,4 @@ .redhatlogo #logospacer %a(href="http://www.redhat.com/")< - %img(src="#{site.jborg_images_url}/common/redhat_logo.png") + %img(src="#{relative("#{site.jborg_images_url}/common/redhat_logo.png")}") diff --git a/_partials/head.html.haml b/_partials/head.html.haml index 7e7ecf9..5997588 100644 --- a/_partials/head.html.haml +++ b/_partials/head.html.haml @@ -1,35 +1,37 @@ +- real_page = page["real_page"] %meta(charset="utf-8") %meta(name="viewport" content="width=device-width, initial-scale=1.0") %meta(name="description" content="#{page.description}") %meta(name="author" content="#{page.author}") - pageStyle = page.style ; -%link(href="#{pageStyle ? site[pageStyle].bootstrap_css_url : site.bootstrap_css_url}#{site.minified}.css" rel="stylesheet" media="screen") +- bootstrap_community_css = relative("#{pageStyle ? site[pageStyle].bootstrap_css_url : site.bootstrap_css_url}#{site.minified}.css", real_page) +%link(href="#{bootstrap_community_css}" rel="stylesheet" media="screen") / IE 6-8 support of HTML 5 elements /[if lt IE 9] - %script(src="#{site.jborg_js_url}/libs/html5/pre3.6/html5.min.js") + %script(src="#{relative("#{site.jborg_js_url}/libs/html5/pre3.6/html5.min.js")}") / Defines the project favicon. Change these URLs to your specific project folder on static.jboss.org. -%link(rel="shortcut icon" href="#{site.project_images_url}/favicon.ico") -%link(rel="apple-touch-icon-precomposed" sizes="144x144" href="#{site.project_images_url}/apple-touch-icon-144x144-precomposed.png") -%link(rel="apple-touch-icon-precomposed" sizes="114x114" href="#{site.project_images_url}/apple-touch-icon-114x114-precomposed.png") -%link(rel="apple-touch-icon-precomposed" sizes="72x72" href="#{site.project_images_url}/apple-touch-icon-72x72-precomposed.png") -%link(rel="apple-touch-icon-precomposed" href="#{site.project_images_url}/apple-touch-icon-precomposed.png") +%link(rel="shortcut icon" href="#{relative("#{site.project_images_url}/favicon.ico", real_page)}") +%link(rel="apple-touch-icon-precomposed" sizes="144x144" href="#{relative("#{site.project_images_url}/apple-touch-icon-144x144-precomposed.png", real_page)}") +%link(rel="apple-touch-icon-precomposed" sizes="114x114" href="#{relative("#{site.project_images_url}/apple-touch-icon-114x114-precomposed.png", real_page)}") +%link(rel="apple-touch-icon-precomposed" sizes="72x72" href="#{relative("#{site.project_images_url}/apple-touch-icon-72x72-precomposed.png", real_page)}") +%link(rel="apple-touch-icon-precomposed" href="#{relative("#{site.project_images_url}/apple-touch-icon-precomposed.png", real_page)}") / Defines the project banner. Change these URLs to your specific project folder on static.jboss.org :css @media (min-width: 980px) { - .banner { background-image: url(#{site.project_images_url}/#{site.project}-banner-1180px.png); height: 110px; } + .banner { background-image: url(#{relative("#{site.project_images_url}/#{site.project}-banner-1180px.png", real_page)}); height: 110px; } } @media (max-width: 979px) { - .banner { background-image: url(#{site.project_images_url}/#{site.project}-logo.png); background-repeat:no-repeat; height: 60px; } + .banner { background-image: url(#{relative("#{site.project_images_url}/#{site.project}-logo.png", real_page)}); background-repeat:no-repeat; height: 60px; } } @media (max-width: 650px) { .banner { width: 200px; margin: 0px auto; } } -%script(src="#{site.jborg_js_url}/libs/jquery/jquery-1.9.1#{site.minified}.js") +%script(src="#{relative("#{site.jborg_js_url}/libs/jquery/jquery-1.9.1#{site.minified}.js")}") - if page.javascripts - page.javascripts.each do |javascript| %script{:src=>javascript, :type=>'text/javascript'} diff --git a/_partials/nav.html.haml b/_partials/nav.html.haml index a9af158..5d2f28b 100644 --- a/_partials/nav.html.haml +++ b/_partials/nav.html.haml @@ -41,19 +41,19 @@ %ul.dropdown-menu.projectsocialmedia %li< %a(href="#")< - %img(src="#{site.jborg_images_url}/common/socialmedia_icon40_twitter.png") + %img(src="#{relative("#{site.jborg_images_url}/common/socialmedia_icon40_twitter.png")}") %li< %a(href="#")< - %img(src="#{site.jborg_images_url}/common/socialmedia_icon40_googleplus.png") + %img(src="#{relative("#{site.jborg_images_url}/common/socialmedia_icon40_googleplus.png")}") %li< %a(href="#")< - %img(src="#{site.jborg_images_url}/common/socialmedia_icon40_facebook.png") + %img(src="#{relative("#{site.jborg_images_url}/common/socialmedia_icon40_facebook.png")}") %li< %a(href="#")< - %img(src="#{site.jborg_images_url}/common/socialmedia_icon40_youtube.png") + %img(src="#{relative("#{site.jborg_images_url}/common/socialmedia_icon40_youtube.png")}") %li< %a(href="#")< - %img(src="#{site.jborg_images_url}/common/socialmedia_icon40_linkedin.png") + %img(src="#{relative("#{site.jborg_images_url}/common/socialmedia_icon40_linkedin.png")}") %li.dropdown %a.dropdown-toggle(href="#" data-toggle="dropdown")< = precede 'Layouts ' do diff --git a/_partials/projectfooter.html.haml b/_partials/projectfooter.html.haml index d9fb074..be347aa 100644 --- a/_partials/projectfooter.html.haml +++ b/_partials/projectfooter.html.haml @@ -1,3 +1,4 @@ +- real_page = page["real_page"] %footer.container .row-fluid .span2.offset1 @@ -37,4 +38,4 @@ %p .jbossbadge %a{:href => "http://www.jboss.org/"} - %img{:src => "/cache/static.jboss.org/theme/images/common/jbossbadge.png"}/ + %img{:src => "#{relative("/cache/static.jboss.org/theme/images/common/jbossbadge.png", real_page)}"}/ diff --git a/bothcol.html.haml b/bothcol.html.haml index ddde96b..c328e91 100644 --- a/bothcol.html.haml +++ b/bothcol.html.haml @@ -32,4 +32,4 @@ title: Example Right & Left Columns %p< .jbossbadge %a(href="http://www.jboss.org/")< - %img(src="#{site.jborg_images_url}/common/jbossbadge.png") + %img(src="#{relative("#{site.jborg_images_url}/common/jbossbadge.png")}") diff --git a/index.html.haml b/index.html.haml index b04ea75..f9af117 100644 --- a/index.html.haml +++ b/index.html.haml @@ -31,4 +31,4 @@ title: Example Homepage %p< .jbossbadge %a(href="http://www.jboss.org/")< - %img(src="#{site.jborg_images_url}/common/jbossbadge.png") + %img(src="#{relative("#{site.jborg_images_url}/common/jbossbadge.png")}") diff --git a/rightcol.html.haml b/rightcol.html.haml index 436bf9c..420c033 100644 --- a/rightcol.html.haml +++ b/rightcol.html.haml @@ -32,4 +32,4 @@ title: Example Right Column %p< .jbossbadge %a(href="http://www.jboss.org/")< - %img(src="#{site.jborg_images_url}/common/jbossbadge.png") + %img(src="#{relative("#{site.jborg_images_url}/common/jbossbadge.png")}") From bfedc3606fb9dc5ada3b843f8930ea7b1fc29399 Mon Sep 17 00:00:00 2001 From: Emmanuel Bernard Date: Fri, 19 Jul 2013 00:26:16 +0200 Subject: [PATCH 3/4] ORG-1737 Make Less use proper relative reference when local cache is used --- _ext/less_config.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/_ext/less_config.rb b/_ext/less_config.rb index 33fed8c..bd81562 100644 --- a/_ext/less_config.rb +++ b/_ext/less_config.rb @@ -28,10 +28,10 @@ class LessConfig def execute(site) output = '' if !site.jborg_fonts_url.nil? - output+= "@jborg_fonts_url: \"" + site.jborg_fonts_url + "\";\n" + output+= "@jborg_fonts_url: \"" + relative(site.jborg_fonts_url, site) + "\";\n" end if !site.jborg_images_url.nil? - output+= "@jborg_images_url: \"" + File.join(site.jborg_images_url , "common") + "\" ;\n" + output+= "@jborg_images_url: \"" + relative(File.join(site.jborg_images_url , "common"), site) + "\" ;\n" end # Create a temporary file with the merged content. @@ -42,6 +42,22 @@ def execute(site) end + def relative(href, site) + if href.start_with?("http://") || href.start_with?("https://") + # do not touch absolute links + href + else + # bootstrap-community.css ends up in /stylesheets : be relative to that directory + begin + result = Pathname.new(File.join(site.config.dir, href)).relative_path_from(Pathname.new(File.join(site.config.stylesheets_dir, "bootstrap-community.css"))).to_s + result + rescue Exception => e + $LOG.error "#{e}" if $LOG.error? + $LOG.error "#{e.backtrace.join("\n")}" if $LOG.error? + end + end + end + end end end From 9d1717b1bffaedffe6197ec65a5268ed6d5e1103 Mon Sep 17 00:00:00 2001 From: Emmanuel Bernard Date: Fri, 19 Jul 2013 01:28:39 +0200 Subject: [PATCH 4/4] ORG-1737 Relativize links to images from css --- _ext/less_config.rb | 3 +++ stylesheets/_community/_features.less | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/_ext/less_config.rb b/_ext/less_config.rb index bd81562..f93ad56 100644 --- a/_ext/less_config.rb +++ b/_ext/less_config.rb @@ -33,6 +33,9 @@ def execute(site) if !site.jborg_images_url.nil? output+= "@jborg_images_url: \"" + relative(File.join(site.jborg_images_url , "common"), site) + "\" ;\n" end + if !site.project_images_url.nil? + output+= "@project_images_url: \"" + relative(site.project_images_url, site) + "\" ;\n" + end # Create a temporary file with the merged content. tmpOutputPath = File.join( site.config.tmp_dir , "config-variables.less") diff --git a/stylesheets/_community/_features.less b/stylesheets/_community/_features.less index 7ff30f8..3994cec 100755 --- a/stylesheets/_community/_features.less +++ b/stylesheets/_community/_features.less @@ -485,7 +485,7 @@ hr.soften { text-indent: -9999px; display: block; margin: 0; - background:@blueDark url(/cache/static.jboss.org/images/example/top.png) no-repeat center center; + background:@blueDark url('@{project_images_url}/top.png') no-repeat center center; } a:hover { background-color:@blue;