我正在尝试使用 Gulp 创建一个静态站点。我遇到了一个有趣的问题,即翻译我在之前版本中编写的概念以及如何使用 Gulp 实现它。
如果我有动态包含其他文件的文件,则其中一个概念。
---
title: Table of Contents
include:
key: book
value: book-1
---
Introduction.
然后,其他文件包括具有该密钥。
---
title: Chapter 1
book: book-1
---
It was a dark and stormy night...
... 和:
---
title: Chapter 2
book: book-1
---
期望的最终结果是:
---
title: Table of Contents
include:
key: book
value: book-1
files:
- path: chapters/chapter-01.markdown
title: Chapter 1
book: book-1
- path: chapters/chapter-02.markdown
title: Chapter 2
book: book-1
---
基本上,扫描文件并将data
元素作为序列插入到包含内容的页面中。我不知道要提前包含的所有类别或标签(我将 30-40 个 Git 存储库合并在一起),所以我不想为每个类别创建一个任务。
我希望是这样的:
return gulp.src("src/**/*.markdown")
.pipe(magicHappens())
.pipe(gulp.dest("build"));
问题似乎是流的工作方式。我不能将两种方法链接在一起,因为每个文件都从一个管道传递到下一个管道。要插入include.files
元素,我必须解析所有输入文件(它们甚至不在子目录中)以在完成之前找出包含哪些文件。
似乎我必须“拆分流”,解析第一个以获取数据,将第二个链接到第一个的末尾,然后使用第二个将结果传递出方法。我只是不完全确定如何做到这一点,并希望得到一些指示或建议。我的 google-fu 并没有真正提出好的建议,甚至没有我重组的提示。谢谢你。