Skip to content

Commit b708d48

Browse files
dmalanjekyllbot
authored andcommitted
Allows generation of redirects.json to be disabled (#207)
Merge pull request 207
1 parent 26d6e61 commit b708d48

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,19 @@ Your layout will get the following variables:
127127
* `page.redirect.from` - the relative path to the redirect page
128128
* `page.redirect.to` - the absolute URL (where available) to the target page
129129

130+
## Configuration
131+
132+
You can configure this plugin in `_config.yml` by adding to the `redirect_from` key.
133+
134+
### Disabling `redirects.json`
135+
136+
By default, a file called `redirects.json`, which can be used for automated testing or to implement server-side redirects, will be included in the output. To exclude it from the output, set the `json` key to `false`:
137+
138+
```yml
139+
redirect_from:
140+
json: false
141+
```
142+
130143
## Contributing
131144

132145
1. Fork it

lib/jekyll-redirect-from/generator.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def generate(site)
2222
generate_redirect_to(doc)
2323
end
2424

25-
generate_redirects_json
25+
generate_redirects_json if generate_redirects_json?
2626
end
2727

2828
private
@@ -53,5 +53,9 @@ def generate_redirects_json
5353
page.data["layout"] = nil
5454
site.pages << page
5555
end
56+
57+
def generate_redirects_json?
58+
site.config.dig("redirect_from", "json") != false
59+
end
5660
end
5761
end

spec/jekyll_redirect_from/generator_spec.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
let(:redirects) { JSON.parse(contents) }
9595
let(:domain) { "http://jekyllrb.com" }
9696

97-
it "creates the redirets file" do
97+
it "creates the redirects file" do
9898
expect(path).to exist
9999
end
100100

@@ -140,10 +140,18 @@
140140
FileUtils.rm_f source_path
141141
end
142142

143-
it "doesn't overwrite redirets.json" do
143+
it "doesn't overwrite redirects.json" do
144144
expect(path).to exist
145145
expect(redirects).to eql("foo" => "bar")
146146
end
147147
end
148+
149+
context "when explicitly disabled" do
150+
let(:site) { Jekyll::Site.new(config.merge("redirect_from" => { "json" => false })) }
151+
152+
it "does not create the redirects file" do
153+
expect(path).to_not exist
154+
end
155+
end
148156
end
149157
end

0 commit comments

Comments
 (0)