我正在_1138149中开发一个插件,插入一个名为 latex
的新液体标签(块标签) . 它的目的是以这种方式在post源文件中插入一块LaTeX源代码:
... post file contents ...
{% latex density=300 usepackages=pstricks-all, %}
\pspicture(5,5)
\psframe(0,0)(5,5) \psline(0,0)(5,5) \psline(0,5)(5,0)
\endpspicture
{% endlatex %}
... post file contents ...
输出文章将在编译后包含 <img>
标记而不是Liquid Tag块,并且LaTeX源将通过 latex
, dvips
, convert
的链式执行进行编译 . 所以它将取决于外部程序(TexLive和ImageMagick) .
到目前为止,我没有发现任何问题 . 我可以把LaTeX块,把它放在一个临时文件中,最后编译成PNG . 渲染文件 must 将放在帖子的同一文件夹中 .
But just there I'm stuck :我想将生成的PNG图像放到 destination
输出文件夹中的此文件夹中 . 没有问题定义一个site-config变量来定义文件夹(事实上,我这样做),也没有放置文件 . 问题很简单: I can write to the source folder, but the generated files will not be copied to the destination folder .
我知道原因:杰基尔先生成并随后渲染 . 复制过程发生在渲染部分之前,因此不会复制生成的文件 .
我找到了这个SO条目:“How to generate files from Liquid blocks in Jekyll?”,但答案感觉不对:您必须为要复制的文件进行两遍构建 .
还找到了“Generate file inside _site with Jekyll plugin”,但这不适用,因为我不想按模板呈现文档 .
我一直在计划的解决方案是:
-
保留一个包含所有生成文件的文件夹和一些最终放置的索引策略 .
-
为最终的放置程序实施
Site
wide方法,例如:
class Site
def generate_latex_adds
// Code that copies the generated files to destination folders
end
end
- 在
self.cleanup
和self.write
调用之前添加self.generate_latex_adds
在site_process.rb
脚本内调用该方法 .
这可能会解决问题, but I feel wrong to modify the site_process.rb . 我正在考虑将此Liquid Tag作为GitHub项目提供给社区,因此,我必须将此手动编辑 site_process.rb
记录给此插件的用户 . 我知道's probably a common situation and a common solution, but I wonder if there is a better way to pospone the copy of the generated files without modifying core files. I'想保持插件简单:只需将插件文件复制到 _plugins
目录即可 .
有任何想法吗?
EDIT :我对实际代码的推理更感兴趣 . 我想学习,而不是要求代码解决方案 .
1 回答
至今为止,任何人都回答了我的问题,而且我一直在调查这个问题 . 最后,我有一个优雅的解决方案: use the Jekyll::StaticFile class . 我错过了那个课程(旁注:仔细阅读文档) .
将此类的一个对象添加到
site.static_files
数组时,您将此文件标记为挂起,以便复制 after 完成渲染过程 . 实际上,这些文件的副本是在site.write
进程中完成的 . 查看Jekyll安装中的site_process.rb
文件 .这个类的用法很简单 . 当您需要将文件标记为将来的副本时,您只需执行如下代码:
path
和filename
取决于src
文件夹中文件的位置 .这就是全部:您在
src
文件夹中生成文件,将它们标记为待处理副本,让Jekyll完成剩下的工作 . No modification of site_process.rb at all!您可以在GitHub上查看生成的LaTeX - > PNG液体标签代码:https://github.com/fgalindo/jekyll-liquid-latex-plugin
我还在那里实现了一个清理方法,以消除已修改和重建的帖子中的孤立生成文件 .