Skip to content

Instantly share code, notes, and snippets.

@thespacedoctor
Last active May 5, 2021 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thespacedoctor/7a6d081f76830913daea6340f28fabc0 to your computer and use it in GitHub Desktop.
Save thespacedoctor/7a6d081f76830913daea6340f28fabc0 to your computer and use it in GitHub Desktop.
[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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment