如何为具有较大图像目录的博客设置Jekyll,以避免在生成的站点中重复该目录? [英] How can I setup Jekyll for a blog with a large image directory, so as to avoid duplicating that directory in the generated site?

查看:56
本文介绍了如何为具有较大图像目录的博客设置Jekyll,以避免在生成的站点中重复该目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑将Jekyll用于一个我正在整合的站点,该站点将是一个包含大量图像(以及其他大型媒体文件)的博客.可以很容易地为图像创建目录,然后根据需要在文章中链接到它们.但是,据我了解,生成站点时,所有图像数据都将复制到包含静态文件的生成的_site目录中.每次生成网站时,都会清空_site目录,并使用该网站的静态版本重新填充该网站.

I'm considering Jekyll for a site I'm putting together that will be a blog with lots of images (and other larg-ish media files). It's easy enough to to make a directory for images and then link to them as needed in the posts. But, as I understand it, when the site is generated, all the image data will be duplicated into the generated _site directory that holds the static files. Each time the site is generated the _site directory is emptied, and repopulated with the static version of the site.

是否有任何方法,例如,将符号链接拖放到站点目录内的images目录,然后在生成静态文件时让jekyll忽略它?

Is there any way to, for example, drop a symlink to the images directory inside the site directory, and then maybe have jekyll ignore it when the static files are generated?

或者还有另一种方法更有意义吗?

Or is there another way to go about this that makes more sense?

推荐答案

假设您正在apache Web服务器上运行,则可以设置Alias指令以从普通docroot之外的目录提供图像.您需要访问权限以编辑VirtualHosts配置或其他创建别名指令的功能(例如,通过控制面板).

Assuming you are running on an apache web server, you can setup an Alias directive to serve images from a directory outside of the normal docroot. You need access to edit the VirtualHosts config or some other ability to create aliases directives (e.g. via a control panel).

有关如何工作的示例,假设您将jekyll文件存储在名为"/web/jekyll"的目录下.要获取图像目录,请执行以下操作:

For an example of how this would work, let's say you are storing your jekyll files under a directory called "/web/jekyll". To get your images directory do the following:

  1. 添加一个"_images"目录以及基本的jekyll树.最终得到这样的结果:

  1. Add an "_images" directory along with your basic jekyll tree. Ending up with something like:

_config.yml
_images/
_layouts/
_posts/
_site/
index.md

  • 更新您的apache配置,以添加Alias指令,例如:

  • Update your apache config to add the Alias directive like:

    Alias /images /web/jekyll/_images
    

  • 重新加载apache配置并运行jekyll来构建站点.

  • Reload the apache config and run jekyll to build the site.

    由于映像目录名称以下划线开头,因此在构建过程中,jekyll不会将其推送/复制到输出_site. Apache将正常地为您_site目录中的大多数文件提供服务,但是当它看到类似"http://jekyll/images/test.jpg"的内容时,而不是在"/web/jekyll/_site/_images/"下查找文件test.jpg",它将通过"/web/jekyll/_images/test.jpg"进行投放.

    Since the image directory name starts with an underscore, jekyll won't push/copy it to the output _site during the build. Apache will happily serve most files from your _site directory as normal, but when it sees something like "http://jekyll/images/test.jpg", instead of looking for the file under "/web/jekyll/_site/_images/test.jpg", it'll serve it from "/web/jekyll/_images/test.jpg".

    顺便说一句,我喜欢源内容和输出内容之间的分隔比jekyll默认情况下的分隔要多一些.因此,我将目录结构设置如下:

    Incidentally, I like a little more separation of the source content and output content than jekyll defaults to. So, I setup my directory structure as follows:

    /web/jekyll/html/
    /web/jekyll/images/
    /web/jekyll/source/
    /web/jekyll/source/_config.yml
    /web/jekyll/source/_layouts
    /web/jekyll/source/_posts
    /web/jekyll/source/index.md
    

    在_config.yml中设置了以下选项

    With the following option set in _config.yml

    destination: ../html
    

    然后使用以下命令设置apache别名指令:

    And the apache alias directive setup with:

    Alias /images /web/jekyll/images
    

    Jekyll在"/web/jekyll/source"目录中运行,但是输出发送到"/web/jekyll/html"目录.与第一个示例类似,从"/web/jekyll/images/test.jpg"提供对"http://jekyll/images/test.jpg"的调用.从网站服务的角度来看,此设置并没有真正的改变.我只喜欢原始源文件,完全烘焙的输出文件和通过别名工作的图像之间更清晰的分隔.

    Jekyll is run in the "/web/jekyll/source" directory, but output is sent to the "/web/jekyll/html" dir. Similar to the first example, calls to "http://jekyll/images/test.jpg" are served from "/web/jekyll/images/test.jpg". This setup doesn't really make a difference from a site serving perspective. I just like the cleaner separation between the raw source files, the fully baked output files and the images which work via the alias.

    这篇关于如何为具有较大图像目录的博客设置Jekyll,以避免在生成的站点中重复该目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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