thespacedoctor
5/12/2016 - 11:32 AM

[Jekyll supplementary data module] copy jekyll post's supplementary data files to a location adjacent to the post's built html #data #jekyll

[Jekyll supplementary data module] copy jekyll post's supplementary data files to a location adjacent to the post's built html #data #jekyll

module Jekyll
  Jekyll::Hooks.register :site, :post_write do |site|
    build = site.config["destination"]
    site.posts.each {|post| 
      source = post.path.split("/")[0..-2].join("/")
      # SKIP POSTS THAT ARE SINGLE FILES NOT DIRECTORIES
      if source.split("/")[-1] == "_posts"
        next
      end
      destination = post.url.split("/")[0..-2].join("/")

      # MOVE EACH ITEM IN DIRECTORY INTO BUILD
      Dir.entries(source).each {|item| 
        if not [".","..",".DS_Store"].include?(item)
            src = source+"/"+item
            des = build+destination+"/"+item
            FileUtils.copy_entry(src, des)
        end
      }
    }
  end
end