Skip to content

Commit fb6a4aa

Browse files
committed
Merge pull request #29 from jekyll/disable
Merge pull request 29
2 parents 475035e + 936ce4d commit fb6a4aa

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ You may optionally specify a `filename` after the `gist_id`:
4747

4848
This will produce the correct URL to show just the specified file in your post rather than the entire Gist.
4949

50+
## Disabling `noscript` support
51+
52+
By default, Jekyll Gist will make an HTTP call per Gist to retrieve the raw content of the Gist. This information is used to propagate `noscript` tags for search engines and browsers without Javascript support. If you'd like to disable this feature, for example, to speed up builds locally, simply add the following to your site's `_config.yml`:
53+
54+
```yml
55+
gist:
56+
noscript: false
57+
```
58+
5059
## Contributing
5160
5261
1. Fork it ( https://github.com/jekyll/jekyll-gist/fork )

lib/jekyll-gist/gist_tag.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class GistTag < Liquid::Tag
1010

1111
def render(context)
1212
@encoding = context.registers[:site].config['encoding'] || 'utf-8'
13+
@settings = context.registers[:site].config['gist']
1314
if tag_contents = determine_arguments(@markup.strip)
1415
gist_id, filename = tag_contents[0], tag_contents[1]
1516
if context.has_key?(gist_id)
@@ -50,6 +51,7 @@ def gist_script_tag(gist_id, filename = nil)
5051
end
5152

5253
def gist_noscript_tag(gist_id, filename = nil)
54+
return if @settings && @settings["noscript"] == false
5355
code = fetch_raw_code(gist_id, filename)
5456
if !code.nil?
5557
code = code.force_encoding(@encoding)

spec/gist_tag_spec.rb

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
it "produces the correct script tag" do
1919
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
2020
end
21-
it "produces the correct noscript tag" do
21+
it "produces the correct noscript tag" do
2222
expect(output).to match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
2323
end
2424
end
@@ -30,7 +30,7 @@
3030
it "produces the correct script tag" do
3131
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
3232
end
33-
it "produces the correct noscript tag" do
33+
it "produces the correct noscript tag" do
3434
expect(output).to match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
3535
end
3636
end
@@ -42,7 +42,7 @@
4242
it "produces the correct script tag" do
4343
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
4444
end
45-
it "produces the correct noscript tag" do
45+
it "produces the correct noscript tag" do
4646
expect(output).to match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
4747
end
4848
end
@@ -56,7 +56,7 @@
5656
it "produces the correct script tag" do
5757
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js\?file=#{filename}">\s<\/script>/)
5858
end
59-
it "produces the correct noscript tag" do
59+
it "produces the correct noscript tag" do
6060
expect(output).to match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
6161
end
6262
end
@@ -74,7 +74,7 @@
7474
it "produces the correct script tag" do
7575
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{doc.data['gist_id']}.js">\s<\/script>/)
7676
end
77-
it "produces the correct noscript tag" do
77+
it "produces the correct noscript tag" do
7878
expect(output).to match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
7979
end
8080
end
@@ -97,12 +97,12 @@
9797
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{doc.data['gist_id']}.js\?file=#{doc.data['gist_filename']}">\s<\/script>/)
9898
end
9999

100-
it "produces the correct noscript tag" do
100+
it "produces the correct noscript tag" do
101101
expect(output).to match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
102102
end
103103
end
104104

105-
context "with valid gist id and invalid filename" do
105+
context "with valid gist id and invalid filename" do
106106
before { stub_request(:get, "https://gist.githubusercontent.com/#{gist_id}/raw/#{gist_filename}").to_return(status: 404) }
107107
let(:gist_id) { "mattr-/24081a1d93d2898ecf0f" }
108108
let(:gist_filename) { "myfile.ext" }
@@ -112,14 +112,26 @@
112112
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist_id}.js\?file=#{gist_filename}">\s<\/script>/)
113113
end
114114

115-
it "does not produce the noscript tag" do
115+
it "does not produce the noscript tag" do
116116
expect(output).to_not match(/<noscript><pre>&lt;test&gt;true&lt;\/test&gt;<\/pre><\/noscript>\n/)
117117
end
118118

119119
end
120120

121-
end
121+
context "with noscript disabled" do
122+
let(:doc) { doc_with_content(content, { "gist" => { "noscript" => false } }) }
123+
let(:output) do
124+
doc.content = content
125+
doc.output = Jekyll::Renderer.new(doc.site, doc).run
126+
end
127+
let(:gist) { "mattr-/24081a1d93d2898ecf0f" }
122128

129+
it "does not produce the noscript tag" do
130+
expect(output).to_not match(/<noscript>/)
131+
end
132+
end
133+
134+
end
123135

124136
context "invalid gist" do
125137

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def dest_dir(*files)
2727
end
2828

2929
def doc_with_content(content, opts = {})
30-
my_site = site
30+
my_site = site(opts)
3131
Jekyll::Document.new(source_dir('_test/doc.md'), {site: my_site, collection: collection(my_site)})
3232
end
3333

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy