Class: RootDirectoryPlugin
- Inherits:
-
Object
- Object
- RootDirectoryPlugin
- Defined in:
- lib/jekyll-root-directory.rb
Instance Method Summary collapse
-
#initialize(site) ⇒ RootDirectoryPlugin
constructor
A new instance of RootDirectoryPlugin.
- #move_files ⇒ Object
Constructor Details
#initialize(site) ⇒ RootDirectoryPlugin
Returns a new instance of RootDirectoryPlugin.
5 6 7 8 |
# File 'lib/jekyll-root-directory.rb', line 5 def initialize(site) @site = site @root_dir = "#{site.source}/_root" end |
Instance Method Details
#move_files ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/jekyll-root-directory.rb', line 10 def move_files() Find.find("#{@root_dir}").select do |filename| filename = filename.gsub("#{@root_dir}/", "") path = "#{@root_dir}/#{filename}" if File.file?("#{path}") # There doesn't seem to be a native Jekyll method to copy + flatten a subfolder :| # This means we need to do it manually. # We can't use StaticFile as it keeps the subfolder used, but we need it for modify times sFile = Jekyll::StaticFile.new(@site, @site.source, "_root", filename) dest_path = "#{@site.config['destination']}/#{filename}" FileUtils.mkdir_p(File.dirname(dest_path)) FileUtils.rm(dest_path) if File.exist?(dest_path) # https://github.com/jekyll/jekyll/blob/22a974200d21a5476e92ee9e33312c583f001271/lib/jekyll/static_file.rb#L192 if @site.safe || Jekyll.env == "production" FileUtils.cp(path, dest_path) else FileUtils.copy_entry(path, dest_path) end unless File.symlink?(dest_path) File.utime(sFile.class.mtimes[path], sFile.class.mtimes[path], dest_path) end end end end |