diff --git a/.gitignore b/.gitignore index 74a000a..c1299ed 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ discussd/discuss.dirty public/blog public/proj node_modules +public/s42/.htaccess diff --git a/Makefile b/Makefile index 2bbcd0c..ee1673c 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,7 @@ publish_blog: blog publish_assets ./bin/publish.sh --delete public/blog scp public/blog/posts.json bohodev.net:discussd/posts.json scp discussd/discussd.js bohodev.net:discussd/discussd.js + scp public/s42/.htaccess samhuri.net:s42.ca/.htaccess ssh bohodev.net restart-discussd.sh publish_proj: proj publish_assets diff --git a/bin/blog.rb b/bin/blog.rb index 0c9eab3..1081a2b 100755 --- a/bin/blog.rb +++ b/bin/blog.rb @@ -11,6 +11,9 @@ require 'rdiscount' DefaultKeywords = ['sjs', 'sami samhuri', 'sami', 'samhuri', 'samhuri.net', 'blog'] +ShortURLCodeSet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +ShortURLBase = ShortURLCodeSet.length.to_f + def main srcdir = ARGV.shift.to_s destdir = ARGV.shift.to_s @@ -49,6 +52,7 @@ class Blag generate_rss generate_posts_json generate_archive + generate_short_urls copy_assets end @@ -101,6 +105,17 @@ class Blag File.open(rss_file, 'w') { |f| f.puts(rss_for_posts.target!) } end + def generate_short_urls + htaccess = ['RewriteEngine on', 'RewriteRule ^$ http://samhuri.net [R=301,L]'] + posts.reverse.each_with_index do |post, i| + code = shorten(i + 1) + htaccess << "RewriteRule ^#{code}$ #{post[:url]} [R=301,L]" + end + File.open(File.join(@dest, 's4,', '.htaccess'), 'w') do |f| + f.puts(htaccess) + end + end + def copy_assets Dir[File.join(@src, 'css', '*.css')].each do |stylesheet| `yui-compressor #{stylesheet} #{File.join(@css_dest, File.basename(stylesheet).sub('.css', '.min.css'))}` @@ -223,6 +238,15 @@ class Blag xml end + def shorten(n) + short = '' + while n > 0 + short = ShortURLCodeSet[n % ShortURLBase, 1] + short + n = (n / ShortURLBase).floor + end + short + end + end main if $0 == __FILE__