Skip to content

Commit d895073

Browse files
committed
Merge pull request #14 from jekyll/mention-from-twitter
2 parents 7dea1c8 + 2896082 commit d895073

File tree

3 files changed

+71
-5
lines changed

3 files changed

+71
-5
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,22 @@ Hey @benbalter, what do you think of this?
2727
```
2828

2929
**Note**: Jekyll Mentions simply turns the @mentions into links, it does not notify the mentioned user.
30+
31+
## Configuration
32+
33+
Have your own social network? No problem. We allow you to configure the base URL of all the mentions.
34+
35+
To change it, add the following to your Jekyll configuration:
36+
37+
```yaml
38+
jekyll-mentions:
39+
base_url: https://twitter.com
40+
```
41+
42+
If you're lazy like me, you can use this shorthand:
43+
44+
```yaml
45+
jekyll-mentions: https://twitter.com
46+
```
47+
48+
Et voilà! Your mentions will now use that base URL instead of the default of `https://github.com`.

lib/jekyll-mentions.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33

44
module Jekyll
55
class Mentions < Jekyll::Generator
6-
76
safe true
87

9-
URL = "https://github.com"
8+
DEFAULT_URL = "https://github.com"
109

11-
def initialize(site)
12-
@filter = HTML::Pipeline::MentionFilter.new(nil, {:base_url => URL })
10+
def initialize(config = Hash.new)
11+
@filter = HTML::Pipeline::MentionFilter.new(nil, {:base_url => base_url(config['jekyll-mentions']) })
1312
end
1413

1514
def generate(site)
@@ -25,5 +24,18 @@ def mentionify(page)
2524
def html_page?(page)
2625
page.html? || page.url.end_with?('/')
2726
end
27+
28+
def base_url(configs)
29+
case configs
30+
when nil, NilClass
31+
DEFAULT_URL
32+
when String
33+
configs.to_s
34+
when Hash
35+
configs.fetch('base_url', DEFAULT_URL)
36+
else
37+
raise ArgumentError.new("Your jekyll-mentions config has to either be a string or a hash! It's a #{configs.class} right now.")
38+
end
39+
end
2840
end
2941
end

test/test_jekyll_mentions.rb

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class TestJekyllMentions < Minitest::Test
66
def setup
77
@site = fixture_site
88
@site.read
9-
@mentions = Jekyll::Mentions.new(@site)
9+
@mentions = Jekyll::Mentions.new(@site.config)
1010
@mention = "test <a href='https://github.com/test' class='user-mention'>@test</a> test"
1111
end
1212

@@ -55,4 +55,39 @@ def setup
5555
assert_equal "Parker \"<a href='https://github.com/parkr' class='user-mention'>@parkr</a>\" Moore", page.content
5656
end
5757

58+
context "with special base URL specified" do
59+
def setup
60+
@site = fixture_site
61+
@site.read
62+
@site.config['jekyll-mentions'] = {"base_url" => "https://twitter.com"}
63+
@mentions = Jekyll::Mentions.new(@site.config)
64+
@mention = "test <a href='https://twitter.com/test' class='user-mention'>@test</a> test"
65+
end
66+
67+
should "convert when hash setting" do
68+
page = page_with_name(@site, "index.md")
69+
70+
@mentions.mentionify page
71+
assert_equal @mention, page.content
72+
end
73+
end
74+
75+
context "reading custom base urls" do
76+
def setup
77+
@mentions = Jekyll::Mentions.new(Hash.new)
78+
end
79+
80+
should "handle a raw string" do
81+
assert_equal "https://twitter.com", @mentions.base_url("https://twitter.com")
82+
end
83+
84+
should "handle a hash config" do
85+
assert_equal "https://twitter.com", @mentions.base_url({"base_url" => "https://twitter.com"})
86+
end
87+
88+
should "default to github.com if not there" do
89+
assert_equal "https://github.com", @mentions.base_url(nil)
90+
end
91+
end
92+
5893
end

0 commit comments

Comments
 (0)