when title changes when editing a page, remove old html and markdown pages
This commit is contained in:
parent
27338da86c
commit
df9ebc7706
4 changed files with 27 additions and 4 deletions
|
@ -67,6 +67,25 @@ router.post('/write/:task?', feature_upload, (req, res) => {
|
||||||
}
|
}
|
||||||
body.feature = feature;
|
body.feature = feature;
|
||||||
body.deleted = false;
|
body.deleted = false;
|
||||||
|
//if title changes, get rid of a pages with old title
|
||||||
|
if (body.current_title !== body.slug) {
|
||||||
|
let path =
|
||||||
|
moment(body.created).format('YYYY') + '/' + moment(body.created).format('MM');
|
||||||
|
|
||||||
|
//remove html page
|
||||||
|
fs.unlink('public/' + path + '/' + body.current_title + '.html')
|
||||||
|
.then()
|
||||||
|
.catch(() => {
|
||||||
|
//console.log('HTML ERROR', err);
|
||||||
|
});
|
||||||
|
|
||||||
|
//remove markdown
|
||||||
|
fs.unlink('content/pages/' + path + '/' + body.current_title + '.md')
|
||||||
|
.then()
|
||||||
|
.catch(() => {
|
||||||
|
//console.log('MD ERROR', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
book.editPage(body, body.page_uuid, task, req.session.user)
|
book.editPage(body, body.page_uuid, task, req.session.user)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.type === DataEvent.PAGE_ADDED) {
|
if (result.type === DataEvent.PAGE_ADDED) {
|
||||||
|
|
|
@ -123,7 +123,6 @@ export default class Render {
|
||||||
};
|
};
|
||||||
resolve(response);
|
resolve(response);
|
||||||
}
|
}
|
||||||
//don't render delete pages
|
|
||||||
//check to see if deleted pages have been renderered and delete them
|
//check to see if deleted pages have been renderered and delete them
|
||||||
if (page.metadata.layout !== 'index') {
|
if (page.metadata.layout !== 'index') {
|
||||||
fs.unlink(
|
fs.unlink(
|
||||||
|
@ -134,8 +133,8 @@ export default class Render {
|
||||||
'.html'
|
'.html'
|
||||||
)
|
)
|
||||||
.then()
|
.then()
|
||||||
.catch(err => {
|
.catch(() => {
|
||||||
console.log('ERROR', err);
|
//console.log('ERROR', err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,6 +159,7 @@ export default class Render {
|
||||||
for (let i = 0; i < pages.length; i++) {
|
for (let i = 0; i < pages.length; i++) {
|
||||||
let page = pages[i];
|
let page = pages[i];
|
||||||
|
|
||||||
|
//TODO: filter for deleted and unpublished pages
|
||||||
if (_.includes(page.metadata.tags, tag.tag_name)) {
|
if (_.includes(page.metadata.tags, tag.tag_name)) {
|
||||||
pageList.push({
|
pageList.push({
|
||||||
title: page.metadata.title,
|
title: page.metadata.title,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
extends frame
|
extends frame
|
||||||
block main-content
|
block main-content
|
||||||
#post-edit-index(data-index=id data-uuid=uuid data-layout=layout)
|
#post-edit-index(data-index=id data-uuid=uuid data-layout=layout data-slug=page.slug)
|
||||||
#post-edit-index-wrapper
|
#post-edit-index-wrapper
|
||||||
//h2 EDIT
|
//h2 EDIT
|
||||||
=post_title
|
=post_title
|
||||||
|
|
|
@ -27,6 +27,10 @@ export default class PostActions {
|
||||||
'layout',
|
'layout',
|
||||||
document.getElementById('post-edit-index').getAttribute('data-layout')
|
document.getElementById('post-edit-index').getAttribute('data-layout')
|
||||||
);
|
);
|
||||||
|
pageInfo.append(
|
||||||
|
'current_title',
|
||||||
|
document.getElementById('post-edit-index').getAttribute('data-slug')
|
||||||
|
);
|
||||||
pageInfo.append('content', html);
|
pageInfo.append('content', html);
|
||||||
pageInfo.append('title', document.getElementById('post_title').value);
|
pageInfo.append('title', document.getElementById('post_title').value);
|
||||||
pageInfo.append(
|
pageInfo.append(
|
||||||
|
|
Loading…
Reference in a new issue