如何从Jekyll中的Liquid块生成文件? [英] How to generate files from Liquid blocks in Jekyll?

查看:77
本文介绍了如何从Jekyll中的Liquid块生成文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个插件,它定义了一个新的Jekyll块ditaa.区块中的任何内容都应从 Ditaa标记转换为图像文件,然后将该图像插入帖子中而不是块.生成文件是可行的,但是当复制到_site目录或在_site目录中生成文件时,该文件显然已删除.

I am writing a plugin that defines a new Jekyll block ditaa. Any content in the block should be converted from Ditaa markup to an image file and that image inserted into the post instead of the block. Generating the file works but when copying into or generating in the _site directory, the file is apparently deleted.

是否有适当/更好的方法来实现可生成自定义资产的块插件?

Is there a proper/better way to implement a block plugin that generates custom assets?

推荐答案

我找到了 proper 解决方案:使用Jekyll::StaticFile.

I've found the proper solution: use the Jekyll::StaticFile class.

将此类的一个对象添加到site.static_files数组时,您将在渲染过程完成后 将该文件标记为待复制.实际上,此类文件的副本是在site.write进程中完成的.看看您的Jekyll安装文件中的site_process.rb文件.

When you add one object of this class to the site.static_files array, you are marking this file as pending for copy after the render process is completed. In fact, the copy of such files is done in the site.write process. Take a look at the site_process.rb file in your Jekyll installation.

此类的用法很简单.当您需要将文件标记为将来复制时,只需执行以下代码即可:

The usage of this class is easy. When you need to mark a file for future copy, you simply execute a code like this:

site.static_files << Jekyll::StaticFile.new(site, site.source, path, filename)

pathfilename的位置取决于文件在src文件夹中的位置.

Where path and filename depends on the location of your file in the src folder.

在开发LaTeX-> PNG液体标签时,我遇到了类似的问题.您可以在GitHub上查看我的代码: https://github.com/fgalindo/jekyll-liquid-latex-plugin

I had a similar issue developing a LaTeX -> PNG liquid tag. You can take a look at my code at GitHub: https://github.com/fgalindo/jekyll-liquid-latex-plugin

这篇关于如何从Jekyll中的Liquid块生成文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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