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';
|
2022-11-03 14:14:36 +03:00
|
|
|
import {inject} from 'ghost-admin/decorators/inject';
|
2015-10-28 14:36:45 +03:00
|
|
|
|
2014-11-28 13:15:48 +03:00
|
|
|
/*
|
|
|
|
Example usage:
|
2023-01-04 12:39:32 +03:00
|
|
|
<GhUrlPreview @prefix="tag" @slug={{theSlugValue}} @tagName="p" @classNames="description" />
|
2014-11-28 13:15:48 +03:00
|
|
|
*/
|
2022-02-01 12:34:03 +03:00
|
|
|
@classic
|
|
|
|
@classNames('ghost-url-preview')
|
|
|
|
export default class GhUrlPreview extends Component {
|
2022-11-03 14:14:36 +03:00
|
|
|
@inject 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
|
2022-10-07 17:24:03 +03:00
|
|
|
let blogUrl = this.config.blogUrl;
|
2015-10-28 14:36:45 +03:00
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|