This repository has been archived by the owner on May 9, 2023. It is now read-only.
forked from diesdasdigital/kirby-meta-knight
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
323 lines (323 loc) Β· 13.4 KB
/
index.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
(function() {
"use strict";
var render$2 = function() {
var _vm = this;
var _h = _vm.$createElement;
var _c = _vm._self._c || _h;
return _c("div", [_c("div", { staticClass: "k-field-label" }, [_c("span", { staticClass: "facebook-icon" }), _vm._v(" " + _vm._s(_vm.headline) + " ")]), _c("div", { staticClass: "open-graph-preview" }, [_c("div", { staticClass: "open-graph-preview__image-container" }, [this.storeImage.length || this.fallbackImage ? _c("img", { staticClass: "open-graph-preview__preview-image", attrs: { "src": _vm.ogImage } }) : _vm._e()]), _c("div", { staticClass: "open-graph-preview__content-container" }, [_c("span", { staticClass: "open-graph-preview__url" }, [_vm._v(_vm._s(_vm.ogSiteName))]), _c("h2", { staticClass: "open-graph-preview__preview-headline", domProps: { "textContent": _vm._s(_vm.ogTitle) } }), _c("p", { staticClass: "open-graph-preview__preview-paragraph" }, [_vm._v(" " + _vm._s(_vm.ogDescription) + " ")])])])]);
};
var staticRenderFns$2 = [];
render$2._withStripped = true;
var facebookPreview_vue_vue_type_style_index_0_lang = "";
function normalizeComponent(scriptExports, render2, staticRenderFns2, functionalTemplate, injectStyles, scopeId, moduleIdentifier, shadowMode) {
var options = typeof scriptExports === "function" ? scriptExports.options : scriptExports;
if (render2) {
options.render = render2;
options.staticRenderFns = staticRenderFns2;
options._compiled = true;
}
if (functionalTemplate) {
options.functional = true;
}
if (scopeId) {
options._scopeId = "data-v-" + scopeId;
}
var hook;
if (moduleIdentifier) {
hook = function(context) {
context = context || this.$vnode && this.$vnode.ssrContext || this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext;
if (!context && typeof __VUE_SSR_CONTEXT__ !== "undefined") {
context = __VUE_SSR_CONTEXT__;
}
if (injectStyles) {
injectStyles.call(this, context);
}
if (context && context._registeredComponents) {
context._registeredComponents.add(moduleIdentifier);
}
};
options._ssrRegister = hook;
} else if (injectStyles) {
hook = shadowMode ? function() {
injectStyles.call(this, (options.functional ? this.parent : this).$root.$options.shadowRoot);
} : injectStyles;
}
if (hook) {
if (options.functional) {
options._injectStyles = hook;
var originalRender = options.render;
options.render = function renderWithStyleInjection(h, context) {
hook.call(context);
return originalRender(h, context);
};
} else {
var existing = options.beforeCreate;
options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
}
}
return {
exports: scriptExports,
options
};
}
const __vue2_script$2 = {
data() {
return {
headline: "Facebook",
url: null,
ogTitle: null,
ogImage: null,
fallbackDescription: null,
fallbackImage: null,
fallbackSiteName: null
};
},
methods: {
async handleLoad(changes) {
let newChanges = {};
Object.entries(changes != null ? changes : this.changes).map(([key, value]) => {
newChanges[key] = encodeURIComponent(value);
});
const response = await this.$api.get(this.parent + "/sections/" + this.name, newChanges);
this.headline = response.headline;
this.ogTitle = response.title;
this.fallbackDescription = response.fallbackDescription;
this.fallbackSiteName = response.fallbackSiteName;
this.fallbackImage = response.fallbackImage;
if (!this.ogImage) {
this.ogImage = response.fallbackImage;
}
this.url = response.url;
}
},
created() {
this.handleLoad();
},
computed: {
changes() {
return this.$store.getters["content/changes"]();
},
ogDescription() {
let ogDescription = this.$store.getters["content/values"]().ogdescription;
if (!ogDescription) {
ogDescription = this.$store.getters["content/values"]().metadescription;
}
return ogDescription === "" ? this.fallbackDescription : ogDescription;
},
ogSiteName() {
let ogSiteName = this.$store.getters["content/values"]().ogsitename;
return ogSiteName === "" ? this.fallbackSiteName : ogSiteName;
},
storeImage() {
return this.$store.getters["content/values"]().ogimage;
}
},
watch: {
storeImage: {
handler() {
if (this.storeImage.length === 0) {
this.ogImage = this.fallbackImage;
} else {
this.$api.files.get(this.$store.getters["content/model"]().api, this.storeImage[0].filename, {
view: "compact"
}).then((response) => {
this.ogImage = response.url;
});
}
},
immediate: true
},
changes(changes) {
this.handleLoad(changes);
}
}
};
const __cssModules$2 = {};
var __component__$2 = /* @__PURE__ */ normalizeComponent(__vue2_script$2, render$2, staticRenderFns$2, false, __vue2_injectStyles$2, null, null, null);
function __vue2_injectStyles$2(context) {
for (let o in __cssModules$2) {
this[o] = __cssModules$2[o];
}
}
__component__$2.options.__file = "src/components/sections/facebook-preview.vue";
var facebookPreview = /* @__PURE__ */ function() {
return __component__$2.exports;
}();
var __glob_1_0 = /* @__PURE__ */ Object.freeze({
__proto__: null,
[Symbol.toStringTag]: "Module",
"default": facebookPreview
});
var render$1 = function() {
var _vm = this;
var _h = _vm.$createElement;
var _c = _vm._self._c || _h;
return _c("div", [_c("div", { staticClass: "k-field-label" }, [_c("span", { staticClass: "google-icon" }), _vm._v(" " + _vm._s(_vm.headline) + " ")]), _c("div", { staticClass: "google-search-preview" }, [_c("div", { staticClass: "google-search-preview__content-container" }, [_c("h2", { staticClass: "google-search-preview__headline", domProps: { "textContent": _vm._s(_vm.metaTitle) } }), _c("span", { staticClass: "google-search-preview__url" }, [_vm._v(_vm._s(_vm.metaUrl))]), _c("p", { staticClass: "google-search-preview__paragraph" }, [_vm._v(" " + _vm._s(_vm.metaDescription) + " ")])])])]);
};
var staticRenderFns$1 = [];
render$1._withStripped = true;
var googlePreview_vue_vue_type_style_index_0_lang = "";
const __vue2_script$1 = {
data() {
return {
headline: "Google Search",
metaTitle: null,
metaUrl: null,
fallbackDescription: null
};
},
created() {
this.handleLoad();
},
methods: {
async handleLoad(changes) {
let newChanges = {};
Object.entries(changes != null ? changes : this.changes).map(([key, value]) => {
newChanges[key] = encodeURIComponent(value);
});
const response = await this.$api.get(this.parent + "/sections/" + this.name, newChanges);
this.headline = response.headline;
this.metaTitle = response.title;
this.fallbackDescription = response.fallbackDescription;
this.metaUrl = response.url;
}
},
computed: {
changes() {
return this.$store.getters["content/changes"]();
},
metaDescription() {
let metaDescription = this.$store.getters["content/values"]().metadescription;
return metaDescription === "" ? this.fallbackDescription : metaDescription;
}
},
watch: {
changes(changes) {
this.handleLoad(changes);
}
}
};
const __cssModules$1 = {};
var __component__$1 = /* @__PURE__ */ normalizeComponent(__vue2_script$1, render$1, staticRenderFns$1, false, __vue2_injectStyles$1, null, null, null);
function __vue2_injectStyles$1(context) {
for (let o in __cssModules$1) {
this[o] = __cssModules$1[o];
}
}
__component__$1.options.__file = "src/components/sections/google-preview.vue";
var googlePreview = /* @__PURE__ */ function() {
return __component__$1.exports;
}();
var __glob_1_1 = /* @__PURE__ */ Object.freeze({
__proto__: null,
[Symbol.toStringTag]: "Module",
"default": googlePreview
});
var render = function() {
var _vm = this;
var _h = _vm.$createElement;
var _c = _vm._self._c || _h;
return _c("div", [_c("div", { staticClass: "k-field-label" }, [_c("span", { staticClass: "twitter-icon" }), _vm._v(" " + _vm._s(_vm.headline) + " ")]), _c("div", { staticClass: "twitter-cards" }, [_vm.twitterCardType === "summary_large_image" ? [_c("div", { staticClass: "twitter-card twitter-card--horizontal" }, [_c("div", { staticClass: "twitter-card__image" }, [this.storeImage.length || this.fallbackImage ? _c("img", { staticClass: "twitter-card__preview-image", attrs: { "src": _vm.twitterImage } }) : _vm._e()]), _c("div", { staticClass: "twitter-card__content-container" }, [_c("h2", { staticClass: "twitter-card__preview-headline" }, [_vm._v(_vm._s(_vm.twitterTitle))]), _c("p", { staticClass: "twitter-card__preview-paragraph" }, [_vm._v(" " + _vm._s(_vm.twitterDescription) + " ")]), _c("span", { staticClass: "twitter-card__url" }, [_vm._v(_vm._s(_vm.twitterUrl))])])])] : [_c("div", { staticClass: "twitter-card" }, [_c("div", { staticClass: "twitter-card__image" }, [this.storeImage.length || this.fallbackImage ? _c("img", { staticClass: "twitter-card__preview-image", attrs: { "src": _vm.twitterImage } }) : _vm._e()]), _c("div", { staticClass: "twitter-card__content-container" }, [_c("h2", { staticClass: "twitter-card__preview-headline" }, [_vm._v(_vm._s(_vm.twitterTitle))]), _c("p", { staticClass: "twitter-card__preview-paragraph" }, [_vm._v(" " + _vm._s(_vm.twitterDescription) + " ")]), _c("span", { staticClass: "twitter-card__url" }, [_vm._v(_vm._s(_vm.twitterUrl))])])])]], 2)]);
};
var staticRenderFns = [];
render._withStripped = true;
var twitterPreview_vue_vue_type_style_index_0_lang = "";
const __vue2_script = {
data() {
return {
headline: "Twitter Card",
twitterTitle: null,
twitterImage: null,
fallbackDescription: null,
fallbackImage: null,
url: null
};
},
created() {
this.handleLoad();
},
methods: {
async handleLoad(changes) {
let newChanges = {};
Object.entries(changes != null ? changes : this.changes).map(([key, value]) => {
newChanges[key] = encodeURIComponent(value);
});
const response = await this.$api.get(this.parent + "/sections/" + this.name, newChanges);
this.headline = response.headline;
this.twitterTitle = response.title;
this.fallbackDescription = response.fallbackDescription;
this.fallbackImage = response.fallbackImage;
if (!this.twitterImage) {
this.twitterImage = response.fallbackImage;
}
this.url = response.url;
}
},
computed: {
changes() {
return this.$store.getters["content/changes"]();
},
twitterCardType() {
let twitterCardType = this.$store.getters["content/values"]().twittercardtype;
return twitterCardType;
},
twitterDescription() {
let twitterDescription = this.$store.getters["content/values"]().twitterdescription;
if (!twitterDescription) {
twitterDescription = this.$store.getters["content/values"]().metadescription;
}
return twitterDescription === "" ? this.fallbackDescription : twitterDescription;
},
storeImage() {
return this.$store.getters["content/values"]().twitterimage;
}
},
watch: {
storeImage: {
handler() {
if (this.storeImage.length === 0) {
this.twitterImage = this.fallbackImage;
} else {
this.$api.files.get(this.$store.getters["content/model"]().api, this.storeImage[0].filename, {
view: "compact"
}).then((response) => {
this.twitterImage = response.url;
});
}
},
immediate: true
},
changes(changes) {
this.handleLoad(changes);
}
}
};
const __cssModules = {};
var __component__ = /* @__PURE__ */ normalizeComponent(__vue2_script, render, staticRenderFns, false, __vue2_injectStyles, null, null, null);
function __vue2_injectStyles(context) {
for (let o in __cssModules) {
this[o] = __cssModules[o];
}
}
__component__.options.__file = "src/components/sections/twitter-preview.vue";
var twitterPreview = /* @__PURE__ */ function() {
return __component__.exports;
}();
var __glob_1_2 = /* @__PURE__ */ Object.freeze({
__proto__: null,
[Symbol.toStringTag]: "Module",
"default": twitterPreview
});
const getComponentName = (path) => path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf(".")).toLowerCase();
const kirbyup = Object.freeze({
import(modules) {
return Object.entries(modules).reduce((accumulator, [path, component]) => {
accumulator[getComponentName(path)] = component.default;
return accumulator;
}, {});
}
});
panel.plugin("coralic/kirby-meta-knight", {
sections: kirbyup.import({ "./components/sections/facebook-preview.vue": __glob_1_0, "./components/sections/google-preview.vue": __glob_1_1, "./components/sections/twitter-preview.vue": __glob_1_2 })
});
})();