Jekyll-Assets未复制图像 [英] Image Not Copied by Jekyll-Assets

查看:88
本文介绍了Jekyll-Assets未复制图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Jekyll-资产来管理jekyll项目的资产管道.我在index.html文件中引用了一些不同的图像:

I am using Jekyll-Assets to manage the asset pipeline for a jekyll project. I have references to a few different images on the index.html file:

<img src="{% asset_path slides/slide-1.jpg %}"

源图像位于_assets/images/slides中.我的_config.yml文件已为此源进行了配置:

The source images are located in _assets/images/slides. My _config.yml file has this configured for sources:

sources:
- _assets/images

_assets/slides目录中的五个图像之一未复制到目标_site/assets/slides.其他四个被正确复制.我已经验证了所有五个图像都使用了相同的img标签和液体标签(请参见上文).

One of the five images in the _assets/slides directory is not getting copied to the destination _site/assets/slides. The other four are copied correctly. I have verified that the same img tag and liquid tag are being used for all five images (see above).

但是,我也尝试过:

sources:
- _assets/images
- _assets/images/slides

我已经尝试过重命名图像以及删除子目录幻灯片,但是没有运气.我确实将图像保存(使用Photoshop)为一个全新的文件,并且确实将其复制了.感觉像文件本身的某些属性正在导致此操作被忽略.

I have tried renaming the image as well as removing the subdirectory slides with no luck. I did save the image (using Photoshop) as a completely new file and it does get copied. This feels like some attribute of the file itself is causing this to be omitted.

在什么情况下不会复制资产?

Under what circumstances will an asset not get copied?

推荐答案

我也遇到了这个问题.问题在于,jekyll-assets根据这些文件的内容(的MD5哈希值)删除重复的资产文件.当您有重复的图像时,只有一幅将被复制到目标文件夹.从Photoshop再次保存文件会更改其内容(可能只是时间戳).

I ran into this too. The problem is that jekyll-assets removes duplicate asset files based on (the MD5 hash of) the contents of those files. When you have duplicate images, only one will be copied to the destination folder. Saving the file again from Photoshop changed its contents (possibly just a timestamp).

这是我正在使用的修复程序,它似乎运行良好:

Here's the fix I'm using, which seems to work well:

require "jekyll-assets"

# Monkey-patch jekyll-assets so it doesn't drop duplicate files.
module FixSitePatch
  def self.included(base)
    base.class_eval do
      alias_method :write, :__my_write
    end
  end
  def __my_write
    static_files.push(*asset_files)
    __orig_write
  end
end
Jekyll::Site.send :include, FixSitePatch

这将替换猴子-用其他不会删除重复项的猴子补丁来修补jekyll-assets制作的.将其放在_plugins/ext.rb或当前包含jekyll-assets的任何位置.

This replaces the monkey-patch that jekyll-assets made with a different monkey-patch that doesn't remove duplicates. Put this in _plugins/ext.rb or wherever you currently include jekyll-assets.

对于jekyll-assets来说,重写所有目标资产路径以指向文件的一个唯一副本的方法可能是更好的解决方法,尽管这可能会破坏外部链接或导致搜索引擎出现问题,这些引擎会部分基于路径对内容进行索引组件.

A possibly better fix would be for jekyll-assets to rewrite all the target asset paths to point to the one unique copy of the file, although that could break external links or cause problems with search engines that index content partially based on path components.

或者,您可以对所有重复文件进行一些(不同)编辑,以更改其MD5哈希值,例如,通过更改像素. (在我的情况下,这不能很好地发挥作用,因为在这种情况下,我还有其他脚本可生成内容,例如缩略图.)

Alternatively, you could make some (different) edits to all duplicate files to change their MD5 hashes, e.g., by changing a pixel. (This doesn't work well in my situation, where I have additional scripts generating content such as thumbnails.)

这篇关于Jekyll-Assets未复制图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