Add alias feature, make some links end in /
authorJoerg Jaspert <joerg@debian.org>
Sun, 6 Mar 2016 22:30:17 +0000 (23:30 +0100)
committerJoerg Jaspert <joerg@debian.org>
Sun, 6 Mar 2016 22:30:17 +0000 (23:30 +0100)
12 files changed:
_layouts/default.html
_layouts/month-archive.html
_layouts/tag-category.html
_plugins/alias_generator.rb [new file with mode: 0644]
_posts/2011-03-21-debian_ftpmaster_meeting_2011.markdown
_posts/2011-03-21-debian_ftpmaster_meeting_2011_1.markdown
_posts/2011-03-23-debian_ftpmaster_meeting_2011_2.markdown
_posts/2011-03-24-debian_ftpmaster_meeting_2011_3.markdown
_posts/2011-03-25-debian_ftpmaster_meeting_2011_4.markdown
_posts/2011-03-26-debian_ftpmaster_meeting_2011_5.markdown
_posts/2013-03-01-tmux_-_like_screen_just_nicer.markdown
archives/index.html

index f7cac7c..02317ea 100644 (file)
@@ -24,9 +24,9 @@ layout: compress
       <nav>
         <ul>
           <li><a href="/" title="Home">Home</a></li>
-          <li><a href="/category" title="Category overview">Categories</a></li>
-          <li><a href="/archives" title="Blog archive">Archive</a></li>
-          <li><a href="/about" title="About the blog">About</a></li>
+          <li><a href="/category/" title="Category overview">Categories</a></li>
+          <li><a href="/archives/" title="Blog archive">Archive</a></li>
+          <li><a href="/about/" title="About the blog">About</a></li>
           <li><a href="https://git.ganneff.de/" title="git.ganneff.de">Git</a></li>
           <li><a href="https://github.com/Ganneff" title="Github user page Ganneff">Github</a></li>
           <li><a href="/atom.xml" title="Atom feed">Feed</a></li>
index 6463858..c391ca8 100644 (file)
@@ -3,7 +3,7 @@ layout: default
 title: Archive of posts
 ---
 <h1>Archive of posts from {{ page.date | date: "%B" }}
-  <a class="year-link" href="/{{ page.date | date: '%Y' }}" title="Archive of {{ page.date | date: "%Y" }}">{{ page.date | date: "%Y" }}</a></h1>
+  <a class="year-link" href="/{{ page.date | date: '%Y' }}/" title="Archive of {{ page.date | date: "%Y" }}">{{ page.date | date: "%Y" }}</a></h1>
 
 <ul class="posts">
   {% for post in page.posts %}
index 04556f8..271c5b4 100644 (file)
@@ -10,7 +10,7 @@ layout: default
 <p>Back to <a href="/category/" title="Category page" title="Back to category overview">the category overview.</a></p>
 </table>
 {% endunless %}
-<h2><a class="year-link" href="/{{ currentdate }}" title="Year {{ currentdate }}">{{ currentdate }}</a></h2>
+<h2><a class="year-link" href="/{{ currentdate }}/" title="Year {{ currentdate }}">{{ currentdate }}</a></h2>
   <table>
     <tbody>
   {% assign date = currentdate %}
