mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-04-27 14:57:40 +00:00
short URLs for blog posts using s42.ca
An htaccess file is generated that redirects the short URL to blog posts.
This commit is contained in:
parent
5a0c212d26
commit
12b1f60f39
3 changed files with 26 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -5,3 +5,4 @@ discussd/discuss.dirty
|
||||||
public/blog
|
public/blog
|
||||||
public/proj
|
public/proj
|
||||||
node_modules
|
node_modules
|
||||||
|
public/s42/.htaccess
|
||||||
|
|
|
||||||
1
Makefile
1
Makefile
|
|
@ -29,6 +29,7 @@ publish_blog: blog publish_assets
|
||||||
./bin/publish.sh --delete public/blog
|
./bin/publish.sh --delete public/blog
|
||||||
scp public/blog/posts.json bohodev.net:discussd/posts.json
|
scp public/blog/posts.json bohodev.net:discussd/posts.json
|
||||||
scp discussd/discussd.js bohodev.net:discussd/discussd.js
|
scp discussd/discussd.js bohodev.net:discussd/discussd.js
|
||||||
|
scp public/s42/.htaccess samhuri.net:s42.ca/.htaccess
|
||||||
ssh bohodev.net restart-discussd.sh
|
ssh bohodev.net restart-discussd.sh
|
||||||
|
|
||||||
publish_proj: proj publish_assets
|
publish_proj: proj publish_assets
|
||||||
|
|
|
||||||
24
bin/blog.rb
24
bin/blog.rb
|
|
@ -11,6 +11,9 @@ require 'rdiscount'
|
||||||
|
|
||||||
DefaultKeywords = ['sjs', 'sami samhuri', 'sami', 'samhuri', 'samhuri.net', 'blog']
|
DefaultKeywords = ['sjs', 'sami samhuri', 'sami', 'samhuri', 'samhuri.net', 'blog']
|
||||||
|
|
||||||
|
ShortURLCodeSet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||||
|
ShortURLBase = ShortURLCodeSet.length.to_f
|
||||||
|
|
||||||
def main
|
def main
|
||||||
srcdir = ARGV.shift.to_s
|
srcdir = ARGV.shift.to_s
|
||||||
destdir = ARGV.shift.to_s
|
destdir = ARGV.shift.to_s
|
||||||
|
|
@ -49,6 +52,7 @@ class Blag
|
||||||
generate_rss
|
generate_rss
|
||||||
generate_posts_json
|
generate_posts_json
|
||||||
generate_archive
|
generate_archive
|
||||||
|
generate_short_urls
|
||||||
copy_assets
|
copy_assets
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -101,6 +105,17 @@ class Blag
|
||||||
File.open(rss_file, 'w') { |f| f.puts(rss_for_posts.target!) }
|
File.open(rss_file, 'w') { |f| f.puts(rss_for_posts.target!) }
|
||||||
end
|
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
|
def copy_assets
|
||||||
Dir[File.join(@src, 'css', '*.css')].each do |stylesheet|
|
Dir[File.join(@src, 'css', '*.css')].each do |stylesheet|
|
||||||
`yui-compressor #{stylesheet} #{File.join(@css_dest, File.basename(stylesheet).sub('.css', '.min.css'))}`
|
`yui-compressor #{stylesheet} #{File.join(@css_dest, File.basename(stylesheet).sub('.css', '.min.css'))}`
|
||||||
|
|
@ -223,6 +238,15 @@ class Blag
|
||||||
xml
|
xml
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def shorten(n)
|
||||||
|
short = ''
|
||||||
|
while n > 0
|
||||||
|
short = ShortURLCodeSet[n % ShortURLBase, 1] + short
|
||||||
|
n = (n / ShortURLBase).floor
|
||||||
|
end
|
||||||
|
short
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
main if $0 == __FILE__
|
main if $0 == __FILE__
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue