jekyll-server-redirects 0.1.0
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.
| 
         @@ -0,0 +1,9 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Raw redirects defined in config file.
         
     | 
| 
      
 2 
     | 
    
         
            +
            {% for redirect in raw_redirects %}
         
     | 
| 
      
 3 
     | 
    
         
            +
            Redirect {{ redirect.type }} "{{ redirect.from }}" "{{ redirect.to }}"
         
     | 
| 
      
 4 
     | 
    
         
            +
            {% endfor %}
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            # Redirects configured in each piece of content.
         
     | 
| 
      
 7 
     | 
    
         
            +
            {% for redirect in redirects %}
         
     | 
| 
      
 8 
     | 
    
         
            +
            Redirect permanent "{{ redirect.from }}" "{{ redirect.to }}$1"
         
     | 
| 
      
 9 
     | 
    
         
            +
            {% endfor %}
         
     | 
| 
         @@ -0,0 +1,88 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Jekyll
         
     | 
| 
      
 2 
     | 
    
         
            +
              module ServerRedirects
         
     | 
| 
      
 3 
     | 
    
         
            +
                class ServerRedirectsCommand < Jekyll::Command
         
     | 
| 
      
 4 
     | 
    
         
            +
                  class << self
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                    def init_with_program(prog)
         
     | 
| 
      
 7 
     | 
    
         
            +
                      prog.command(:server_redirects) do |c|
         
     | 
| 
      
 8 
     | 
    
         
            +
                        c.syntax 'server_redirects [options]'
         
     | 
| 
      
 9 
     | 
    
         
            +
                        c.description 'Generate server redirects'
         
     | 
| 
      
 10 
     | 
    
         
            +
                        c.option 'server', '--server_type SERVER', String, 'Type of server to generate redirects for.'
         
     | 
| 
      
 11 
     | 
    
         
            +
                        c.option 'config_template', '-T', '--config_template TEMPLATE_FILE', String, 'Your own Liquid template file from which to generate the redirects configuration.'
         
     | 
| 
      
 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 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                    def process(options)
         
     | 
| 
      
 22 
     | 
    
         
            +
                      options = configuration_from_options(options)
         
     | 
| 
      
 23 
     | 
    
         
            +
                      site = ::Jekyll::Site.new(options)
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                      site.read
         
     | 
| 
      
 26 
     | 
    
         
            +
                      redirects = Array.new
         
     | 
| 
      
 27 
     | 
    
         
            +
                      custom_redirects = site.config['custom_redirects'] || Array.new
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                      site.config['custom_redirects'].each do |conf|
         
     | 
| 
      
 30 
     | 
    
         
            +
                        puts "config: #{conf}"
         
     | 
| 
      
 31 
     | 
    
         
            +
                      end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                      # Default redirect type for raw redirects
         
     | 
| 
      
 34 
     | 
    
         
            +
                      custom_redirects = custom_redirects.map do |r|
         
     | 
| 
      
 35 
     | 
    
         
            +
                        r['redirect'] ||= 'redirect'
         
     | 
| 
      
 36 
     | 
    
         
            +
                        r
         
     | 
| 
      
 37 
     | 
    
         
            +
                      end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                      site.config['custom_redirects'].each do |conf|
         
     | 
| 
      
 40 
     | 
    
         
            +
                        puts "config: #{conf}"
         
     | 
| 
      
 41 
     | 
    
         
            +
                      end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                      incomplete = custom_redirects.select do |r|
         
     | 
| 
      
 44 
     | 
    
         
            +
                        puts "from: #{r.has_key?('from')}, to: #{r.has_key?('to')}"
         
     | 
| 
      
 45 
     | 
    
         
            +
                        STDOUT.flush
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                        !(r.has_key?('from') && r.has_key?('to') && r['from'].length > 0 && r['to'].length > 0)
         
     | 
| 
      
 48 
     | 
    
         
            +
                      end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                      if incomplete.length > 0
         
     | 
| 
      
 51 
     | 
    
         
            +
                        Jekyll.logger.error 'Check [site_redirects] in your config for incomplete entries. Entries should at least have `from` and `to`'
         
     | 
| 
      
 52 
     | 
    
         
            +
                        return nil
         
     | 
| 
      
 53 
     | 
    
         
            +
                      end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                      site.posts.each do |post|
         
     | 
| 
      
 56 
     | 
    
         
            +
                        if post.data.has_key?(':redirect_from') && post.data[':redirect_from'].is_a?(Array)
         
     | 
| 
      
 57 
     | 
    
         
            +
                          post.data[':redirect_from'].each do |from_url|
         
     | 
| 
      
 58 
     | 
    
         
            +
                            redirects.push('from' => Regexp.escape(from_url), 'to' => post.url)
         
     | 
| 
      
 59 
     | 
    
         
            +
                          end
         
     | 
| 
      
 60 
     | 
    
         
            +
                        end
         
     | 
