如何让jekyll复制子文件夹? [英] How to get jekyll to copy sub folder?
问题描述
我的_posts文件夹中有jekyll的imgs子文件夹.我使用Markdown表单链接到该文件夹中的图像:
I have an imgs subfolder in my _posts folder for jekyll. I link to images in that folder using the Markdown form:
![myimg](imgs/myimage.jpg)
当我生成网站时,jekyll正确创建了链接:
When I generate the website, jekyll correctly creates the link:
<img src='imgs/myimage.jpg>
,但不会将带有图像的imgs文件夹复制到_site中的正确子目录中.
but it doesn't copy over the imgs folder with the image to the correct subdirectory in _site.
如果html创建为
_site/2013/10/myEntry.html
_site/2013/10/myEntry.html
图片应位于
_site/2013/10/imgs
_site/2013/10/imgs
用于链接的文件夹.
如何配置jekyll以将imgs文件夹复制到_site中的正确位置?
How can I configure jekyll to copy over the imgs folder to the correct place in the _site?
推荐答案
虽然最好将images文件夹放在Jekyll网站的根目录,但是您可以使用一个插件,该插件可使Jekyll识别其中的images文件夹. _posts
.为图像文件添加与发布所用日期格式相同的日期格式前缀,它们将被复制到所需目录结构中的_site
中.
While it is best to put your images folder at the root of your Jekyll site, you can make use of a plugin that will make Jekyll recognize your images folder inside _posts
. Prefix your image files with the same date format as what you use for your posts and they'll be copied over to _site
in the directory structure you want.
# _plugins/post_images.rb
module Jekyll
POST_IMAGES_DIR = '_posts/imgs'
DEST_IMAGES_DIR = 'imgs'
class PostImageFile < StaticFile
def destination(dest)
name_bits = @name.split('-', 4)
date_dir = ''
date_dir += "#{name_bits.shift}/" if name_bits.first.to_i > 0
date_dir += "#{name_bits.shift}/" if name_bits.first.to_i > 0
date_dir += "#{name_bits.shift}/" if name_bits.first.to_i > 0
File.join(dest, date_dir + DEST_IMAGES_DIR, name_bits.join('-'))
end
end
class PostImagesGenerator < Generator
def generate(site)
# Check for the images directory inside the posts directory.
return unless File.exists?(POST_IMAGES_DIR)
post_images = []
# Process each image.
Dir.foreach(POST_IMAGES_DIR) do |entry|
if entry != '.' && entry != '..'
site.static_files << PostImageFile.new(site, site.source, POST_IMAGES_DIR, entry)
post_images << entry.gsub(File.extname(entry), '')
end
end
# Remove images considered to be "actual" posts from the posts array.
site.posts.each do |post|
if post_images.include?(post.id[1..-1].gsub('/', '-'))
site.posts.delete(post)
end
end
end
end
end
这篇关于如何让jekyll复制子文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!