support for moved sites

master
muflax 2012-06-23 20:20:36 +02:00
parent 8ca76ff990
commit 8c47154e66
5 changed files with 52 additions and 7 deletions

View File

@ -19,13 +19,15 @@ site_cmds = [
module ::Nanoc
class Site
attr_accessor :name
attr_reader :site_yaml, :moved_yaml
def extended_build_config(dir_or_config_hash, site)
puts "load extended config..."
@name = site
@site_yaml = YAML.load(File.open("sites.yaml"))
@moved_yaml = YAML.load(File.open("moved.yaml"))
@config[:output_dir] = "out/#{site}"
@config[:data_sources] = [{

View File

@ -16,6 +16,11 @@ RewriteRule ^feed/? /rss.xml
<% @site.slug_items.each do |item| %>RewriteRule ^<%= item[:slug].chop %> <%= item.identifier%> [R=301]
<% end %>
# redirect sites if they moved
<% @site.moved_pages.each do |from, to| %>RewriteRule ^<%= from %> <%= to %> [R=301]
<% end %>
# serve gzipped files if available
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME} !\.gz$

View File

@ -20,7 +20,7 @@ class Nanoc::Item
# shared content or not?
def shared?
self[:filename].start_with? "content/"
self[:filename].nil? or self[:filename].start_with? "content/"
end
def draft?
@ -93,6 +93,8 @@ class Nanoc::Site
# slugs for wordpress links
attr_reader :slug_items
# pages that got moved around
def initialize_items
find_printed_items

View File

@ -44,10 +44,6 @@ class Nanoc::Item
def merged_link
raise "no merged link for #{self.identifier}" unless self[:merged]
if m = self[:merged].match(/^(?<site>\w+):(?<page>.+)$/)
"http://#{m[:site] == "muflax" ? "" : "#{m[:site]}."}muflax.com/#{m[:page]}"
else
raise "invalid format: #{self[:merged]}"
end
local_link self[:merged]
end
end

40
lib/links.rb Normal file
View File

@ -0,0 +1,40 @@
def local_link url
if m = url.match(/^(?<site>\w+):(?<page>.+)$/)
"#{site_url m[:site]}/#{m[:page]}"
else
raise "invalid format: #{self[:merged]}"
end
end
def site_url site
"http://#{site == "muflax" ? "" : "#{site}."}muflax.com"
end
def site_link site
site = site.to_s
url = site_url site
title = @site.site_yaml["sites"][site]["title"]
"#{url} - #{title}"
end
def topic_link topic, target
url = local_link target
"#{url} - #{topic}"
end
class Nanoc::Site
def moved_pages
moved = []
sites = @moved_yaml["sites"]
if sites.include? @name
sites[@name].each do |m|
moved << [m["from"], local_link(m["to"])]
end
end
moved
end
end