From 5eb80dff81e28b4cba7f227ccdc50ed3e5e83b40 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Tue, 16 Oct 2018 14:59:35 +0200 Subject: [PATCH] renamed urlTitle to slug since thats what it should be --- models/blog-post.js | 8 ++++---- routes/admin.js | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/models/blog-post.js b/models/blog-post.js index 8ee89da..1bf656e 100644 --- a/models/blog-post.js +++ b/models/blog-post.js @@ -30,7 +30,7 @@ const blogPostSchema = new mongoose.Schema({ required: [true, 'Short version is required'] }, meta: { - urlTitle: { + slug: { type: String, required: [true, 'Author is required'], trim: true @@ -73,17 +73,17 @@ blogPostSchema.methods.getBlogPostShortTemplateReady = function() { return { content: this.short, title: this.name, - url: common.convertDateToString(this.meta.date) + '/' + this.meta.urlTitle + url: common.convertDateToString(this.meta.date) + '/' + this.meta.slug }; }; blogPostSchema.statics.convertMarkdownToHtml = function(markdown) { return converter.makeHtml(markdown); }; -blogPostSchema.statics.getPost = function(date, urlTitle, callback) { +blogPostSchema.statics.getPost = function(date, slug, callback) { return blogPostModel.findOne({ 'meta.date': date, - 'meta.urlTitle': urlTitle + 'meta.slug': slug }, callback); }; // not tested diff --git a/routes/admin.js b/routes/admin.js index 28526e0..006733f 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -215,7 +215,7 @@ router.post('/admin/api/v1/newpost', adminUserMiddleware.adminAuthenticationRequ meta: { author, category, - urlTitle: title + slug: title .trim() .replace(/\s/g, '-') .replace(/[^A-z0-9-]/g, '') @@ -226,7 +226,7 @@ router.post('/admin/api/v1/newpost', adminUserMiddleware.adminAuthenticationRequ newBlogPost.save().then((post) => { // successfull common.sendApiReturn(res, { - url: common.convertDateToString(post.meta.date) + '/' + post.meta.urlTitle + url: common.convertDateToString(post.meta.date) + '/' + post.meta.slug }); }).catch((rejection) => { // TODO format exception so it doesnt have a huge list of errors @@ -269,7 +269,7 @@ router.post('/admin/api/v1/editpost', adminUserMiddleware.adminAuthenticationReq }, (err, post) => { if (err) return common.sendApiError(res, 500, [err]); common.sendApiReturn(res, { - url: common.convertDateToString(post.meta.date) + '/' + post.meta.urlTitle + url: common.convertDateToString(post.meta.date) + '/' + post.meta.slug }); }); });