support for multiple sites

master
muflax 2012-04-11 15:50:50 +02:00
parent 6ee3232ffa
commit cb5c0a256c
4 changed files with 76 additions and 39 deletions

68
commands/sites.rb Normal file
View File

@ -0,0 +1,68 @@
# support for site-specific configs
# add option to all nanoc commands
Nanoc::CLI.root_command.modify do
required :s, :site, "custom site" do |site, _|
puts "set site: #{site}, adding config..."
# make site globally accessibly
$site = site
module ::Nanoc
class Site
alias old_build_config build_config
def build_config(dir_or_config_hash)
# build default
old_build_config(dir_or_config_hash)
puts "extend config..."
@config[:output_dir] = "out/#{$site}"
@config[:data_sources] = [{
type: "filesystem_customizable",
source_dir: ["content_#{$site}"],
items_root: "/",
layouts_root: "/",
config: {},
}]
@config[:data_sources].map! { |ds| ds.symbolize_keys }
ssh =
if $site == "muflax"
$site
else
"muflax-#{$site}"
end
@config[:deploy] = {
default: {
dst: "#{ssh}:/home/public",
options: ['-gpPrtvz', '--delete'],
kind: "rsync"
}
}
@config[:watcher][:dirs_to_watch] << "content_#{$site}"
end
end
end
end
end
# add list of all sites so that this file does something useful
usage 'sites'
summary 'prints all available sites'
description 'Prints all sites that can be used via -s SITE.'
module Nanoc::CLI::Commands
class Sites < ::Nanoc::CLI::CommandRunner
def run
self.require_site
puts "sites: #{Dir['content_*'].map{|d| d.gsub(/^content_/, '')}.join ', '}"
end
end
end
runner Nanoc::CLI::Commands::Sites

View File

@ -3,11 +3,6 @@
# will be considered as binary.
text_extensions: [ 'css', 'erb', 'html', 'mkd', 'org', 'scss', 'xml' ]
# The path to the directory where all generated files will be written to. This
# can be an absolute path starting with a slash, but it can also be path
# relative to the site directory.
output_dir: out
# A list of index filenames, i.e. names of files that will be served by a web
# server when a directory is requested. Usually, index files are named
# “index.hml”, but depending on the web server, this may be something else,
@ -19,30 +14,6 @@ index_filenames: [ 'index.html' ]
# before and after the last site compilation.
enable_output_diff: false
# The data sources where nanoc loads its data from. This is an array of
# hashes; each array element represents a single data source. By default,
# there is only a single data source that reads data from the “content/” and
# “layout/” directories in the site directory.
data_sources:
-
# The type is the identifier of the data source. By default, this will be
# `filesystem_unified`.
type: filesystem_customizable
# The path where items should be mounted (comparable to mount points in
# Unix-like systems). This is “/” by default, meaning that items will have
# “/” prefixed to their identifiers. If the items root were “/en/”
# instead, an item at content/about.html would have an identifier of
# “/en/about/” instead of just “/about/”.
items_root: /
# The path where layouts should be mounted. The layouts root behaves the
# same as the items root, but applies to layouts rather than items.
layouts_root: /
# site-specific configs
source_dir: ["content_muflax"]
# Configuration for the “watch” command, which watches a site for changes and
# recompiles if necessary.
watcher:
@ -51,19 +22,13 @@ watcher:
# because recompiling the site will cause these directories to change, which
# will cause the site to be recompiled, which will cause these directories
# to change, which will cause the site to be recompiled again, and so on.
dirs_to_watch: [ 'layouts', 'lib' ]
dirs_to_watch: [ 'content', 'layouts', 'lib' ]
# A list of single files to watch for changes. As mentioned above, dont put
# any files from the “output/” or “tmp/” directories in here.
files_to_watch: [ 'Rules' ]
files_to_watch: [ 'config.yaml', 'Rules' ]
# When to send notifications (using Growl or notify-send).
notify_on_compilation_success: false
notify_on_compilation_failure: false
# deploying the site
deploy:
default:
dst: muflax:/home/public
options: ['-gpPrtvz', '--delete']
kind: rsync

View File

@ -29,8 +29,7 @@ module DataSources
@dtstart = Time.now
end
def down
@dtend = Time.now
puts "Data loaded in #{format('%.2f', @dtend - @dtstart)}s."
puts "Data loaded in #{format('%.2f', Time.now - @dtstart)}s."
end
end
end

View File

@ -5,3 +5,8 @@ end
def blog?
false
end
def sites
Dir['content_*'].map{|d| d.gsub(/^content_/, '')}
end