import React from 'react'; import CMS from 'netlify-cms-app'; import dayjs from 'dayjs'; import Prism from 'prismjs'; import { CacheProvider } from '@emotion/core'; import createCache from '@emotion/cache'; import BlogPostTemplate from '../components/blog-post-template'; import { LayoutTemplate as Layout } from '../components/layout'; import DocsTemplate from '../components/docs-template'; import WidgetDoc from '../components/widget-doc'; import WhatsNew from '../components/whats-new'; import Notification from '../components/notification'; import Community from '../components/community'; import siteConfig from '../../site.yml'; let emotionCache; function getEmotionCache() { const previewPaneIframe = document.querySelector('iframe[class*="PreviewPaneFrame"]'); const previewPaneHeadEl = previewPaneIframe.contentWindow.document.querySelector('head'); if (!emotionCache || emotionCache.sheet.container !== previewPaneHeadEl) { emotionCache = createCache({ container: previewPaneHeadEl }); } return emotionCache; } function PreviewContainer({ children, highlight }) { return ( {highlight ? {children} : children} ); } class Highlight extends React.Component { constructor(props) { super(props); this.ref = React.createRef(); } highlight() { setTimeout(() => { if (this.ref.current) { Prism.highlightAllUnder(this.ref.current); } }); } componentDidMount() { this.highlight(); } componentDidUpdate() { this.highlight(); } render() { return
{this.props.children}
; } } function BlogPostPreview({ entry, widgetFor }) { const data = entry.get('data'); return ( ); } function CommunityPreview({ entry }) { const { title, headline, subhead, sections } = entry.get('data').toJS(); return ( ); } function DocsPreview({ entry, widgetFor }) { return ( ); } function WidgetDocPreview({ entry, widgetFor }) { return ( ); } function ReleasePreview({ entry }) { return ( ({ version: release.get('version'), date: dayjs(release.get('date')).format('MMMM D, YYYY'), description: release.get('description'), })) .toJS()} /> ); } function NotificationPreview({ entry }) { return ( {entry .getIn(['data', 'notifications']) .filter(notif => notif.get('published')) .map((notif, idx) => ( {notif.get('message')} ))} ); } CMS.registerPreviewTemplate('blog', BlogPostPreview); siteConfig.menu.docs.forEach(group => { CMS.registerPreviewTemplate(`docs_${group.name}`, DocsPreview); }); CMS.registerPreviewTemplate('widget_docs', WidgetDocPreview); CMS.registerPreviewTemplate('releases', ReleasePreview); CMS.registerPreviewTemplate('notifications', NotificationPreview); CMS.registerPreviewTemplate('community', CommunityPreview);