2018-09-06 14:44:58 -04:00
|
|
|
import React from 'react';
|
2020-02-04 09:16:48 +02:00
|
|
|
import CMS from 'netlify-cms-app';
|
2018-09-06 14:44:58 -04:00
|
|
|
import dayjs from 'dayjs';
|
2018-10-01 20:00:57 -04:00
|
|
|
import Prism from 'prismjs';
|
2018-09-06 14:44:58 -04:00
|
|
|
import { BlogPostTemplate } from '../templates/blog-post';
|
|
|
|
import { DocsTemplate } from '../templates/doc-page';
|
2018-10-01 20:00:57 -04:00
|
|
|
import WidgetDoc from '../components/widget-doc';
|
2018-09-06 14:44:58 -04:00
|
|
|
import WhatsNew from '../components/whats-new';
|
|
|
|
import Notification from '../components/notification';
|
2019-06-26 15:52:47 -04:00
|
|
|
import Community from '../components/community';
|
2018-09-06 14:44:58 -04:00
|
|
|
|
2018-10-01 20:00:57 -04:00
|
|
|
const withHighlight = WrappedComponent =>
|
|
|
|
class Highlight extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.ref = React.createRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
highlight() {
|
|
|
|
Prism.highlightAllUnder(this.ref.current);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.highlight();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
this.highlight();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className="language-markup" ref={this.ref}>
|
|
|
|
<WrappedComponent {...this.props} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-06 14:44:58 -04:00
|
|
|
const BlogPostPreview = ({ entry, widgetFor }) => {
|
|
|
|
const data = entry.get('data');
|
|
|
|
return (
|
|
|
|
<BlogPostTemplate
|
|
|
|
title={data.get('title')}
|
|
|
|
author={data.get('author')}
|
|
|
|
date={dayjs(data.get('date')).format('MMMM D, YYYY')}
|
|
|
|
body={widgetFor('body')}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-06-26 15:52:47 -04:00
|
|
|
const CommunityPreview = ({ entry }) => {
|
|
|
|
const { title, headline, subhead, sections } = entry.get('data').toJS();
|
|
|
|
return <Community title={title} headline={headline} subhead={subhead} sections={sections} />;
|
|
|
|
};
|
|
|
|
|
2018-09-06 14:44:58 -04:00
|
|
|
const DocsPreview = ({ entry, widgetFor }) => (
|
|
|
|
<DocsTemplate title={entry.getIn(['data', 'title'])} body={widgetFor('body')} />
|
|
|
|
);
|
|
|
|
|
2018-10-01 20:00:57 -04:00
|
|
|
const WidgetDocPreview = ({ entry, widgetFor }) => (
|
|
|
|
<WidgetDoc visible={true} label={entry.get('label')} body={widgetFor('body')} />
|
|
|
|
);
|
|
|
|
|
2018-09-06 14:44:58 -04:00
|
|
|
const ReleasePreview = ({ entry }) => (
|
2020-01-23 21:55:18 -05:00
|
|
|
<WhatsNew
|
2020-02-04 09:16:48 +02:00
|
|
|
updates={entry
|
|
|
|
.getIn(['data', 'updates'])
|
|
|
|
.map(release => ({
|
2020-01-23 21:55:18 -05:00
|
|
|
version: release.get('version'),
|
|
|
|
date: dayjs(release.get('date')).format('MMMM D, YYYY'),
|
|
|
|
description: release.get('description'),
|
2020-02-04 09:16:48 +02:00
|
|
|
}))
|
|
|
|
.toJS()}
|
2020-01-23 21:55:18 -05:00
|
|
|
/>
|
2018-09-06 14:44:58 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
const NotificationPreview = ({ entry }) =>
|
|
|
|
entry
|
|
|
|
.getIn(['data', 'notifications'])
|
|
|
|
.filter(notif => notif.get('published'))
|
|
|
|
.map((notif, idx) => (
|
|
|
|
<Notification key={idx} url={notif.get('url')} loud={notif.get('loud')}>
|
|
|
|
{notif.get('message')}
|
|
|
|
</Notification>
|
|
|
|
));
|
|
|
|
|
2018-10-01 20:00:57 -04:00
|
|
|
CMS.registerPreviewTemplate('blog', withHighlight(BlogPostPreview));
|
|
|
|
CMS.registerPreviewTemplate('docs', withHighlight(DocsPreview));
|
|
|
|
CMS.registerPreviewTemplate('widget_docs', withHighlight(WidgetDocPreview));
|
2018-09-06 14:44:58 -04:00
|
|
|
CMS.registerPreviewTemplate('releases', ReleasePreview);
|
|
|
|
CMS.registerPreviewTemplate('notifications', NotificationPreview);
|
2019-06-26 15:52:47 -04:00
|
|
|
CMS.registerPreviewTemplate('community', CommunityPreview);
|