如何为具有大图像目录的博客设置 Jekyll,以避免在生成的站点中重复该目录?

发布于 2024-11-28 05:03:03 字数 262 浏览 5 评论 0原文

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

有什么方法可以,例如,将符号链接放到站点目录内的图像目录中,然后在生成静态文件时让 jekyll 忽略它?

或者还有其他更有意义的方法来解决这个问题吗?

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

随心而道 2024-12-05 05:03:03

假设您在 apache Web 服务器上运行,您可以设置 Alias 指令来从正常文档根目录之外的目录提供图像。您需要具有编辑 VirtualHosts 配置的权限或创建别名指令的其他能力(例如通过控制面板)。

作为其工作原理的示例,假设您将 jekyll 文件存储在名为“/web/jekyll”的目录下。要获取图像目录,请执行以下操作:

  1. 添加“_images”目录以及基本 jekyll 树。最终得到类似的结果:

    <前><代码>_config.yml
    _图片/
    _布局/
    _帖子/
    _地点/
    索引.md

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

    别名 /images /web/jekyll/_images
    
  3. 重新加载 apache 配置并运行 jekyll 来构建站点。

由于图像目录名称以下划线开头,因此 jekyll 在构建期间不会将其推送/复制到输出 _site。 Apache 会很乐意像平常一样从您的 _site 目录中提供大多数文件,但是当它看到类似“http://jekyll/images/test.jpg”的内容时,而不是在“/web/jekyll/_site/_images/”下查找文件test.jpg”,它将从“/web/jekyll/_images/test.jpg”提供服务。


顺便说一句,我喜欢比 jekyll 默认的源内容和输出内容更加分离。因此,我按如下方式设置目录结构:

/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 中设置以下选项

destination: ../html

,并设置 apache 别名指令:

Alias /images /web/jekyll/images

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

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).

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. Add an "_images" directory along with your basic jekyll tree. Ending up with something like:

    _config.yml
    _images/
    _layouts/
    _posts/
    _site/
    index.md
    
  2. Update your apache config to add the Alias directive like:

    Alias /images /web/jekyll/_images
    
  3. Reload the apache config and run jekyll to build the site.

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".


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

With the following option set in _config.yml

destination: ../html

And the apache alias directive setup with:

Alias /images /web/jekyll/images

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.

栀梦 2024-12-05 05:03:03

正确,jekyll 命令的第一部分会删除目标目录中的所有内容。问题是必须再次手动创建符号链接。接下来,继续创建一个每次都执行此操作的脚本。

请确保:

排除:_config.yml 文件中的 [jekyll, css, img]

linux:“;”符号运行第一、第二、第三......命令。

script:一个名为 jekyll 的文件,具有可执行权限,包含

 jekyll;
 ln -s /var/www/css /var/www/_site/css;
 ln -s /var/www/img /var/www/_site/img;

“最终运行 (./jekyll)”该程序而不是 jekyll。

-担

Correct, the first part of the jekyll command removes everything in the destination directory. The problem with that is the symlinks must be manually created again. So next, go ahead and create a script that does this each time.

Be sure that:

exclude: [jekyll, css, img] in the _config.yml file

linux: The ";" symbol runs first, second, third.. commands.

script: A file named jekyll with executable permissions containing

 jekyll;
 ln -s /var/www/css /var/www/_site/css;
 ln -s /var/www/img /var/www/_site/img;

Finally run (./jekyll) that program instead of jekyll.

-Dan

铁轨上的流浪者 2024-12-05 05:03:03
  1. 为图像创建一个项目页面
  2. 设置目录结构

    <前><代码>/home/git/svnpenn.github.io
    /home/git/img

  3. 运行 Jekyll

    # 在 jekyll 完成之前我们无法添加符号链接。我们将删除
    # site 文件夹并等待它重建。
    rm -r _site
    jekyll --服务器 &
    尽管 [ ! -f_site/index.html]
    做
      睡觉 1
    完毕
    ln -s ../images_site/images
    

注意 我使用它是因为我认为它有助于在 GitHub 上发布时间
页。事实并非如此。 GitHub 可能需要 1-10 分钟才能发布,具体取决于
服务器。

  1. Make a project page for the images.
  2. Set up directory structure

    /home/git/svnpenn.github.io
    /home/git/img
    
  3. Run Jekyll

    # We cant add the symlink until after jekyll is done. We will remove the
    # site folder and wait for it to rebuild.
    rm -r _site
    jekyll --server &
    while [ ! -f _site/index.html ]
    do
      sleep 1
    done
    ln -s ../images _site/images
    

Note I was using this because I thought it would help publish time on GitHub
pages. It does not. GitHub can take 1-10 minutes to publish depending on the
server.

深海夜未眠 2024-12-05 05:03:03

我知道这个问题已经得到了回答,但我走了一条略有不同的路线。我将所有图像托管在 Dropbox 上的公共目录中,并使用 grunt 生成图像清单。它使我的存储库保持较小,因为图像不会被签入。我不久前在 博客文章

I know this has already been answered, but I went a slightly different route. I hosted all of my images in a public directory on Dropbox and use grunt to generate a manifest of the images. It keeps my repository small because the images don't get checked in. I detailed it a while back in a blog post.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文