# along with this program. If not, see <https://www.gnu.org/licenses/>.
preprocess do
+ # Remove dead annex keys from processing
+ @items.delete_if do |item|
+ l = File.readlink(item.raw_filename)
+ true if !File.exists?(item.raw_filename) and l =~ %r{/annex/objects/}
+ rescue Errno::EINVAL
+ end
+
commit = nil
Open3.popen2("git", "rev-parse", "HEAD") do |stdin, stdout, result|
stdin.close
write @item.identifier.without_ext + '.css'
end
-passthrough '/**/*'
+compile '/**/*' do
+ filter :copybin if @item.binary?
+ write @item.identifier.to_s
+end
+
layout '/**/*.xsl', :xsl
layout '/**/*', :erb
--- /dev/null
+# Nick's web site: copybin filter. No-op filter binary that simply copies the
+# input to the output. This exists primarily to break symlinks in rules.
+#
+# Copyright © 2020 Nick Bowler
+#
+# 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 3 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, see <https://www.gnu.org/licenses/>.
+
+class CopyBinFilter < Nanoc::Filter
+ identifier :copybin
+ type :binary
+
+ require 'fileutils'
+
+ def run(filename, params = {})
+ FileUtils.cp(filename, output_filename)
+ end
+end
--- /dev/null
+# Nick's web site: Workarounds for Nanoc's busted handling of broken symlinks.
+#
+# Copyright © 2020 Nick Bowler
+#
+# 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 3 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, see <https://www.gnu.org/licenses/>.
+
+# Monkey patch the filesystem data source to adjust some strange behavoiur.
+class Nanoc::DataSources::Filesystem < Nanoc::DataSource
+ # The filesystem mtime_of crashes on broken symlinks. Let's not do that,
+ # instead we'll fall back to the link mtime for broken links.
+ def mtime_of(*args)
+ mtimes = args.compact.map do |f|
+ File.stat(f).mtime
+ rescue Errno::ENOENT
+ File.lstat(f).mtime
+ end
+ mtimes.max
+ end
+
+ module Tools
+ @dummy_file = Tempfile.new('dummy')
+
+ # The original resolve_symlink helper uses a readlink loop which
+ # crashes on broken links. I'm also fairly sure symlinks in path
+ # components are not correctly resolved. Let's just use realpath
+ # instead and hope ruby itself doesn't have these bugs.
+ def resolve_symlink(filename, recursion_limit = nil)
+ File.realpath(filename)
+ rescue Errno::ENOENT
+ # Dead link. Return a valid filename otherwise the filesystem
+ # source does bizarre things. The actual items are created with
+ # the original filename so this dummy file does not appear to
+ # leak outside of the filesystem data source implementation.
+ @dummy_file.path
+ end
+ module_function :resolve_symlink
+ end
+end