Skip to content

Commit

Permalink
added fallback support for SVG
Browse files Browse the repository at this point in the history
  • Loading branch information
garrett committed Jul 3, 2014
1 parent f4e5250 commit ee166b4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
35 changes: 31 additions & 4 deletions source/layouts/_header.haml
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
:ruby
logo = data.site.logo

def graphic_exists file
sitemap.find_resource_by_path("images/#{file}")
end

def make_logo trySVG = false, file = data.site.logo
if graphic_exists file
isSVG = file[/.svg$/] ? 'is-svg' : 'not-svg'
image_tag file, id: "logo", class: "logo #{trySVG ? isSVG : ''}", alt: data.site.name
end
end


%header#branding.masthead.hidden-print(role="banner")
%section.hgroup
%h1
= link_to "/" do
- if data.site.logo
= image_tag data.site.logo, id: "logo", class: "logo", alt: data.site.name
~ link_to "/" do

- if logo

- if logo.match /.svg$/ and graphic_exists logo

- fallback = logo.gsub /.svg$/, '.png'
~ make_logo 'svg'
~ make_logo 'svg', fallback

- elsif

~ make_logo

- else
= data.site.name

~ data.site.name

- if data.site.subhead
%h2#site-title
Expand Down
1 change: 1 addition & 0 deletions source/stylesheets/application.css.sass
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
@import lib/blog.sass

@import lib/stickyfooter.sass
@import lib/svg-fallback.sass

@import font-awesome
3 changes: 3 additions & 0 deletions source/stylesheets/lib/svg-fallback.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
html.svg .not-svg,
html.no-svg .is-svg
display: none

0 comments on commit ee166b4

Please sign in to comment.