This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
gh-tag-settings-form.js
101 lines (76 loc) · 2.75 KB
/
gh-tag-settings-form.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import Component from '@ember/component';
import Ember from 'ember';
import {computed} from '@ember/object';
import {htmlSafe} from '@ember/string';
import {inject as service} from '@ember/service';
const {Handlebars} = Ember;
export default Component.extend({
feature: service(),
config: service(),
tag: null,
scratchTag: null,
// Allowed actions
setProperty: () => {},
title: computed('tag.isNew', function () {
if (this.get('tag.isNew')) {
return 'New tag';
} else {
return 'Tag settings';
}
}),
seoTitle: computed('scratchTag.{title,metaTitle}', function () {
let metaTitle = this.scratchTag.metaTitle || '';
metaTitle = metaTitle.length > 0 ? metaTitle : this.scratchTag.title;
if (metaTitle && metaTitle.length > 70) {
metaTitle = metaTitle.substring(0, 70).trim();
metaTitle = Handlebars.Utils.escapeExpression(metaTitle);
metaTitle = htmlSafe(`${metaTitle}…`);
}
return metaTitle;
}),
seoURL: computed('scratchTag.slug', function () {
let blogUrl = this.get('config.blogUrl');
let seoSlug = this.scratchTag.slug || '';
let seoURL = `${blogUrl}/tag/${seoSlug}`;
// only append a slash to the URL if the slug exists
if (seoSlug) {
seoURL += '/';
}
if (seoURL.length > 70) {
seoURL = seoURL.substring(0, 70).trim();
seoURL = Handlebars.Utils.escapeExpression(seoURL);
seoURL = htmlSafe(`${seoURL}…`);
}
return seoURL;
}),
seoDescription: computed('scratchTag.{description,metaDescription}', function () {
let metaDescription = this.scratchTag.metaDescription || '';
metaDescription = metaDescription.length > 0 ? metaDescription : this.scratchTag.description;
if (metaDescription && metaDescription.length > 156) {
metaDescription = metaDescription.substring(0, 156).trim();
metaDescription = Handlebars.Utils.escapeExpression(metaDescription);
metaDescription = htmlSafe(`${metaDescription}…`);
}
return metaDescription;
}),
didReceiveAttrs() {
this._super(...arguments);
let oldTagId = this._oldTagId;
let newTagId = this.get('tag.id');
if (newTagId !== oldTagId) {
this.reset();
}
this._oldTagId = newTagId;
},
actions: {
setProperty(property, value) {
this.setProperty(property, value);
},
setCoverImage(image) {
this.setProperty('featureImage', image);
},
clearCoverImage() {
this.setProperty('featureImage', '');
}
}
});