Skip to content

Commit

Permalink
fix: #45 bug create same content twice
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Nov 28, 2016
1 parent 81bc0cc commit 6d226f9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/cli/cms/operations/create.js
@@ -1,5 +1,6 @@
import path from 'path'
import {
Manager,
coreUtils,
cmsTemplates,
cmsOperations,
Expand All @@ -14,6 +15,13 @@ var create = function(template, pathCreate, name, req, forceJson = {}, duplicate
var postUrl = path.join('/', pathCreate, name)
postUrl = coreUtils.slug.clean(postUrl)

var postExist = Manager.instance.postExist(postUrl)
if (postExist) {
var postJson = cmsData.revision.getDocumentRevision(postUrl)
resolve(postJson)
return
}

var json = (forceJson) ? forceJson : {}
json = cmsData.metas.create(json, template, postUrl)

Expand Down
14 changes: 14 additions & 0 deletions src/cli/core/manager/Manager.js
Expand Up @@ -241,6 +241,20 @@ class Manager {
return this
}

/**
* When a post is modified or created, this method is called so that the manager updates the list with the updated/new item
* @param {String} pathFile The full path to the post
*/
postExist(postUrl){
var parentRelativePath = cmsData.fileAttr.delete(postUrl.split('/').join(path.sep).replace(`.${config.files.templates.extension}`, '.json')).replace(/^\//, '')
const found = coreUtils.array.find(this._list, 'parentRelativePath', parentRelativePath)

if (found.length > 0) {
return true
}
return false
}

/**
* When a post is modified or created, this method is called so that the manager updates the list with the updated/new item
* @param {String} pathFile The full path to the post
Expand Down

0 comments on commit 6d226f9

Please sign in to comment.