2017-08-22 10:53:26 +03:00
|
|
|
import Component from '@ember/component';
|
2022-02-01 12:34:03 +03:00
|
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
import {classNames} from '@ember-decorators/component';
|
2017-08-22 10:53:26 +03:00
|
|
|
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"}}
|
|
|
|
*/
|
2022-02-01 12:34:03 +03:00
|
|
|
@classic
|
|
|
|
@classNames('ghost-url-preview')
|
|
|
|
export default class GhUrlPreview extends Component {
|
2022-02-01 20:03:45 +03:00
|
|
|
@service config;
|
2018-01-11 20:43:23 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
prefix = null;
|
|
|
|
slug = null;
|
2014-11-28 13:15:48 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('slug')
|
|
|
|
get url() {
|
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;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
|
|
|
}
|