diff --git a/_plugins/alias_generator.rb b/_plugins/alias_generator.rb
new file mode 100644 (file)
index 0000000..06c1dcb
--- /dev/null
@@ -0,0 +1,99 @@
+# Alias Generator for Posts.
+#
+# Generates redirect pages for posts with aliases set in the YAML Front Matter.
+#
+# Place the full path of the alias (place to redirect from) inside the
+# destination post's YAML Front Matter. One or more aliases may be given.
+#
+# Example Post Configuration:
+#
+#   ---
+#     layout: post
+#     title: "How I Keep Limited Pressing Running"
+#     alias: /post/6301645915/how-i-keep-limited-pressing-running/index.html
+#   ---
+#
+# Example Post Configuration:
+#
+#   ---
+#     layout: post
+#     title: "How I Keep Limited Pressing Running"
+#     alias: [/first-alias/index.html, /second-alias/index.html]
+#   ---
+#
+# Author: Thomas Mango
+# Site: http://thomasmango.com
+# Plugin Source: http://github.com/tsmango/jekyll_alias_generator
+# Site Source: http://github.com/tsmango/tsmango.github.com
+# Plugin License: MIT
+
+module Jekyll
+
+  class AliasGenerator < Generator
+
+    def generate(site)
+      @site = site
+
+      process_posts
+      process_pages
+    end
+
+    def process_posts
+      @site.posts.each do |post|
+        generate_aliases(post.url, post.data['alias'])
+      end
+    end
+
+    def process_pages
+      @site.pages.each do |page|
+        generate_aliases(page.destination('').gsub(/index\.(html|htm)$/, ''), page.data['alias'])
+      end
+    end
+
+    def generate_aliases(destination_path, aliases)
+      alias_paths ||= Array.new
+      alias_paths << aliases
+      alias_paths.compact!
+
+      alias_paths.flatten.each do |alias_path|
+        alias_path = File.join('/', alias_path.to_s)
+
+        alias_dir  = File.extname(alias_path).empty? ? alias_path : File.dirname(alias_path)
+        alias_file = File.extname(alias_path).empty? ? "index.html" : File.basename(alias_path)
+
+        fs_path_to_dir = File.join(@site.dest, alias_dir)
+        alias_sections = alias_dir.split('/')[1..-1]
+
+        FileUtils.mkdir_p(fs_path_to_dir)
+
+        File.open(File.join(fs_path_to_dir, alias_file), 'w') do |file|
+          file.write(alias_template(destination_path))
+        end
+
+        alias_sections.size.times do |sections|
+          @site.static_files << Jekyll::AliasFile.new(@site, @site.dest, alias_sections[0, sections + 1].join('/'), '')
+        end
+        @site.static_files << Jekyll::AliasFile.new(@site, @site.dest, alias_dir, alias_file)
+      end
+    end
+
+    def alias_template(destination_path)
+      <<-EOF
+      <!DOCTYPE html>
+      <html><head> <title>Redirecting</title><link rel="canonical" href="#{destination_path}"/><meta http-equiv="content-type" content="text/html; charset=utf-8" /><meta http-equiv="refresh" content="0;url=#{destination_path}" /></head><body><p><strong>Redirecting...</strong></p><p><a href='#{destination_path}'>Click here if you are not redirected.</a></p><script>document.location.href = "#{destination_path}";</script></body></html>
+      EOF
+    end
+  end
+
+  class AliasFile < StaticFile
+    require 'set'
+
+    def modified?
+      return false
+    end
+
+    def write(dest)
+      return true
+    end
+  end
+end
index 8f144f9..bc21e09 100644 (file)
@@ -6,6 +6,7 @@ mt_id: 321
 blog_id: 1
 post_id: 321
 basename: debian_ftpmaster_meeting_2011
+alias: /2011/03/21/debian-ftpmaster-meeting-2011.html
 categories:
 - ftpmaster
 ---
index 8aaf140..a813542 100644 (file)
@@ -6,6 +6,7 @@ mt_id: 322
 blog_id: 1
 post_id: 322
 basename: debian_ftpmaster_meeting_2011_1
+alias: /2011/03/21/debian-ftpmaster-meeting-2011-1.html
 categories:
 - ftpmaster
 ---
index 95640aa..8e6a744 100644 (file)
@@ -7,6 +7,7 @@ mt_id: 323
 blog_id: 1
 post_id: 323
 basename: debian_ftpmaster_meeting_2011_2
+alias: /2011/03/23/debian-ftpmaster-meeting-2011-2.html
 categories:
 - ftpmaster
 ---
index 40029c2..8a7583a 100644 (file)
@@ -7,6 +7,7 @@ mt_id: 324
 blog_id: 1
 post_id: 324
 basename: debian_ftpmaster_meeting_2011_3
+alias: /2011/03/24/debian-ftpmaster-meeting-2011-3.html
 categories:
 - ftpmaster
 ---
index d7f576e..0299182 100644 (file)
@@ -7,6 +7,7 @@ mt_id: 325
 blog_id: 1
 post_id: 325
 basename: debian_ftpmaster_meeting_2011_4
+alias: /2011/03/25/debian-ftpmaster-meeting-2011-4.html
 categories:
 - ftpmaster
 ---
index 071f329..c2159b9 100644 (file)
@@ -6,6 +6,7 @@ mt_id: 326
 blog_id: 1
 post_id: 326
 basename: debian_ftpmaster_meeting_2011_5
+alias: /2011/03/26/debian-ftpmaster-meeting-2011-5.html
 categories:
 - ftpmaster
 ---
index 2575ebc..765e37d 100644 (file)
@@ -6,6 +6,7 @@ mt_id: 389
 blog_id: 1
 post_id: 389
 basename: tmux_-_like_screen_just_nicer
+alias: 2013/03/01/tmux___like_screen_just_nicer.html
 categories:
 - tech
 ---
index be63435..949a09c 100644 (file)
@@ -12,7 +12,7 @@ title: Archives
 {% if currentdate != date %}
     <tr class="yearline">
       <td class="yearcell" colspan="2">
-        <a href="/{{currentdate}}" class="year-link" title="Link to Year {{currentdate}}">{{ currentdate }}</a>
+        <a href="/{{currentdate}}/" class="year-link" title="Link to Year {{currentdate}}">{{ currentdate }}</a>
       </td>
     </tr>
   {% assign date = currentdate %}