我很好奇,为什么在每个循环中将JavaScript ChapterFiles数组(如下所示)中的每个项目重复两次:
-
var generate_timeline = false
var fs = require('fs');
var files = fs.readdirSync('/home/lamberms/Documents/Book/');
var chapterFiles = files.filter(function filterIfNotChapter(filename) {
return filename.toLowerCase().startsWith("chapter");
});
function loadmd(md) {
var markdown = require('markdown-it')({
html: true
});
// Read and render markdown
var mdfile = fs.readFileSync(md);
var mdContent = markdown.render(mdfile.toString());
// Need slice to take off < and > from beginning and end
return mdContent.slice(1, -2);
}
if !generate_timeline
#cover
img.title-img(src='Assets/asteroid.png')
h1.book-title Awakenings
h2.author by Michael Lambert
each chapterFile in chapterFiles
.chapter
img.title-img(src='Assets/chapter_image.jpg')
#{loadmd(chapterFile)}
#{console.log(chapterFile)}
template#page-footer
style(type='text/css').
.pdf-footer {
font-family: Helvetica;
font-size: 10px;
width: 100%;
text-align: center;
}
img.pageNumber-img(src='Assets/page_number.jpg')
.pdf-footer #[span.pageNumber]
style
include:scss Book.scss
如下面的代码块所示,我正在将文件名写到控制台:
each chapterFile in chapterFiles
.chapter
img.title-img(src='Assets/chapter_image.jpg')
#{loadmd(chapterFile)}
#{console.log(chapterFile)}
其输出是:
正在处理/Book.pug ...
chapter_1.md
chapter_1.md
chapter_appendix_characters.md
chapter_appendix_characters.md
您可以看到每个文件都被处理了两次,并确保它们都在我的pdf输出中。有任何想法吗?提前致谢。 -迈克