MCPcopy
hub / github.com/jaredly/hexo-admin / rename

Function rename

api.js:87–115  ·  view source on GitHub ↗
(id, body, res)

Source from the content-addressed store, hash-verified

85 }
86
87 function rename(id, body, res) {
88 var model = 'Post'
89 var post = hexo.model('Post').get(id)
90 if (!post) {
91 model = 'Page'
92 post = hexo.model('Page').get(id)
93 if (!post) return res.send(404, "Post not found")
94 }
95 // remember old path w/o index.md
96 var oldPath = post.full_source
97 oldPath = oldPath.slice(0, oldPath.indexOf('index.md'))
98
99 updateAny(model, id, {source: body.filename}, function (err, post) {
100 if (err) {
101 return res.send(400, err);
102 }
103 hexo.log.d(`renamed ${model.toLowerCase()} to ${body.filename}`)
104
105 // remove old folder if empty
106 if (model === 'Page' && fs.existsSync(oldPath)) {
107 if (fs.readdirSync(oldPath).length === 0) {
108 fs.rmdirSync(oldPath)
109 hexo.log.d('removed old page\'s empty directory')
110 }
111 }
112
113 res.done(addIsDraft(post))
114 }, hexo)
115 }
116
117 var use = function (path, fn) {
118 app.use(hexo.config.root + 'admin/api/' + path, function (req, res) {

Callers 2

api.jsFile · 0.85
gulpfile.jsFile · 0.85

Calls 1

addIsDraftFunction · 0.85

Tested by

no test coverage detected