Skip to content

Commit

Permalink
fixed slug bug
Browse files Browse the repository at this point in the history
  • Loading branch information
samhatoum committed Dec 10, 2014
1 parent 9baf763 commit 6b31aaf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package.describe({
name: 'xolvio:md-blog',
summary: 'A markdown powered blog',
version: '0.2.1',
version: '0.2.2',
git: 'https://github.com/xolvio/md-blog'
});

Expand Down
21 changes: 18 additions & 3 deletions src/server/blog-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
function _upsertBlogPost (blog) {
blog.published = blog.published ? blog.published : false;
blog.archived = blog.archived ? blog.archived : false;
blog.slug = _replaceAll(' ', '-', blog.title.toLowerCase());
blog.slug = _getSlug(blog.title);

// if no id was provided, this is a new blog entry so we should create an ID here to extract
// a short ID before this blog is inserted into the DB
Expand Down Expand Up @@ -46,7 +46,7 @@
throw new Meteor.Error(403, "Not authorized to author blog posts");
}
},
'mdBlogCount': function() {
'mdBlogCount': function () {
if (Roles.userIsInRole(this.userId, ['mdblog-author'])) {
return Blog.find().count();
} else {
Expand All @@ -55,8 +55,23 @@
}
});

function _getSlug (title) {

var replace = [
' ', '#', '%', '"', ':', '/',
'^', '`', '[', ']', '{', '}', '<', '>',
';', '@', '&', '=', '+', '$', '|', ','
];

var slug = title.toLowerCase();
for (var i = 0; i < replace.length; i++) {
slug = _replaceAll(replace[i], '-', slug);
}
return slug;
}

function _replaceAll (find, replace, str) {
return str.replace(new RegExp(find, 'g'), replace);
return str.replace(new RegExp('\\' + find, 'g'), replace);
}


Expand Down

0 comments on commit 6b31aaf

Please sign in to comment.