import React from 'react'; import CMS from 'netlify-cms'; import dayjs from 'dayjs'; import Prism from 'prismjs'; import { BlogPostTemplate } from '../templates/blog-post'; import { DocsTemplate } from '../templates/doc-page'; import WidgetDoc from '../components/widget-doc'; import Release from '../components/release'; import WhatsNew from '../components/whats-new'; import Notification from '../components/notification'; import '../css/imports/docs.css'; import '../css/imports/whatsnew.css'; import '../css/imports/header.css'; 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 (
); } }; const BlogPostPreview = ({ entry, widgetFor }) => { const data = entry.get('data'); return ( ); }; const DocsPreview = ({ entry, widgetFor }) => ( ); const WidgetDocPreview = ({ entry, widgetFor }) => ( ); const ReleasePreview = ({ entry }) => ( {entry.getIn(['data', 'updates']).map((release, idx) => ( ))} ); const NotificationPreview = ({ entry }) => entry .getIn(['data', 'notifications']) .filter(notif => notif.get('published')) .map((notif, idx) => ( {notif.get('message')} )); CMS.registerPreviewTemplate('blog', withHighlight(BlogPostPreview)); CMS.registerPreviewTemplate('docs', withHighlight(DocsPreview)); CMS.registerPreviewTemplate('widget_docs', withHighlight(WidgetDocPreview)); CMS.registerPreviewTemplate('releases', ReleasePreview); CMS.registerPreviewTemplate('notifications', NotificationPreview);