Output an nginx rewrite "map"
authorJoerg Jaspert <joerg@debian.org>
Mon, 7 Mar 2016 21:56:24 +0000 (22:56 +0100)
committerJoerg Jaspert <joerg@debian.org>
Mon, 7 Mar 2016 21:56:24 +0000 (22:56 +0100)
_config.yml
_plugins/alias_generator.rb

index 45149d5..38e119b 100644 (file)
@@ -37,7 +37,7 @@ kramdown:
   toc_levels:     1..6
   smart_quotes:   lsquo,rsquo,ldquo,rdquo
 
-exclude: ['README.md', 'Gemfile.lock', 'Gemfile', 'Rakefile']
+exclude: ['README.md', 'Gemfile.lock', 'Gemfile', 'Rakefile', 'nginx.rewrite']
 keep_files:
   - assets/images/resized
 
index 06c1dcb..0755a69 100644 (file)
@@ -31,11 +31,14 @@ module Jekyll
 
   class AliasGenerator < Generator
 
+    @@nginxaliases = Hash.new
+
     def generate(site)
       @site = site
 
       process_posts
       process_pages
+      write_nginx
     end
 
     def process_posts
@@ -50,10 +53,21 @@ module Jekyll
       end
     end
 
+    def write_nginx
+      File.open(File.join(@site.dest, '../nginx.rewrite'), 'w') do |file|
+        @@nginxaliases.each_pair do |dest, aliases|
+          aliases.each do |falias|
+            file.write("rewrite #{falias} #{dest} permanent\n")
+          end
+        end
+      end
+    end
+
     def generate_aliases(destination_path, aliases)
       alias_paths ||= Array.new
       alias_paths << aliases
       alias_paths.compact!
+      @@nginxaliases[destination_path]=Array.new
 
       alias_paths.flatten.each do |alias_path|
         alias_path = File.join('/', alias_path.to_s)
@@ -69,6 +83,7 @@ module Jekyll
         File.open(File.join(fs_path_to_dir, alias_file), 'w') do |file|
           file.write(alias_template(destination_path))
         end
+        @@nginxaliases[destination_path] << File.join(alias_dir, alias_file)
 
         alias_sections.size.times do |sections|
           @site.static_files << Jekyll::AliasFile.new(@site, @site.dest, alias_sections[0, sections + 1].join('/'), '')