-
Notifications
You must be signed in to change notification settings - Fork 39
Added an noscript fallback for browsers without javascript enabled. #7
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
Changes from 1 commit
4e7d870
56aef57
4a24dcd
93e91fa
a5d65cf
4ca4831
748c701
6ea01cf
13e6357
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
require 'cgi' | ||
require 'open-uri' | ||
|
||
module Jekyll | ||
module Gist | ||
class GistTag < Liquid::Tag | ||
|
@@ -11,7 +14,9 @@ def render(context) | |
if context.has_key?(filename) | ||
filename = context[filename] | ||
end | ||
gist_script_tag(gist_id, filename) | ||
noscript_tag = gist_noscript_tag(gist_id, filename) | ||
script_tag = gist_script_tag(gist_id, filename) | ||
"#{noscript_tag}#{script_tag}" | ||
else | ||
raise ArgumentError.new <<-eos | ||
Syntax error in tag 'gist' while parsing the following markup: | ||
|
@@ -42,6 +47,16 @@ def gist_script_tag(gist_id, filename = nil) | |
end | ||
end | ||
|
||
def gist_noscript_tag(gist_id, filename = nil) | ||
if filename.empty? | ||
uri = "https://gist.githubusercontent.com/#{gist_id}/raw" | ||
else | ||
uri = "https://gist.githubusercontent.com/#{gist_id}/raw/#{filename}" | ||
end | ||
code = open(uri).read.chomp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if I'm offline? (Or if I don't get a 200) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for pointing that out, I will fix that in the next couple of days. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok! This is a great improvement and I'm excited to have it. Let me know if you need anything from me to get this done. 😃 |
||
"<noscript><pre>#{CGI.escapeHTML(code)}</pre></noscript>" | ||
end | ||
|
||
end | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about
to replace the
if
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it does look cleaner.
I guess the same could be done for the
gist_script_tag
method: