2022-09-28 20:04:00 -06:00
|
|
|
// Register all the things
|
2022-10-26 11:46:06 -04:00
|
|
|
CMS.init();
|
2022-09-28 20:04:00 -06:00
|
|
|
|
2022-10-26 11:46:06 -04:00
|
|
|
const PostPreview = createClass({
|
2022-09-28 20:04:00 -06:00
|
|
|
render: function () {
|
|
|
|
var entry = this.props.entry;
|
2022-10-26 11:46:06 -04:00
|
|
|
return h(
|
2022-09-28 20:04:00 -06:00
|
|
|
'div',
|
|
|
|
{},
|
2022-10-26 11:46:06 -04:00
|
|
|
h(
|
2022-09-28 20:04:00 -06:00
|
|
|
'div',
|
|
|
|
{ className: 'cover' },
|
2022-10-26 11:46:06 -04:00
|
|
|
h('h1', {}, entry.data.title),
|
2022-09-28 20:04:00 -06:00
|
|
|
this.props.widgetFor('image'),
|
|
|
|
),
|
2022-10-26 11:46:06 -04:00
|
|
|
h('p', {}, h('small', {}, 'Written ' + entry.data.date)),
|
|
|
|
h('div', { className: 'text' }, this.props.widgetFor('body')),
|
2022-09-28 20:04:00 -06:00
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-10-26 11:46:06 -04:00
|
|
|
const GeneralPreview = createClass({
|
2022-09-28 20:04:00 -06:00
|
|
|
render: function () {
|
|
|
|
const entry = this.props.entry;
|
2022-10-20 11:57:30 -04:00
|
|
|
const title = entry.data.site_title;
|
|
|
|
const posts = entry.data.posts;
|
|
|
|
const thumb = posts && posts.thumb;
|
2022-09-28 20:04:00 -06:00
|
|
|
|
2022-10-26 11:46:06 -04:00
|
|
|
return h(
|
2022-09-28 20:04:00 -06:00
|
|
|
'div',
|
|
|
|
{},
|
2022-10-26 11:46:06 -04:00
|
|
|
h('h1', {}, title),
|
|
|
|
h(
|
2022-09-28 20:04:00 -06:00
|
|
|
'dl',
|
|
|
|
{},
|
2022-10-26 11:46:06 -04:00
|
|
|
h('dt', {}, 'Posts on Frontpage'),
|
|
|
|
h('dd', {}, this.props.widgetsFor('posts').widgets.front_limit || 0),
|
2022-09-28 20:04:00 -06:00
|
|
|
|
2022-10-26 11:46:06 -04:00
|
|
|
h('dt', {}, 'Default Author'),
|
|
|
|
h('dd', {}, this.props.widgetsFor('posts').data.author || 'None'),
|
2022-09-28 20:04:00 -06:00
|
|
|
|
2022-10-26 11:46:06 -04:00
|
|
|
h('dt', {}, 'Default Thumbnail'),
|
2022-10-26 14:55:26 -04:00
|
|
|
h('dd', {}, thumb && h('img', { src: this.props.getAsset(thumb).toString() })),
|
2022-09-28 20:04:00 -06:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
2022-10-26 11:46:06 -04:00
|
|
|
const AuthorsPreview = createClass({
|
2022-09-28 20:04:00 -06:00
|
|
|
render: function () {
|
2022-10-26 11:46:06 -04:00
|
|
|
return h(
|
2022-09-28 20:04:00 -06:00
|
|
|
'div',
|
|
|
|
{},
|
2022-10-26 11:46:06 -04:00
|
|
|
h('h1', {}, 'Authors'),
|
2022-09-28 20:04:00 -06:00
|
|
|
this.props.widgetsFor('authors').map(function (author, index) {
|
2022-10-26 11:46:06 -04:00
|
|
|
return h(
|
2022-09-28 20:04:00 -06:00
|
|
|
'div',
|
|
|
|
{ key: index },
|
2022-10-26 11:46:06 -04:00
|
|
|
h('hr', {}),
|
|
|
|
h('strong', {}, author.data.name),
|
2022-10-20 11:57:30 -04:00
|
|
|
author.widgets.description,
|
2022-09-28 20:04:00 -06:00
|
|
|
);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-10-26 11:46:06 -04:00
|
|
|
const RelationKitchenSinkPostPreview = createClass({
|
2022-09-28 20:04:00 -06:00
|
|
|
render: function () {
|
|
|
|
// When a post is selected from the relation field, all of it's data
|
|
|
|
// will be available in the field's metadata nested under the collection
|
|
|
|
// name, and then further nested under the value specified in `value_field`.
|
|
|
|
// In this case, the post would be nested under "posts" and then under
|
|
|
|
// the title of the selected post, since our `value_field` in the config
|
|
|
|
// is "title".
|
|
|
|
const { value, fieldsMetaData } = this.props;
|
2022-10-20 11:57:30 -04:00
|
|
|
const post = fieldsMetaData && fieldsMetaData.posts.value;
|
2022-09-28 20:04:00 -06:00
|
|
|
const style = { border: '2px solid #ccc', borderRadius: '8px', padding: '20px' };
|
|
|
|
return post
|
2022-10-26 11:46:06 -04:00
|
|
|
? h(
|
2022-09-28 20:04:00 -06:00
|
|
|
'div',
|
|
|
|
{ style: style },
|
2022-10-26 11:46:06 -04:00
|
|
|
h('h2', {}, 'Related Post'),
|
|
|
|
h('h3', {}, post.title),
|
|
|
|
h('img', { src: post.image }),
|
|
|
|
h('p', {}, (post.body ?? '').slice(0, 100) + '...'),
|
2022-09-28 20:04:00 -06:00
|
|
|
)
|
|
|
|
: null;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-10-26 14:55:26 -04:00
|
|
|
CMS.registerPreviewStyle('.toastui-editor-contents h1 { color: blue }', { raw: true });
|
2022-10-26 11:46:06 -04:00
|
|
|
CMS.registerPreviewTemplate('posts', PostPreview);
|
|
|
|
CMS.registerPreviewTemplate('general', GeneralPreview);
|
|
|
|
CMS.registerPreviewTemplate('authors', AuthorsPreview);
|
2022-09-28 20:04:00 -06:00
|
|
|
// Pass the name of a registered control to reuse with a new widget preview.
|
2022-10-26 11:46:06 -04:00
|
|
|
CMS.registerWidget('relationKitchenSinkPost', 'relation', RelationKitchenSinkPostPreview);
|
|
|
|
CMS.registerAdditionalLink({
|
2022-10-20 11:57:30 -04:00
|
|
|
id: 'example',
|
|
|
|
title: 'Example.com',
|
|
|
|
data: 'https://example.com',
|
|
|
|
options: {
|
|
|
|
icon: 'page',
|
|
|
|
},
|
|
|
|
});
|