Skip to content

Commit 37f6f51

Browse files
author
Leon Gersing
committed
Update regex to allow for new sha-ish ids in Gist.
Recently Gist unified all the URLs (which in public gists were numeric and in private gists, alphanumeric). This made certain flows break but Gist now should redirect to the proper url if given either the new SHA-ish id or the classic numeric ID.
1 parent 543018d commit 37f6f51

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

lib/jekyll-gist/gist_tag.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,18 @@ def render(context)
1313
#{@markup}
1414
1515
Valid syntax:
16-
for all gists: {% gist user/1234567 %}
16+
{% gist user/1234567 %}
17+
{% gist user/1234567 foo.js %}
18+
{% gist 28949e1d5ee2273f9fd3 %}
19+
{% gist 28949e1d5ee2273f9fd3 best.md %}
1720
eos
1821
end
1922
end
2023

2124
private
2225

2326
def determine_arguments(input)
24-
matched = if input.include?("/")
25-
input.match(/\A([a-zA-Z0-9\/\-_]+) ?(\S*)\Z/)
26-
else
27-
input.match(/\A(\d+) ?(\S*)\Z/)
28-
end
27+
matched = input.match(/\A([\S]+|.*(?=\/).+)\s?(\S*)\Z/)
2928
[matched[1].strip, matched[2].strip] if matched && matched.length >= 3
3029
end
3130

@@ -41,4 +40,4 @@ def gist_script_tag(gist_id, filename = nil)
4140
end
4241
end
4342

44-
Liquid::Template.register_tag('gist', Jekyll::Gist::GistTag)
43+
Liquid::Template.register_tag('gist', Jekyll::Gist::GistTag)

spec/gist_tag_spec.rb

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
doc.output = Jekyll::Renderer.new(doc.site, doc).run
99
end
1010

11-
context "simple gist" do
12-
let(:gist) { 358471 }
1311

14-
it "produces the correct script tag" do
15-
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
16-
end
17-
end
12+
context "valid gist" do
13+
context "with user prefix" do
14+
let(:gist) { "mattr-/24081a1d93d2898ecf0f" }
1815

19-
context "private gist" do
16+
it "produces the correct script tag" do
17+
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
18+
end
19+
end
2020

21-
context "when valid" do
22-
let(:gist) { "mattr-/24081a1d93d2898ecf0f" }
21+
context "without user prefix" do
22+
let(:gist) { "28949e1d5ee2273f9fd3" }
2323

2424
it "produces the correct script tag" do
2525
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js">\s<\/script>/)
@@ -35,9 +35,13 @@
3535
expect(output).to match(/<script src="https:\/\/gist.github.com\/#{gist}.js\?file=#{filename}">\s<\/script>/)
3636
end
3737
end
38+
end
39+
3840

39-
context "when invalid" do
40-
let(:gist) { "mattr-24081a1d93d2898ecf0f" }
41+
context "invalid gist" do
42+
43+
context "no gist id present" do
44+
let(:gist) { "" }
4145

4246
it "raises an error" do
4347
expect(->{ output }).to raise_error
@@ -46,12 +50,4 @@
4650

4751
end
4852

49-
context "no gist id present" do
50-
let(:gist) { "" }
51-
52-
it "raises an error" do
53-
expect(->{ output }).to raise_error
54-
end
55-
end
56-
5753
end

0 commit comments

Comments
 (0)