diff --git a/lib/models/note.js b/lib/models/note.js index 8030be0059..33e0785a30 100644 --- a/lib/models/note.js +++ b/lib/models/note.js @@ -129,6 +129,13 @@ module.exports = function (sequelize, DataTypes) { return resolve(note) }) }) + }, + afterUpdate: function (note, options, callback) { + const filePath = path.join(config.docsPath, note.alias + '.md') + if (Note.checkFileExist(filePath)) { + // if doc in filesystem, write content to file + Note.writeNoteToFilesystem(note, filePath) + } } } }) @@ -583,6 +590,15 @@ module.exports = function (sequelize, DataTypes) { } return operations } + Note.writeNoteToFilesystem = function (note, filePath) { + try { + fs.writeFileSync(filePath, note.content, 'utf8') + return true + } catch (err) { + logger.warn(err) + return false + } + } return Note }