#!/usr/bin/env ruby # # Nukumi2 -- a flexible Ruby blogging system # Copyright (C) 2004 Christian Neukirchen # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Written by Christian Neukirchen . # # Make Nukumi2 relocatable. require 'rbconfig' src = File.readlink(__FILE__) rescue __FILE__ $NUKUMI2_ROOT = File.expand_path File.join(File.dirname(src), "..") $: << File.join($NUKUMI2_ROOT, "lib") $: << File.join($NUKUMI2_ROOT, "lib", "ruby", "site_ruby", [Config::CONFIG["MAJOR"], Config::CONFIG["MINOR"]].join(".")) require 'nukumi2' require 'fileutils' require 'optparse' mode = :static opts = OptionParser.new { |opts| opts.banner = "Usage: nukumi2 [--server]" opts.separator "Options:" opts.on("-s", "--server", "Run the Nukumi2 webrick server") do mode = :webrick end opts.on("-h", "--help", "Show this messaged") do puts opts exit end opts.on("--version", "Show version") do puts "Nukumi2 #{Nukumi2::VERSION}" exit end opts.separator "" opts.separator "Nukumi2 version #{Nukumi2::VERSION}, Copyright (C) 2004 Christian Neukirchen" opts.separator "Please report bugs, patches and feature requests to ." opts.parse ARGV } # Preload configuration Nukumi2::DefaultRegistry.config blog = Nukumi2::DefaultRegistry.blog blog.load! if mode == :webrick # Run Webrick require 'webrick' require 'nukumi2/bricklet' require 'nukumi2/xhtmlwebrick' module WEBrick class HTTPServer < ::WEBrick::GenericServer def mount(dir, servlet, *options) # This inspect somehow totally slows down webrick... therefore, override. # @logger.debug(sprintf("%s is mounted on %s.", servlet.inspect, dir)) @mount_tab[dir] = [ servlet, options ] end end end s = Nukumi2::DefaultRegistry.webrick s.mount("/", Nukumi2::Bricklet.new(blog)) trap("INT"){ Thread.new{sleep 1; p "killed"; exit}; s.shutdown } trap("USR1") { blog.reload! } trap("HUP") { blog.reload! } s.start exit else # Static render output_dir = blog.config.static || "blog" blog.categories.each { |topic, options| if options.save blog.topictree.each_path(topic, false) { |path| options.save.to_a.each { |flavor| if path == "/" filepath = "index" else filepath = path[1..-2] end filename = File.join(output_dir, filepath + "." + flavor) page = blog.fetch((path == "/" ? "/" : path.gsub(/\/$/, '')) + "." + flavor) if File.exist?(filename) && File.mtime(filename) > page.last_change next else puts filename FileUtils.mkdir_p File.dirname(filename) File.open(filename, "w") { |file| file.write page.render } end } } end } ["data", "graphics"].each { |dir| Dir[File.join(dir, "**/*")].each { |f| FileUtils.mkdir_p File.join(output_dir, File.dirname(f)) FileUtils.install f, File.join(output_dir, File.dirname(f)) } } end