Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORG-1737 Make site work as local static website and non root domains #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions _ext/less_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ 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
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.
Expand All @@ -42,6 +45,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
2 changes: 2 additions & 0 deletions _ext/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions _ext/relative.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions _layouts/bothcol.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
= partial( page.rightcol_partial.nil? ? 'rightcol.html.haml' : page.rightcol_partial, {"real_page" => page} )
2 changes: 1 addition & 1 deletion _layouts/leftcol.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions _layouts/project.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'}
2 changes: 1 addition & 1 deletion _layouts/rightcol.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ layout: project
~ content

#rightcol.span3.well
= partial( page.rightcol_partial.nil? ? 'rightcol.html.haml' : page.rightcol_partial )
= partial( page.rightcol_partial.nil? ? 'rightcol.html.haml' : page.rightcol_partial, {"real_page" => page} )
1 change: 1 addition & 0 deletions _partials/banner.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- real_page = page["real_page"]
.banner
%a(href="#")<
.taglinelight.visible-desktop This text is for the project tagline.
2 changes: 1 addition & 1 deletion _partials/companyfooter.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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")}")
22 changes: 12 additions & 10 deletions _partials/head.html.haml
Original file line number Diff line number Diff line change
@@ -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'}
10 changes: 5 additions & 5 deletions _partials/nav.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion _partials/projectfooter.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- real_page = page["real_page"]
%footer.container
.row-fluid
.span2.offset1
Expand Down Expand Up @@ -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)}"}/
2 changes: 1 addition & 1 deletion bothcol.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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")}")
2 changes: 1 addition & 1 deletion index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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")}")
2 changes: 1 addition & 1 deletion rightcol.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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")}")
2 changes: 1 addition & 1 deletion stylesheets/_community/_features.less
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down