2017-08-22 10:53:26 +03:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import {computed} from '@ember/object';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2015-10-28 14:36:45 +03:00
|
|
|
|
2014-11-28 13:15:48 +03:00
|
|
|
/*
|
|
|
|
Example usage:
|
|
|
|
{{gh-url-preview prefix="tag" slug=theSlugValue tagName="p" classNames="description"}}
|
|
|
|
*/
|
2015-10-28 14:36:45 +03:00
|
|
|
export default Component.extend({
|
2018-01-11 20:43:23 +03:00
|
|
|
config: service(),
|
|
|
|
|
2014-11-28 13:15:48 +03:00
|
|
|
classNames: 'ghost-url-preview',
|
|
|
|
prefix: null,
|
|
|
|
slug: null,
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
url: computed('slug', function () {
|
2014-11-28 13:15:48 +03:00
|
|
|
// Get the blog URL and strip the scheme
|
2015-10-28 14:36:45 +03:00
|
|
|
let blogUrl = this.get('config.blogUrl');
|
|
|
|
// Remove `http[s]://`
|
|
|
|
let noSchemeBlogUrl = blogUrl.substr(blogUrl.indexOf('://') + 3);
|
2014-11-28 13:15:48 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
// Get the prefix and slug values
|
2019-03-06 16:53:54 +03:00
|
|
|
let prefix = this.prefix ? `${this.prefix}/` : '';
|
|
|
|
let slug = this.slug ? `${this.slug}/` : '';
|
2014-11-28 13:15:48 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
// Join parts of the URL together with slashes
|
|
|
|
let theUrl = `${noSchemeBlogUrl}/${prefix}${slug}`;
|
2014-11-28 13:15:48 +03:00
|
|
|
|
2015-01-29 20:05:16 +03:00
|
|
|
return theUrl;
|
|
|
|
})
|
2014-11-28 13:15:48 +03:00
|
|
|
});
|