2015-02-12 21:22:32 -07:00
|
|
|
import Ember from 'ember';
|
2015-10-28 11:36:45 +00:00
|
|
|
|
|
|
|
const {Component, computed, inject} = Ember;
|
|
|
|
|
2014-11-28 10:15:48 +00:00
|
|
|
/*
|
|
|
|
Example usage:
|
|
|
|
{{gh-url-preview prefix="tag" slug=theSlugValue tagName="p" classNames="description"}}
|
|
|
|
*/
|
2015-10-28 11:36:45 +00:00
|
|
|
export default Component.extend({
|
2014-11-28 10:15:48 +00:00
|
|
|
classNames: 'ghost-url-preview',
|
|
|
|
prefix: null,
|
|
|
|
slug: null,
|
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
config: inject.service(),
|
2015-05-25 21:10:50 -05:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
url: computed('slug', function () {
|
2014-11-28 10:15:48 +00:00
|
|
|
// Get the blog URL and strip the scheme
|
2015-10-28 11:36:45 +00:00
|
|
|
let blogUrl = this.get('config.blogUrl');
|
|
|
|
// Remove `http[s]://`
|
|
|
|
let noSchemeBlogUrl = blogUrl.substr(blogUrl.indexOf('://') + 3);
|
2014-11-28 10:15:48 +00:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
// Get the prefix and slug values
|
|
|
|
let prefix = this.get('prefix') ? `${this.get('prefix')}/` : '';
|
|
|
|
let slug = this.get('slug') ? `${this.get('slug')}/` : '';
|
2014-11-28 10:15:48 +00:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
// Join parts of the URL together with slashes
|
|
|
|
let theUrl = `${noSchemeBlogUrl}/${prefix}${slug}`;
|
2014-11-28 10:15:48 +00:00
|
|
|
|
2015-01-29 17:05:16 +00:00
|
|
|
return theUrl;
|
|
|
|
})
|
2014-11-28 10:15:48 +00:00
|
|
|
});
|