jekyll-nginx-config 1.0.0alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1181db4a3258ba96611a54a484e6deef4944d421
4
+ data.tar.gz: 95053b23bab8e8c6b81a7211685d955bb37f733f
5
+ SHA512:
6
+ metadata.gz: 355c169163c36666459297b503a2521f5bef9d5ab3c6f65d44b740f75b566e7eed0c12ad7bb33a196ebe9c171d4792c36af68f43b2544d4a24a0f2b4a3da6533
7
+ data.tar.gz: 0dcba870b8520f5f3dbfc11f2fa2ccc57d345f4c8fcf49591d42dde40e4bd7082d08f01280daa15e587b2075344eeda39675f3f3ae0584b44b924832186b4586
@@ -0,0 +1,7 @@
1
+ require 'jekyll-nginx-config/version'
2
+ require 'jekyll-nginx-config/command'
3
+
4
+ module Jekyll
5
+ module NginxConfig
6
+ end
7
+ end
@@ -0,0 +1,84 @@
1
+ module Jekyll
2
+ module NginxConfig
3
+ class NginxConfigCommand < Jekyll::Command
4
+ class << self
5
+ def init_with_program(prog)
6
+ prog.command(:nginx_config) do |c|
7
+ c.syntax 'nginx_config [options]'
8
+ c.description 'Generate Nginx proxy config'
9
+ c.option 'proxy_host', '-H', '--proxy_host HOST', String, 'FQDN of Jekyll site to proxy to. Used for `proxy_set_header Host <proxy_host>`.'
10
+ c.option 'proxy_port', '-P', '--proxy_port PORT', Integer, 'Port on proxy host serving the Jekyll site. Used for `proxy_pass http://<proxy_host>:<proxy_port>`. Defaults to `80`.'
11
+ c.option 'config_template', '-T', '--config_template TEMPLATE_FILE', String, 'Your own Liquid template file that compose into an nginx config.'
12
+ add_build_options(c)
13
+ c.action do |args, options|
14
+ options['quiet'] = true
15
+ exit(1) unless process options
16
+ end
17
+ end
18
+ end
19
+
20
+ def process(options)
21
+
22
+
23
+ options = configuration_from_options(options)
24
+ site = ::Jekyll::Site.new(options)
25
+ return nil unless site.config['nginx']
26
+
27
+ site.config['nginx']['proxy_host'] = options['proxy_host'] || site.config['nginx']['proxy_host']
28
+ site.config['nginx']['proxy_port'] = options['proxy_port'] || site.config['nginx']['proxy_port']
29
+
30
+ unless site.config['nginx']['proxy_host'].length > 0
31
+ Jekyll.logger.error 'You must at least specify `proxy_host`.'
32
+ return nil
33
+ end
34
+
35
+ site.read
36
+ redirects = Array.new
37
+ raw_redirects = site.config['nginx']['redirects'] || Array.new
38
+ raw_redirects = raw_redirects.map do |r|
39
+ r['redirect'] ||= 'redirect'
40
+ r
41
+ end
42
+
43
+ incomplete = raw_redirects.select do |r|
44
+ !(r.has_key?('from') && r.has_key?('to') && r['from'].length > 0 && r['to'].length > 0)
45
+ end
46
+
47
+ if incomplete.length > 0
48
+ Jekyll.logger.error 'Check [nginx][redirects] in your config for incomplete entries. Entries should at least have `from` and `to`'
49
+ return nil
50
+ end
51
+
52
+ site.posts.each do |post|
53
+ pretty_url = ::Jekyll::URL.new(
54
+ :template => site.config['nginx']['from_format'] || "/:year/:month/:day/:title/",
55
+ :placeholders => post.url_placeholders
56
+ ).to_s
57
+ redirects.push('from' => Regexp.escape(pretty_url), 'to' => post.url)
58
+
59
+ if post.data.has_key?('past_urls') && post.data['past_urls'].is_a?(Array)
60
+ post.data['past_urls'].each do |past_url|
61
+ redirects.push('from' => Regexp.escape(past_url), 'to' => post.url)
62
+ end
63
+ end
64
+ end
65
+
66
+ if options['config_template']
67
+ template = Liquid::Template.parse(File.read(options['config_template']))
68
+ else
69
+ template = Liquid::Template.parse(File.read(File.join(File.dirname(__FILE__), 'nginx-template.conf')))
70
+ end
71
+
72
+ conf = template.render({
73
+ 'proxy_host' => site.config['nginx']['proxy_host'],
74
+ 'proxy_port' => site.config['nginx']['proxy_port'],
75
+ 'redirects' => redirects,
76
+ 'raw_redirects' => site.config['nginx']['redirects']
77
+ })
78
+ puts conf
79
+ true
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,21 @@
1
+ # Raw redirects defined in config file.
2
+ {% for redirect in raw_redirects %}
3
+ rewrite {{ redirect.from }} {{ redirect.to }} {{ redirect.type }};
4
+ {% endfor %}
5
+
6
+ # Redirects legacy URLs (`nginx.from_format`) and past URLs to current URLs.
7
+ {% for redirect in redirects %}
8
+ rewrite ^{{ redirect.from }}?(\?.*)?$ {{ redirect.to }}$1 permanent;
9
+ {% endfor %}
10
+
11
+ # Proxy configuration
12
+ location / {
13
+ proxy_set_header Host {{ proxy_host }};
14
+ proxy_set_header X-Real-IP $remote_addr;
15
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
16
+ {% if proxy_port %}
17
+ proxy_pass http://{{ proxy_host }}:{{ proxy_port }};
18
+ {% else %}
19
+ proxy_pass http://{{ proxy_host }};
20
+ {% endif %}
21
+ }
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module NginxConfig
3
+ VERSION = '1.0.0alpha'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-nginx-config
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0alpha
5
+ platform: ruby
6
+ authors:
7
+ - Bez Hermoso
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ description: Generate nginx proxy config for Jekyll.
28
+ email: bez@activelamp.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/jekyll-nginx-config.rb
34
+ - lib/jekyll-nginx-config/command.rb
35
+ - lib/jekyll-nginx-config/nginx-template.conf
36
+ - lib/jekyll-nginx-config/version.rb
37
+ homepage: https://github.com/activelamp/jekyll-nginx-config
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.1
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.2.2
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Nginx proxy config for Jekyll
61
+ test_files: []