Class: Jekyll::PostFileGenerator
- Inherits:
-
Generator
- Object
- Generator
- Jekyll::PostFileGenerator
- Defined in:
- lib/jekyll-postfiles.rb
Instance Method Summary collapse
-
#copy_post_files(post) ⇒ Object
Copy the files from post’s folder.
-
#generate(site) ⇒ Object
Generate content by copying files associated with each post.
Instance Method Details
#copy_post_files(post) ⇒ Object
Copy the files from post’s folder.
post - A Post which may have associated content.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/jekyll-postfiles.rb', line 38 def copy_post_files(post) post_path = Pathname.new post.path site = post.site site_src_dir = Pathname.new site.source # Jekyll.logger.warn( # "[PostFiles]", # "Current post: #{post_path[site_src_dir.length..-1]}" # ) post_dir = post_path.dirname dest_dir = Pathname.new(post.destination("")).dirname # Count other Markdown files in the same directory other_md_count = 0 other_md = Dir.glob(post_dir + '*.{md,markdown}', File::FNM_CASEFOLD) do |mdfilepath| if mdfilepath != post_path.to_path other_md_count += 1 end end contents = Dir.glob(post_dir + '**/*') do |filepath| if filepath != post_path \ && !File.directory?(filepath) \ && !File.fnmatch?('*.{md,markdown}', filepath, File::FNM_EXTGLOB | File::FNM_CASEFOLD) filepath = Pathname.new(filepath) # Jekyll.logger.warn( # "[PostFiles]", # "-> attachment: #{filepath[site_src_dir.length..-1]}" # ) if other_md_count > 0 Jekyll.logger.abort_with( "[PostFiles]", "Sorry, there can be only one Markdown file in each directory containing other assets to be copied by jekyll-postfiles" ) end relpath = filepath.relative_path_from(site_src_dir) filedir, filename = relpath.dirname, relpath.basename absfiledir = site_src_dir + filedir new_dir = absfiledir.relative_path_from(post_dir) site.static_files << PostFile.new(site, site_src_dir, filedir, filename, (dest_dir + new_dir).to_path) end end end |
#generate(site) ⇒ Object
Generate content by copying files associated with each post.
87 88 89 90 91 |
# File 'lib/jekyll-postfiles.rb', line 87 def generate(site) site.posts.docs.each do |post| copy_post_files(post) end end |