| 
      
 61 
     | 
    
         
            +
                      end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                      template_name = 'nginx-template.conf'
         
     | 
| 
      
 64 
     | 
    
         
            +
                      case options['server']
         
     | 
| 
      
 65 
     | 
    
         
            +
                        when 'nginx'
         
     | 
| 
      
 66 
     | 
    
         
            +
                          template_name = 'nginx-template.conf'
         
     | 
| 
      
 67 
     | 
    
         
            +
                        when 'apache'
         
     | 
| 
      
 68 
     | 
    
         
            +
                          template_name = 'apache-template.conf'
         
     | 
| 
      
 69 
     | 
    
         
            +
                        else
         
     | 
| 
      
 70 
     | 
    
         
            +
                      end
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                      if options['config_template']
         
     | 
| 
      
 73 
     | 
    
         
            +
                        template = Liquid::Template.parse(File.read(options['config_template']))
         
     | 
| 
      
 74 
     | 
    
         
            +
                      else
         
     | 
| 
      
 75 
     | 
    
         
            +
                        template = Liquid::Template.parse(File.read(File.join(File.dirname(__FILE__), template_name)))
         
     | 
| 
      
 76 
     | 
    
         
            +
                      end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                      conf = template.render({
         
     | 
| 
      
 79 
     | 
    
         
            +
                        'redirects' => redirects,
         
     | 
| 
      
 80 
     | 
    
         
            +
                        'raw_redirects' => custom_redirects
         
     | 
| 
      
 81 
     | 
    
         
            +
                      })
         
     | 
| 
      
 82 
     | 
    
         
            +
                      puts conf
         
     | 
| 
      
 83 
     | 
    
         
            +
                      true
         
     | 
| 
      
 84 
     | 
    
         
            +
                    end
         
     | 
| 
      
 85 
     | 
    
         
            +
                  end
         
     | 
| 
      
 86 
     | 
    
         
            +
                end
         
     | 
| 
      
 87 
     | 
    
         
            +
              end
         
     | 
| 
      
 88 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,9 @@ 
     | 
|
| 
      
 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 configured in each piece of content.
         
     | 
| 
      
 7 
     | 
    
         
            +
            {% for redirect in redirects %}
         
     | 
| 
      
 8 
     | 
    
         
            +
            rewrite ^{{ redirect.from }}$ {{ redirect.to }} permanent;
         
     | 
| 
      
 9 
     | 
    
         
            +
            {% endfor %}
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,66 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: jekyll-server-redirects
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.0
         
     | 
| 
      
 5 
     | 
    
         
            +
              prerelease: 
         
     | 
| 
      
 6 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 7 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 8 
     | 
    
         
            +
            - Raúl Santos
         
     | 
| 
      
 9 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 10 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 11 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2016-04-22 00:00:00.000000000 Z
         
     | 
| 
      
 13 
     | 
    
         
            +
            dependencies:
         
     | 
| 
      
 14 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 15 
     | 
    
         
            +
              name: jekyll
         
     | 
| 
      
 16 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 17 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 18 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 19 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 20 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 21 
     | 
    
         
            +
                    version: '3.0'
         
     | 
| 
      
 22 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 23 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 24 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 25 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 26 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 27 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 28 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 29 
     | 
    
         
            +
                    version: '3.0'
         
     | 
| 
      
 30 
     | 
    
         
            +
            description: Generate server redirects for Jekyll.
         
     | 
| 
      
 31 
     | 
    
         
            +
            email: borfast@gmail.com
         
     | 
| 
      
 32 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 33 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 34 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 35 
     | 
    
         
            +
            files:
         
     | 
| 
      
 36 
     | 
    
         
            +
            - lib/jekyll-server-redirects.rb
         
     | 
| 
      
 37 
     | 
    
         
            +
            - lib/jekyll-server-redirects/version.rb
         
     | 
| 
      
 38 
     | 
    
         
            +
            - lib/jekyll-server-redirects/apache-template.conf
         
     | 
| 
      
 39 
     | 
    
         
            +
            - lib/jekyll-server-redirects/command.rb
         
     | 
| 
      
 40 
     | 
    
         
            +
            - lib/jekyll-server-redirects/nginx-template.conf
         
     | 
| 
      
 41 
     | 
    
         
            +
            homepage: https://github.com/borfast/jekyll-server-redirects
         
     | 
| 
      
 42 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 43 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 44 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 45 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 46 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 47 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 48 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 49 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 50 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 51 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 52 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 53 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 54 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 55 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 56 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 57 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 58 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 59 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 60 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 61 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 62 
     | 
    
         
            +
            rubygems_version: 1.8.23
         
     | 
| 
      
 63 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 64 
     | 
    
         
            +
            specification_version: 3
         
     | 
| 
      
 65 
     | 
    
         
            +
            summary: Server redirects for Jekyll
         
     | 
| 
      
 66 
     | 
    
         
            +
            test_files: []
         
     |