Skip to content

Commit

Permalink
Merge pull request xolvio#15 from adeubank/master
Browse files Browse the repository at this point in the history
Add support for blog path customization
  • Loading branch information
samhatoum committed Jan 12, 2015
2 parents 13d37e2 + 9a85698 commit 83169bb
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 17 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ framework of your choice.
By default, the blog sorts your posts by date. You can change this by modifying the `sortBy`
field in the settings file.

####Blog Routes

The blog runs at the default "/blog" route. The archive runs at the default
"/blog/archive" route. For each post, the default is the "blog/:shortId/:slug" route. You can customize where the blog handles requests by
changing the `blogPath` and `archivePath`. You can also remove the short id from the blog post path by setting the `useUniqueBlogPostsPath` to false.

####Settings File Example
```json
{
Expand All @@ -118,7 +124,10 @@ field in the settings file.
}
]
},
"sortBy": {"date": -1}
"sortBy": {"date": -1},
"blogPath": "/blog",
"archivePath": "/blog/archive",
"useUniqueBlogPostsPath": true
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<a class="pure-menu-heading" href="http://xolv.io" target="_blank">Xolv.io</a>
<ul>
<li class="pure-menu-selected"><a href="/">Home</a></li>
<li><a href="/blog">Blog</a></li>
<li><a href="{{pathFor 'blogList'}}">Blog</a></li>
{{#if currentUser}}
<li><a class="sign-out" href="#">Sign Out</a></li>
{{else}}
Expand Down
5 changes: 4 additions & 1 deletion app/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
}
]
},
"sortBy": {"date": -1}
"sortBy": {"date": -1},
"blogPath": "/blog",
"archivePath": "/blog/archive",
"useUniqueBlogPostsPath": true
}
}
}
21 changes: 11 additions & 10 deletions src/client/blog-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@

var defaultBlogSettings = {
"name": "Blog",
"Description": "Blog posts."
"Description": "Blog posts.",
"blogPath": "/blog",
"archivePath": "/blog/archive",
"useUniqueBlogPostsPath": true,
"prettify": {
"syntax-highlighting": true
}
};

if (!Meteor.settings || !Meteor.settings.public || !Meteor.settings.public.blog) {
Meteor.settings = Meteor.settings || {};
Meteor.settings.public = Meteor.settings.public || {};
Meteor.settings.public.blog = defaultBlogSettings;
} else {
_.defaults(Meteor.settings.public.blog, defaultBlogSettings);
}

if (!Meteor.settings.public.blog.prettify
|| !Meteor.settings.public.blog.prettify['syntax-highlighting']) {
Meteor.settings.public.blog.prettify = Meteor.settings.public.blog.prettify || {};
Meteor.settings.public.blog.prettify['syntax-highlighting'] = Meteor.settings.public.blog.prettify['syntax-highlighting'] || true;
}


'use strict';

// ***********************************************************************************************
Expand Down Expand Up @@ -101,7 +102,7 @@
};
Meteor.call('upsertBlog', newBlog, function(err, blog) {
if (!err) {
Router.go('/blog/' + blog.shortId + '/' + blog.slug);
Router.go('blogPost', blog);
} else {
console.log('Erorr upserting blog', err);
}
Expand Down Expand Up @@ -265,7 +266,7 @@
}
Meteor.call('upsertBlog', this, function (err, blog) {
if (!err) {
Router.go('/blog/' + blog.shortId + '/' + blog.slug);
Router.go('blogPost', blog);
Session.set('mdblog-modified', false);
}
});
Expand Down
26 changes: 23 additions & 3 deletions src/client/blog-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,29 @@

var blogSub = Meteor.subscribe('blog');

function getBaseBlogPath () {
return Meteor.settings.public.blog.blogPath;
}

function getBaseArchivePath () {
return Meteor.settings.public.blog.archivePath;
}

function getBlogPostPath () {

var blogPostPath = getBaseBlogPath();
if (Meteor.settings.public.blog.useUniqueBlogPostsPath) {
blogPostPath += '/:shortId';
}
blogPostPath += '/:slug';

// Remove any duplicate '/'
return _.compact(blogPostPath.split('/')).join('/');
}

Router.map(function () {
this.route('blogList', {
path: '/blog',
path: getBaseBlogPath(),
layoutTemplate: 'blogListLayout',
action: function () {
this.wait(blogSub);
Expand All @@ -17,7 +37,7 @@
});

this.route('blogListArchive', {
path: '/blog/archive',
path: getBaseArchivePath(),
layoutTemplate: 'blogListLayout',
action: function () {
this.wait(blogSub);
Expand All @@ -30,7 +50,7 @@
});

this.route('blogPost', {
path: '/blog/:shortId/:slug',
path: getBlogPostPath(),
layoutTemplate: 'blogPostLayout',
action: function () {
this.wait(blogSub);
Expand Down
2 changes: 1 addition & 1 deletion src/client/blog-templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ <h3 id="summary" {{contenteditable}}>{{{summary}}}</h3>
{{else}}
Loading...
{{/if}}
</template>
</template>

0 comments on commit 83169bb

Please sign in to comment.