Jekyll的本地邮政资产 [英] Local post assets with Jekyll

查看:47
本文介绍了Jekyll的本地邮政资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道其他人在使用Jekyll时如何组织他们的资产用于单个帖子.例如,如果帖子中有图像,您是否只是将其转储到共享图像文件夹中?我真的不喜欢这样做的想法-这意味着当我认为图像应该配对时,图像与帖子是完全分开的.

I was wondering how other people are organising their assets for individual posts when using Jekyll. For example, if a post has an image, do you just dump it in a shared images folder? I don't really like the idea of doing this - it means that an image is completely separated from a post, when I think they should be paired.

推荐答案

我更喜欢将图像视为零个或多个页面中包含的独立资产.大多数情况下,我的图像显示在单个页面中.有时候我想将它们放在多个页面中,在其他情况下,我根本不链接图像.如果您的工作流程是将每张图片都放置在带有帖子的目录中,那么找到它们开始需要大量的搜索,并且对于不属于特定帖子的图片,您必须提出一些不同的建议.

I prefer to think of images as stand alone assets that are included in zero or more pages. Most of the time, my images show up in a single page. There are times when I want to have them in multiple pages and in other cases I don't link an image at all. If your workflow is to put each image in a directory with a post, finding them starts to require a significant amount of searching and you have to come up with something different for images that don't belong to a specific post.

我使用的方法在频谱的另一面.我只有一个图像目录(从"/images"提供),并且100%的图像都存放在该目录中.这样做的好处是:

The approach I use is on the opposite side of the spectrum. I have a single image directory (served from "/images") and 100% of my images are housed there. Benefits of this are:

  1. 当我在帖子中添加图片时,很容易知道要使用的路径.总是这样:

  1. When I'm adding an image to a post it's easy to know what path to use. It's always:

/images/{image-name}

例如: http://alanwsmith.com/i/aws-20111017--0906-02 .这样就可以编写一个插件,因此您只需输入图像名称,其余的已知路径就会自动填写.

For example: http://alanwsmith.com/i/aws-20111017--0906-02. This makes it possible to write a plug-in so all you have to enter is the image name and the rest of the known path is filled out automatically.

使用照片技工之类的应用程序,可以非常轻松地在本地浏览单个目录并查看每个图像.如果我想在另一页上添加图片,则可以大大减少找到图片的时间.

With an application like Photo Mechanic, it's incredibly easy to browse the single directory locally and see every image. If I want to include an image on another page, this drastically reduces the time to find it.

如果我想将图像发送给某人而不将其实际包含在页面中(即,将图像直接发送给该图像文件),则没有单独的位置/过程.我只是将图像放在标准目录中,然后发送直接链接.

There isn't a separate location/process if I want to send an image to someone without actually including it in a page (i.e. send them a direct link to the image file). I just throw the image in the standard directory and send the direct link.

如果您想提高一点,将所有图像保存在一个目录中也可以进行一些很好的调整.例如,即使我图像的URL以"/images"开头,这些图像实际上仍存储在jekyll使用的目录之外的目录中.就我而言,我的源代码树的顶部看起来像这样:

If you want to get a little more advanced, keeping all your images in a single directory makes some nice tweaks possible as well. For example, even though the URLs for my images start with "/images", the images are actually stored in a directory outside of the ones jekyll uses. In my case, the top of my source tree looks like this:

./html
./source-files
./image-files

我所有的图像都存储在"./image-files"目录中.在我的apache配置中,我设置了一个别名,以便URL"/images"指向"./image-files"目录.例如:

All of my images are stored in the "./image-files" directory. In my apache config, I've setup an alias so that the URL "/images" points to the "./image-files" directory. For example:

Alias /images /webroot/image-files

当我运行jekyll时,它将处理"./source-files"中的所有内容并将其放入"./html"中.由于所有图像都在这两个目录之外,因此jekyll永远不会看到/触摸它们.随着图像库的增长,这将有助于加快处理速度并防止大量不必要的文件复制.

When I run jekyll, it process everything in "./source-files" and drops it in "./html". Because all of the images are outside those two directories, jekyll never sees/touches them. As your image library grows this will help speed things up and will prevent a tremendous amount of unnecessary file copying.

我喜欢在Apache中进行的另一项调整:

Another tweak I like in Apache is turning on:

Options +MultiViews

这使您可以调用图像而不必使用文件扩展名(例如,无".jpg",.png"等).您可以在我上面提供的示例链接中看到这一点.对于性能而言,这并不重要.我只是喜欢它的外观,它使我不必在每次调用图像时都键入扩展名.

This lets you call your images without having to use the file extension (e.g. no '.jpg', '.png', etc...). You can see that in the example link I provided above. It doesn't really matter for performance. I just like the way it looks and it saves me from having to type the extension every time I'm calling an image.

MultiViews还可以将一种格式的图像替换为另一种格式,而无需重新编码其他任何内容.例如,如果删除"some-image.gif"并将其替换为"some-image.png",则无需触摸任何HTML.仍将以"/images/some-image"的形式提供.需要进行这样的更改可能非常罕见.我只是认为能够做到这一点很有趣.

MultiViews also makes it possible to replace an image of one format with another without having to recode anything else. For example, if you remove "some-image.gif" and replace it with "some-image.png", you wouldn't have to touch any HTML. It would still be served form "/images/some-image". Needing to make changes like that is probably exceedingly rare. I just think it's an interesting thing to be able to do.

最后,您可以决定是否允许浏览图像目录.就个人而言,我只希望将图像显示在放置它们的位置.因此,我将图像目录中的.htaccess文件设置为:

Finally, you can make a single decision about allowing or disallowing your image directory to be browsed. Personally, I only want my images to show up where I place them. So, I've set the .htaccess file in my images directory to:

Options -Indexes

如果要在具有成千上万个页面和图像的网站上工作,则可能无法缩放.对于普通大小的个人网站,我发现这种方法使维护图像更加容易.

If you are going to be working on a site with many thousands or tens of thousands of pages and images, this might not scale. For a normal sized, personal site, I find that this approach makes maintaining images easier.

这篇关于Jekyll的本地邮政资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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