Ajout de la rubrique rencontres.

This commit is contained in:
David Soulayrol
2024-03-24 21:29:27 +01:00
parent 89223cbf2b
commit 179bb0a850
8 changed files with 157 additions and 12 deletions

View File

@@ -10,10 +10,9 @@ function plugin (options) {
return function (files, metalsmith, done) {
const dest = options.destination
const items = options.files.length
const promises = []
const addTask = function (promise) {
const addTask = function (items, promise) {
promises.push(promise)
if (items === promises.length) {
debug('Waiting for ' + items + 'copy operations.')
@@ -27,8 +26,19 @@ function plugin (options) {
}
}
options.files.forEach((filename) => {
addTask(new Promise(function (resolve, reject) {
const iterateFiles = function (options, action) {
if (options.files != null) {
options.files.forEach((filename) => action(filename, options.files.length))
}
if (options.generator != null) {
options.generator(documents => {
documents.forEach((filename) => action(filename, documents.length))
})
}
}
iterateFiles(options, (filename, items) => {
addTask(items, new Promise(function (resolve, reject) {
fs.stat(filename, function (err, stats) {
if (err) return reject(err)
fs.readFile(filename, function (err, buffer) {