Skip to content

Commit e7efada

Browse files
committed
Set site.url
1 parent d768ff9 commit e7efada

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

lib/jekyll/netlify/generator.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ def generate(site)
1212
site.config['environment'] = env.jekyll_env
1313
site.config['netlify'] = load_netlify_env
1414
site.config['netlify']['environment'] = env.prefixed_env
15+
if production?
16+
site.config['url'] = site.config['netlify']['url']
17+
else
18+
site.config['url'] = site.config['netlify']['deploy_url']
19+
end
1520
else
1621
site.config['netlify'] = false
1722
end

test/test_netlify.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ def jekyll_test_site
99
File.join(File.dirname(__FILE__), 'test_site')
1010
end
1111

12+
def get_about_page(site)
13+
return site.pages[0]
14+
end
15+
1216
class Jekyll::NetlifyTest < Minitest::Test
1317
context 'normal build' do
1418
setup do
@@ -26,6 +30,8 @@ class Jekyll::NetlifyTest < Minitest::Test
2630
@site = Jekyll::Site.new(config)
2731
@site.read
2832
@site.generate
33+
@site.render
34+
@about_page = get_about_page(@site)
2935
end
3036

3137
context 'netlify info' do
@@ -37,6 +43,13 @@ class Jekyll::NetlifyTest < Minitest::Test
3743
assert_equal false, @netlify
3844
end
3945
end
46+
47+
context 'site.url' do
48+
should 'be from _config.yml' do
49+
assert_equal 'http://fake.com', @site.config['url']
50+
assert_operator @about_page.output, :include?, 'http://fake.com'
51+
end
52+
end
4053
end
4154

4255
context 'netlify production context' do
@@ -61,6 +74,8 @@ class Jekyll::NetlifyTest < Minitest::Test
6174
@site = Jekyll::Site.new(config)
6275
@site.read
6376
@site.generate
77+
@site.render
78+
@about_page = get_about_page(@site)
6479
end
6580

6681
context 'info' do
@@ -92,14 +107,25 @@ class Jekyll::NetlifyTest < Minitest::Test
92107
assert_equal false, @netlify['webhook']
93108
end
94109
end
110+
111+
context 'site.url' do
112+
should 'be netlify production url' do
113+
assert_equal 'https://example.com', @site.config['url']
114+
end
115+
should 'be expanded in about.md' do
116+
assert_operator @about_page.output, :include?, 'https://example.com'
117+
end
118+
end
95119
end
120+
96121
context 'netlify deploy-preview context' do
97122
setup do
98123
Jekyll.instance_variable_set(
99124
:@logger, Jekyll::LogAdapter.new(Jekyll::Stevenson.new, :error)
100125
)
101126

102127
ENV.clear
128+
ENV['URL'] = 'https://example.com'
103129
ENV['CONTEXT'] = 'deploy-preview'
104130
ENV['JEKYLL_ENV'] = 'staging'
105131

@@ -114,6 +140,8 @@ class Jekyll::NetlifyTest < Minitest::Test
114140
@site = Jekyll::Site.new(config)
115141
@site.read
116142
@site.generate
143+
@site.render
144+
@about_page = get_about_page(@site)
117145
end
118146

119147
context 'info' do
@@ -125,6 +153,15 @@ class Jekyll::NetlifyTest < Minitest::Test
125153
assert_equal 'staging-deploy-preview', @netlify['environment']
126154
end
127155
end
156+
157+
context 'site.url' do
158+
should 'be netlify deploy-preview url' do
159+
assert_equal ENV['DEPLOY_URL'], @site.config['url']
160+
end
161+
should 'be expanded in about.md' do
162+
assert_operator @about_page.output, :include?, ENV['DEPLOY_URL']
163+
end
164+
end
128165
end
129166

130167
context 'netlify unrecognised pull request' do

test/test_site/_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
title: Jekyll Test Site for Jekyll::Netlify
33
description: "This is a test jekyll site with git contents to properly test the Jekyll::Netlify generator"
44
baseurl: ""
5-
url: "http://example.com"
5+
url: "http://fake.com"

test/test_site/about.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ This is a test Jekyll site for Jekyll::Netlify. You can view the plugin at [Gith
88

99
You are welcome to submit pull requests or suggest ideas!
1010

11-
Adding some content
11+
Site: [site.url]({{ site.url }})

0 commit comments

Comments
 (0)